Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
192 - 1
#! /bin/sh
2
set -e
3
 
4
# grub-mkconfig helper script.
5
# Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
6
#
7
# GRUB is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# GRUB is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
19
 
20
prefix="/usr"
21
exec_prefix="/usr"
22
datarootdir="/usr/share"
23
 
24
. "$pkgdatadir/grub-mkconfig_lib"
25
 
26
export TEXTDOMAIN=grub
27
export TEXTDOMAINDIR="${datarootdir}/locale"
28
 
29
CLASS="--class gnu-linux --class gnu --class os --class xen"
30
 
31
if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
32
  OS="$(sed 's, release .*$,,g' /etc/system-release)"
33
else
34
  OS="${GRUB_DISTRIBUTOR}"
35
  CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
36
fi
37
 
38
# loop-AES arranges things so that /dev/loop/X can be our root device, but
39
# the initrds that Linux uses don't like that.
40
case ${GRUB_DEVICE} in
41
  /dev/loop/*|/dev/loop[0-9])
42
    GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
43
  ;;
44
esac
45
 
46
# Default to disabling partition uuid support to maintian compatibility with
47
# older kernels.
48
GRUB_DISABLE_LINUX_PARTUUID=${GRUB_DISABLE_LINUX_PARTUUID-true}
49
 
50
# btrfs may reside on multiple devices. We cannot pass them as value of root= parameter
51
# and mounting btrfs requires user space scanning, so force UUID in this case.
52
if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \
53
    || ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
54
	&& [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \
55
    || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
56
	&& ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \
57
    || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then
58
  LINUX_ROOT_DEVICE=${GRUB_DEVICE}
59
elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \
60
    || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then
61
  LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID}
62
else
63
  LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
64
fi
65
 
66
# Allow overriding GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT.
67
if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE}" ]; then
68
  GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX_XEN_REPLACE}"
69
fi
70
if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}" ]; then
71
  GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}"
72
fi
73
 
74
case x"$GRUB_FS" in
75
    xbtrfs)
76
	if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then
77
	GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}"
78
	else
79
	rootsubvol="`make_system_path_relative_to_its_root /`"
80
	rootsubvol="${rootsubvol#/}"
81
	if [ "x${rootsubvol}" != x ]; then
82
	    GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
83
	fi
84
	fi;;
85
    xzfs)
86
	rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
87
	bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
88
	LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
89
	;;
90
esac
91
 
92
title_correction_code=
93
 
94
linux_entry ()
95
{
96
  os="$1"
97
  version="$2"
98
  xen_version="$3"
99
  type="$4"
100
  args="$5"
101
  xen_args="$6"
102
  if [ -z "$boot_device_id" ]; then
103
      boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
104
  fi
105
  if [ x$type != xsimple ] ; then
106
      if [ x$type = xrecovery ] ; then
107
	  title="$(gettext_printf "%s, with Xen %s and Linux %s (recovery mode)" "${os}" "${xen_version}" "${version}")"
108
      else
109
	  title="$(gettext_printf "%s, with Xen %s and Linux %s" "${os}" "${xen_version}" "${version}")"
110
      fi
111
      replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
112
      if [ x"Xen ${xen_version}>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
113
         quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
114
         title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
115
         grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")"
116
      fi
117
      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'xen-gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
118
  else
119
      title="$(gettext_printf "%s, with Xen hypervisor" "${os}")"
120
      echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'xen-gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
121
  fi
122
  if [ x$type != xrecovery ] ; then
123
      save_default_entry | grub_add_tab | sed "s/^/$submenu_indentation/"
124
  fi
125
 
126
  if [ -z "${prepare_boot_cache}" ]; then
127
    prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
128
  fi
129
  printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
130
  xmessage="$(gettext_printf "Loading Xen %s ..." ${xen_version})"
131
  lmessage="$(gettext_printf "Loading Linux %s ..." ${version})"
132
  sed "s/^/$submenu_indentation/" << EOF
133
	echo	'$(echo "$xmessage" | grub_quote)'
134
        if [ "\$grub_platform" = "pc" -o "\$grub_platform" = "" ]; then
135
            xen_rm_opts=
136
        else
137
            xen_rm_opts="no-real-mode edd=off"
138
        fi
139
	insmod ${module_loader}
140
	insmod ${xen_loader}
141
	${xen_loader}	${rel_xen_dirname}/${xen_basename} placeholder ${xen_args} \${xen_rm_opts}
142
	echo	'$(echo "$lmessage" | grub_quote)'
143
	${module_loader}	${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args}
144
EOF
145
  if test -n "${initrd}" ; then
146
    # TRANSLATORS: ramdisk isn't identifier. Should be translated.
147
    message="$(gettext_printf "Loading initial ramdisk ...")"
148
    sed "s/^/$submenu_indentation/" << EOF
149
	echo	'$(echo "$message" | grub_quote)'
150
	insmod ${module_loader}
151
	${module_loader}	--nounzip   ${rel_dirname}/${initrd}
152
EOF
153
  fi
154
  sed "s/^/$submenu_indentation/" << EOF
155
}
156
EOF
157
}
158
 
159
linux_list=
160
for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* /boot/kernel-*; do
161
    if grub_file_is_not_garbage "$i"; then
162
    	basename=$(basename $i)
163
	version=$(echo $basename | sed -e "s,^[^0-9]*-,,g")
164
	dirname=$(dirname $i)
165
	config=
166
	for j in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
167
	    if test -e "${j}" ; then
168
		config="${j}"
169
		break
170
	    fi
171
	done
172
        if (grep -qx "CONFIG_XEN_DOM0=y" "${config}" 2> /dev/null || grep -qx "CONFIG_XEN_PRIVILEGED_GUEST=y" "${config}" 2> /dev/null); then linux_list="$linux_list $i" ; fi
173
    fi
174
done
175
if [ "x${linux_list}" = "x" ] ; then
176
    exit 0
177
fi
178
 
179
file_is_not_sym () {
180
    case "$1" in
181
	*/xen-syms-*)
