]>
Commit | Line | Data |
---|---|---|
6b566244 AF |
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" | |
3273f479 AF |
21 | exec_prefix="/usr" |
22 | datarootdir="/usr/share" | |
6b566244 | 23 | |
3273f479 | 24 | . "$pkgdatadir/grub-mkconfig_lib" |
6b566244 AF |
25 | |
26 | export TEXTDOMAIN=grub | |
27 | export TEXTDOMAINDIR="${datarootdir}/locale" | |
28 | ||
29 | CLASS="--class gnu-linux --class gnu --class os" | |
30 | ||
31 | if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then | |
32 | OS=GNU/Linux | |
33 | else | |
34 | OS="${GRUB_DISTRIBUTOR} GNU/Linux" | |
3273f479 | 35 | CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" |
6b566244 AF |
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 | ||
3273f479 AF |
46 | : ${GRUB_CMDLINE_LINUX_RECOVERY:=single} |
47 | ||
48 | # Default to disabling partition uuid support to maintian compatibility with | |
49 | # older kernels. | |
50 | : ${GRUB_DISABLE_LINUX_PARTUUID=true} | |
51 | ||
52 | # btrfs may reside on multiple devices. We cannot pass them as value of root= parameter | |
53 | # and mounting btrfs requires user space scanning, so force UUID in this case. | |
54 | if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \ | |
55 | || ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ | |
56 | && [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \ | |
57 | || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ | |
58 | && ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \ | |
59 | || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then | |
6b566244 | 60 | LINUX_ROOT_DEVICE=${GRUB_DEVICE} |
3273f479 AF |
61 | elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \ |
62 | || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then | |
63 | LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID} | |
6b566244 AF |
64 | else |
65 | LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} | |
66 | fi | |
67 | ||
3273f479 | 68 | case x"$GRUB_FS" in |
6b566244 AF |
69 | xbtrfs) |
70 | rootsubvol="`make_system_path_relative_to_its_root /`" | |
71 | rootsubvol="${rootsubvol#/}" | |
72 | if [ "x${rootsubvol}" != x ]; then | |
73 | GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}" | |
74 | fi;; | |
75 | xzfs) | |
76 | rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true` | |
77 | bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`" | |
3273f479 | 78 | LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs%/}" |
6b566244 AF |
79 | ;; |
80 | esac | |
81 | ||
82 | title_correction_code= | |
83 | ||
84 | linux_entry () | |
85 | { | |
86 | os="$1" | |
87 | version="$2" | |
88 | type="$3" | |
89 | args="$4" | |
90 | ||
91 | if [ -z "$boot_device_id" ]; then | |
92 | boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" | |
93 | fi | |
94 | if [ x$type != xsimple ] ; then | |
95 | case $type in | |
96 | recovery) | |
97 | title="$(gettext_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;; | |
98 | *) | |
99 | title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;; | |
100 | esac | |
101 | if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then | |
102 | replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')" | |
103 | quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)" | |
104 | title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;" | |
105 | 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")" | |
106 | fi | |
107 | echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/" | |
108 | else | |
109 | echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/" | |
110 | fi | |
111 | if [ x$type != xrecovery ] ; then | |
3273f479 | 112 | save_default_entry | grub_add_tab |
6b566244 AF |
113 | fi |
114 | ||
115 | # Use ELILO's generic "efifb" when it's known to be available. | |
116 | # FIXME: We need an interface to select vesafb in case efifb can't be used. | |
117 | if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then | |
118 | echo " load_video" | sed "s/^/$submenu_indentation/" | |
119 | if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \ | |
120 | && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then | |
121 | echo " set gfxpayload=keep" | sed "s/^/$submenu_indentation/" | |
122 | fi | |
123 | else | |
124 | if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then | |
125 | echo " load_video" | sed "s/^/$submenu_indentation/" | |
126 | fi | |
127 | echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/" | |
128 | fi | |
129 | ||
130 | echo " insmod gzio" | sed "s/^/$submenu_indentation/" | |
131 | ||
132 | if [ x$dirname = x/ ]; then | |
133 | if [ -z "${prepare_root_cache}" ]; then | |
3273f479 | 134 | prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)" |
6b566244 AF |
135 | fi |
136 | printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/" | |
137 | else | |
138 | if [ -z "${prepare_boot_cache}" ]; then | |
3273f479 | 139 | prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)" |
6b566244 AF |
140 | fi |
141 | printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" | |
142 | fi | |
143 | message="$(gettext_printf "Loading Linux %s ..." ${version})" | |
144 | sed "s/^/$submenu_indentation/" << EOF | |
3273f479 | 145 | echo '$(echo "$message" | grub_quote)' |
6b566244 AF |
146 | linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} |
147 | EOF | |
148 | if test -n "${initrd}" ; then | |
149 | # TRANSLATORS: ramdisk isn't identifier. Should be translated. | |
150 | message="$(gettext_printf "Loading initial ramdisk ...")" | |
3273f479 AF |
151 | initrd_path= |
152 | for i in ${initrd}; do | |
153 | initrd_path="${initrd_path} ${rel_dirname}/${i}" | |
154 | done | |
6b566244 | 155 | sed "s/^/$submenu_indentation/" << EOF |
3273f479 AF |
156 | echo '$(echo "$message" | grub_quote)' |
157 | initrd $(echo $initrd_path) | |
6b566244 AF |
158 | EOF |
159 | fi | |
160 | sed "s/^/$submenu_indentation/" << EOF | |
161 | } | |
162 | EOF | |
163 | } | |
164 | ||
165 | machine=`uname -m` | |
166 | case "x$machine" in | |
167 | xi?86 | xx86_64) | |
3273f479 AF |
168 | list= |
169 | for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do | |
170 | if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi | |
171 | done ;; | |
6b566244 | 172 | *) |
3273f479 AF |
173 | list= |
174 | for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do | |
175 | if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi | |
176 | done ;; | |
6b566244 AF |
177 | esac |
178 | ||
179 | case "$machine" in | |
180 | i?86) GENKERNEL_ARCH="x86" ;; | |
181 | mips|mips64) GENKERNEL_ARCH="mips" ;; | |
182 | mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;; | |
183 | arm*) GENKERNEL_ARCH="arm" ;; | |
184 | *) GENKERNEL_ARCH="$machine" ;; | |
185 | esac | |
186 | ||
187 | prepare_boot_cache= | |
188 | prepare_root_cache= | |
189 | boot_device_id= | |
190 | title_correction_code= | |
191 | ||
192 | # Extra indentation to add to menu entries in a submenu. We're not in a submenu | |
193 | # yet, so it's empty. In a submenu it will be equal to '\t' (one tab). | |
194 | submenu_indentation="" | |
195 | ||
3273f479 AF |
196 | # Perform a reverse version sort on the entire list. |
197 | # Temporarily replace the '.old' suffix by ' 1' and append ' 2' for all | |
198 | # other files to order the '.old' files after their non-old counterpart | |
199 | # in reverse-sorted order. | |
200 | ||
201 | reverse_sorted_list=$(echo $list | tr ' ' '\n' | sed -e 's/\.old$/ 1/; / 1$/! s/$/ 2/' | version_sort -r | sed -e 's/ 1$/.old/; s/ 2$//') | |
202 | ||
203 | if [ "x$GRUB_TOP_LEVEL" != x ]; then | |
204 | reverse_sorted_list=$(grub_move_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_list}) | |
205 | fi | |
206 | ||
207 | is_top_level=true | |
208 | for linux in ${reverse_sorted_list}; do | |
6b566244 AF |
209 | gettext_printf "Found linux image: %s\n" "$linux" >&2 |
210 | basename=`basename $linux` | |
211 | dirname=`dirname $linux` | |
212 | rel_dirname=`make_system_path_relative_to_its_root $dirname` | |
213 | version=`echo $basename | sed -e "s,^[^0-9]*-,,g"` | |
214 | alt_version=`echo $version | sed -e "s,\.old$,,g"` | |
215 | linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" | |
216 | ||
3273f479 AF |
217 | initrd_early= |
218 | for i in ${GRUB_EARLY_INITRD_LINUX_STOCK} \ | |
219 | ${GRUB_EARLY_INITRD_LINUX_CUSTOM}; do | |
220 | if test -e "${dirname}/${i}" ; then | |
221 | initrd_early="${initrd_early} ${i}" | |
222 | fi | |
223 | done | |
224 | ||
225 | initrd_real= | |
226 | for i in "initrd.img-${version}" "initrd-${version}.img" \ | |
227 | "initrd-${alt_version}.img.old" "initrd-${version}.gz" \ | |
228 | "initrd-${alt_version}.gz.old" "initrd-${version}" \ | |
229 | "initramfs-${version}.img" "initramfs-${alt_version}.img.old" \ | |
6b566244 AF |
230 | "initrd.img-${alt_version}" "initrd-${alt_version}.img" \ |
231 | "initrd-${alt_version}" "initramfs-${alt_version}.img" \ | |
232 | "initramfs-genkernel-${version}" \ | |
233 | "initramfs-genkernel-${alt_version}" \ | |
234 | "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \ | |
235 | "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do | |
236 | if test -e "${dirname}/${i}" ; then | |
3273f479 | 237 | initrd_real="${i}" |
6b566244 AF |
238 | break |
239 | fi | |
240 | done | |
241 | ||
3273f479 AF |
242 | initrd= |
243 | if test -n "${initrd_early}" || test -n "${initrd_real}"; then | |
244 | initrd="${initrd_early} ${initrd_real}" | |
245 | ||
246 | initrd_display= | |
247 | for i in ${initrd}; do | |
248 | initrd_display="${initrd_display} ${dirname}/${i}" | |
249 | done | |
250 | gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2 | |
251 | fi | |
252 | ||
6b566244 AF |
253 | config= |
254 | for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do | |
255 | if test -e "${i}" ; then | |
256 | config="${i}" | |
257 | break | |
258 | fi | |
259 | done | |
260 | ||
261 | initramfs= | |
262 | if test -n "${config}" ; then | |
263 | initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"` | |
264 | fi | |
265 | ||
3273f479 | 266 | if test -z "${initramfs}" && test -z "${initrd_real}" ; then |
6b566244 AF |
267 | # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's |
268 | # no initrd or builtin initramfs, it can't work here. | |
3273f479 AF |
269 | if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \ |
270 | || [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then | |
271 | ||
272 | linux_root_device_thisversion=${GRUB_DEVICE} | |
273 | else | |
274 | linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID} | |
275 | fi | |
6b566244 AF |
276 | fi |
277 | ||
3273f479 AF |
278 | # The GRUB_DISABLE_SUBMENU option used to be different than others since it was |
279 | # mentioned in the documentation that has to be set to 'y' instead of 'true' to | |
280 | # enable it. This caused a lot of confusion to users that set the option to 'y', | |
281 | # 'yes' or 'true'. This was fixed but all of these values must be supported now. | |
282 | if [ "x${GRUB_DISABLE_SUBMENU}" = xyes ] || [ "x${GRUB_DISABLE_SUBMENU}" = xy ]; then | |
283 | GRUB_DISABLE_SUBMENU="true" | |
284 | fi | |
285 | ||
286 | if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then | |
ff1953f7 | 287 | linux_entry "Serial Console: ${OS}" "${version}" serial \ |
6b566244 AF |
288 | "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} console=ttyS0,115200n8" |
289 | ||
3273f479 | 290 | submenu_indentation="$grub_tab" |
6b566244 AF |
291 | |
292 | if [ -z "$boot_device_id" ]; then | |
293 | boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" | |
294 | fi | |
295 | fi | |
6b566244 AF |
296 | done |
297 | ||
298 | echo "$title_correction_code" |