182
	    return 1;;
183
	*)
184
	    return 0;;
185
    esac
186
}
187
 
188
xen_list=
189
for i in /boot/xen*; do
190
    if grub_file_is_not_garbage "$i" && file_is_not_sym "$i" ; then xen_list="$xen_list $i" ; fi
191
done
192
prepare_boot_cache=
193
boot_device_id=
194
 
195
title_correction_code=
196
 
197
machine=`uname -m`
198
 
199
case "$machine" in
200
    i?86) GENKERNEL_ARCH="x86" ;;
201
    mips|mips64) GENKERNEL_ARCH="mips" ;;
202
    mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
203
    arm*) GENKERNEL_ARCH="arm" ;;
204
    *) GENKERNEL_ARCH="$machine" ;;
205
esac
206
 
207
# Extra indentation to add to menu entries in a submenu. We're not in a submenu
208
# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
209
submenu_indentation=""
210
 
211
is_top_level=true
212
 
213
while [ "x${xen_list}" != "x" ] ; do
214
    list="${linux_list}"
215
    current_xen=`version_find_latest $xen_list`
216
    xen_basename=`basename ${current_xen}`
217
    xen_dirname=`dirname ${current_xen}`
218
    rel_xen_dirname=`make_system_path_relative_to_its_root $xen_dirname`
219
    xen_version=`echo $xen_basename | sed -e "s,.gz$,,g;s,^xen-,,g"`
220
    if [ -z "$boot_device_id" ]; then
221
	boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
222
    fi
223
    if [ "x$is_top_level" != xtrue ]; then
224
	echo "	submenu '$(gettext_printf "Xen hypervisor, version %s" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {"
225
    fi
226
    if ($grub_file --is-arm64-efi $current_xen); then
227
	xen_loader="xen_hypervisor"
228
	module_loader="xen_module"
229
    else
230
	if ($grub_file --is-x86-multiboot2 $current_xen); then
231
	    xen_loader="multiboot2"
232
	    module_loader="module2"
233
	else
234
	    xen_loader="multiboot"
235
	    module_loader="module"
236
        fi
237
    fi
238
    while [ "x$list" != "x" ] ; do
239
	linux=`version_find_latest $list`
240
	gettext_printf "Found linux image: %s\n" "$linux" >&2
241
	basename=`basename $linux`
242
	dirname=`dirname $linux`
243
	rel_dirname=`make_system_path_relative_to_its_root $dirname`
244
	version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
245
	alt_version=`echo $version | sed -e "s,\.old$,,g"`
246
	linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
247
 
248
	initrd=
249
	for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
250
	   "initrd-${version}" "initramfs-${version}.img" \
251
	   "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
252
	   "initrd-${alt_version}" "initramfs-${alt_version}.img" \
253
	   "initramfs-genkernel-${version}" \
254
	   "initramfs-genkernel-${alt_version}" \
255
	   "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
256
	   "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}" ; do
257
	    if test -e "${dirname}/${i}" ; then
258
		initrd="$i"
259
		break
260
	    fi
261
	done
262
	if test -n "${initrd}" ; then
263
	    gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2
264
	else
265
    # "UUID=" magic is parsed by initrds.  Since there's no initrd, it can't work here.
266
	    if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \
267
		|| [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then
268
 
269
		linux_root_device_thisversion=${GRUB_DEVICE}
270
	    else
271
		linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID}
272
	    fi
273
	fi
274
 
275
	if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then
276
	    linux_entry "${OS}" "${version}" "${xen_version}" simple \
277
		"${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
278
 
279
	    submenu_indentation="$grub_tab$grub_tab"
280
 
281
	    if [ -z "$boot_device_id" ]; then
282
		boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
283
	    fi
284
            # TRANSLATORS: %s is replaced with an OS name
285
	    echo "submenu '$(gettext_printf "Advanced options for %s (with Xen hypervisor)" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
286
	echo "	submenu '$(gettext_printf "Xen hypervisor, version %s" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {"
287
	   is_top_level=false
288
	fi
289
 
290
	linux_entry "${OS}" "${version}" "${xen_version}" advanced \
291
	    "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
292
	if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
293
	    linux_entry "${OS}" "${version}" "${xen_version}" recovery \
294
		"single ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE_XEN}"
295
	fi
296
 
297
	list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
298
    done
299
    if [ x"$is_top_level" != xtrue ]; then
300
	echo '	}'
301
    fi
302
    xen_list=`echo $xen_list | tr ' ' '\n' | fgrep -vx "$current_xen" | tr '\n' ' '`
303
done
304
 
305
# If at least one kernel was found, then we need to
306
# add a closing '}' for the submenu command.
307
if [ x"$is_top_level" != xtrue ]; then
308
  echo '}'
309
fi
310
 
311
echo "$title_correction_code"