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 | ubuntu_recovery="1" |
---|
24 | quiet_boot="1" |
---|
25 | quick_boot="1" |
---|
26 | gfxpayload_dynamic="1" |
---|
27 | vt_handoff="1" |
---|
28 | |
---|
29 | . "${datarootdir}/grub/grub-mkconfig_lib" |
---|
30 | |
---|
31 | export TEXTDOMAIN=grub |
---|
32 | export TEXTDOMAINDIR="${datarootdir}/locale" |
---|
33 | |
---|
34 | CLASS="--class gnu-linux --class gnu --class os" |
---|
35 | |
---|
36 | if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then |
---|
37 | OS=GNU/Linux |
---|
38 | else |
---|
39 | case ${GRUB_DISTRIBUTOR} in |
---|
40 | Ubuntu|Kubuntu) |
---|
41 | OS="${GRUB_DISTRIBUTOR}" |
---|
42 | ;; |
---|
43 | *) |
---|
44 | OS="${GRUB_DISTRIBUTOR} GNU/Linux" |
---|
45 | ;; |
---|
46 | esac |
---|
47 | CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}" |
---|
48 | fi |
---|
49 | |
---|
50 | # loop-AES arranges things so that /dev/loop/X can be our root device, but |
---|
51 | # the initrds that Linux uses don't like that. |
---|
52 | case ${GRUB_DEVICE} in |
---|
53 | /dev/loop/*|/dev/loop[0-9]) |
---|
54 | GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"` |
---|
55 | # We can't cope with devices loop-mounted from files here. |
---|
56 | case ${GRUB_DEVICE} in |
---|
57 | /dev/*) ;; |
---|
58 | *) exit 0 ;; |
---|
59 | esac |
---|
60 | ;; |
---|
61 | esac |
---|
62 | |
---|
63 | if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ |
---|
64 | || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ |
---|
65 | || uses_abstraction "${GRUB_DEVICE}" lvm; then |
---|
66 | LINUX_ROOT_DEVICE=${GRUB_DEVICE} |
---|
67 | else |
---|
68 | LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} |
---|
69 | fi |
---|
70 | |
---|
71 | case x"$GRUB_FS" in |
---|
72 | xbtrfs) |
---|
73 | rootsubvol="`make_system_path_relative_to_its_root /`" |
---|
74 | rootsubvol="${rootsubvol#/}" |
---|
75 | if [ "x${rootsubvol}" != x ]; then |
---|
76 | GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}" |
---|
77 | fi;; |
---|
78 | xzfs) |
---|
79 | rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true` |
---|
80 | bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`" |
---|
81 | LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}" |
---|
82 | ;; |
---|
83 | esac |
---|
84 | |
---|
85 | title_correction_code= |
---|
86 | |
---|
87 | if [ -x /lib/recovery-mode/recovery-menu ]; then |
---|
88 | GRUB_CMDLINE_LINUX_RECOVERY=recovery |
---|
89 | else |
---|
90 | GRUB_CMDLINE_LINUX_RECOVERY=single |
---|
91 | fi |
---|
92 | if [ "$ubuntu_recovery" = 1 ]; then |
---|
93 | GRUB_CMDLINE_LINUX_RECOVERY="$GRUB_CMDLINE_LINUX_RECOVERY nomodeset" |
---|
94 | fi |
---|
95 | |
---|
96 | if [ "$vt_handoff" = 1 ]; then |
---|
97 | for word in $GRUB_CMDLINE_LINUX_DEFAULT; do |
---|
98 | if [ "$word" = splash ]; then |
---|
99 | GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT \$vt_handoff" |
---|
100 | fi |
---|
101 | done |
---|
102 | fi |
---|
103 | |
---|
104 | linux_entry () |
---|
105 | { |
---|
106 | os="$1" |
---|
107 | version="$2" |
---|
108 | type="$3" |
---|
109 | args="$4" |
---|
110 | |
---|
111 | if [ -z "$boot_device_id" ]; then |
---|
112 | boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" |
---|
113 | fi |
---|
114 | if [ x$type != xsimple ] ; then |
---|
115 | case $type in |
---|
116 | recovery) |
---|
117 | title="$(gettext_printf "%s, with Linux %s (%s)" "${os}" "${version}" "$(gettext "${GRUB_RECOVERY_TITLE}")")" ;; |
---|
118 | lliurexfix) |
---|
119 | title="$(gettext_printf "%s, with Linux %s (%s)" "${os}" "${version}" "$(gettext "${GRUB_RECOVERY_TITLE}")") + LliureX Fix" ;; |
---|
120 | *) |
---|
121 | title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;; |
---|
122 | esac |
---|
123 | if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then |
---|
124 | replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')" |
---|
125 | quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)" |
---|
126 | title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;" |
---|
127 | 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")" |
---|
128 | fi |
---|
129 | echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/" |
---|
130 | else |
---|
131 | echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/" |
---|
132 | fi |
---|
133 | if [ "$quick_boot" = 1 ]; then |
---|
134 | echo " recordfail" | sed "s/^/$submenu_indentation/" |
---|
135 | fi |
---|
136 | if [ x$type != xrecovery ] ; then |
---|
137 | save_default_entry | grub_add_tab |
---|
138 | fi |
---|
139 | |
---|
140 | # Use ELILO's generic "efifb" when it's known to be available. |
---|
141 | # FIXME: We need an interface to select vesafb in case efifb can't be used. |
---|
142 | if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then |
---|
143 | echo " load_video" | sed "s/^/$submenu_indentation/" |
---|
144 | else |
---|
145 | if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then |
---|
146 | echo " load_video" | sed "s/^/$submenu_indentation/" |
---|
147 | fi |
---|
148 | fi |
---|
149 | if ([ "$ubuntu_recovery" = 0 ] || [ x$type != xrecovery ]) && \ |
---|
150 | ([ "x$GRUB_GFXPAYLOAD_LINUX" != x ] || [ "$gfxpayload_dynamic" = 1 ]); then |
---|
151 | echo " gfxmode \$linux_gfx_mode" | sed "s/^/$submenu_indentation/" |
---|
152 | fi |
---|
153 | |
---|
154 | echo " insmod gzio" | sed "s/^/$submenu_indentation/" |
---|
155 | |
---|
156 | if [ x$dirname = x/ ]; then |
---|
157 | if [ -z "${prepare_root_cache}" ]; then |
---|
158 | prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)" |
---|
159 | fi |
---|
160 | printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/" |
---|
161 | else |
---|
162 | if [ -z "${prepare_boot_cache}" ]; then |
---|
163 | prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)" |
---|
164 | fi |
---|
165 | printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/" |
---|
166 | fi |
---|
167 | if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then |
---|
168 | message="$(gettext_printf "Loading Linux %s ..." ${version})" |
---|
169 | sed "s/^/$submenu_indentation/" << EOF |
---|
170 | echo '$(echo "$message" | grub_quote)' |
---|
171 | EOF |
---|
172 | fi |
---|
173 | if test -d /sys/firmware/efi && test -e "${linux}.efi.signed"; then |
---|
174 | sed "s/^/$submenu_indentation/" << EOF |
---|
175 | linux ${rel_dirname}/${basename}.efi.signed root=${linux_root_device_thisversion} rw ${args} |
---|
176 | EOF |
---|
177 | else |
---|
178 | sed "s/^/$submenu_indentation/" << EOF |
---|
179 | linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} rw ${args} |
---|
180 | EOF |
---|
181 | fi |
---|
182 | if test -n "${initrd}" ; then |
---|
183 | # TRANSLATORS: ramdisk isn't identifier. Should be translated. |
---|
184 | if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then |
---|
185 | message="$(gettext_printf "Loading initial ramdisk ...")" |
---|
186 | sed "s/^/$submenu_indentation/" << EOF |
---|
187 | echo '$(echo "$message" | grub_quote)' |
---|
188 | EOF |
---|
189 | fi |
---|
190 | sed "s/^/$submenu_indentation/" << EOF |
---|
191 | initrd ${rel_dirname}/${initrd} |
---|
192 | EOF |
---|
193 | fi |
---|
194 | sed "s/^/$submenu_indentation/" << EOF |
---|
195 | } |
---|
196 | EOF |
---|
197 | } |
---|
198 | |
---|
199 | machine=`uname -m` |
---|
200 | case "x$machine" in |
---|
201 | xi?86 | xx86_64) |
---|
202 | list=`for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do |
---|
203 | if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi |
---|
204 | done` ;; |
---|
205 | *) |
---|
206 | list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do |
---|
207 | if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi |
---|
208 | done` ;; |
---|
209 | esac |
---|
210 | |
---|
211 | case "$machine" in |
---|
212 | i?86) GENKERNEL_ARCH="x86" ;; |
---|
213 | mips|mips64) GENKERNEL_ARCH="mips" ;; |
---|
214 | mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;; |
---|
215 | arm*) GENKERNEL_ARCH="arm" ;; |
---|
216 | *) GENKERNEL_ARCH="$machine" ;; |
---|
217 | esac |
---|
218 | |
---|
219 | prepare_boot_cache= |
---|
220 | prepare_root_cache= |
---|
221 | boot_device_id= |
---|
222 | title_correction_code= |
---|
223 | |
---|
224 | cat << 'EOF' |
---|
225 | function gfxmode { |
---|
226 | set gfxpayload="${1}" |
---|
227 | EOF |
---|
228 | if [ "$vt_handoff" = 1 ]; then |
---|
229 | cat << 'EOF' |
---|
230 | if [ "${1}" = "keep" ]; then |
---|
231 | set vt_handoff=vt.handoff=7 |
---|
232 | else |
---|
233 | set vt_handoff= |
---|
234 | fi |
---|
235 | EOF |
---|
236 | fi |
---|
237 | cat << EOF |
---|
238 | } |
---|
239 | EOF |
---|
240 | |
---|
241 | # Use ELILO's generic "efifb" when it's known to be available. |
---|
242 | # FIXME: We need an interface to select vesafb in case efifb can't be used. |
---|
243 | if [ "x$GRUB_GFXPAYLOAD_LINUX" != x ] || [ "$gfxpayload_dynamic" = 0 ]; then |
---|
244 | echo "set linux_gfx_mode=$GRUB_GFXPAYLOAD_LINUX" |
---|
245 | else |
---|
246 | cat << EOF |
---|
247 | if [ "\${recordfail}" != 1 ]; then |
---|
248 | if [ -e \${prefix}/gfxblacklist.txt ]; then |
---|
249 | if hwmatch \${prefix}/gfxblacklist.txt 3; then |
---|
250 | if [ \${match} = 0 ]; then |
---|
251 | set linux_gfx_mode=keep |
---|
252 | else |
---|
253 | set linux_gfx_mode=text |
---|
254 | fi |
---|
255 | else |
---|
256 | set linux_gfx_mode=text |
---|
257 | fi |
---|
258 | else |
---|
259 | set linux_gfx_mode=keep |
---|
260 | fi |
---|
261 | else |
---|
262 | set linux_gfx_mode=text |
---|
263 | fi |
---|
264 | EOF |
---|
265 | fi |
---|
266 | cat << EOF |
---|
267 | export linux_gfx_mode |
---|
268 | EOF |
---|
269 | |
---|
270 | # Extra indentation to add to menu entries in a submenu. We're not in a submenu |
---|
271 | # yet, so it's empty. In a submenu it will be equal to '\t' (one tab). |
---|
272 | submenu_indentation="" |
---|
273 | |
---|
274 | is_top_level=true |
---|
275 | while [ "x$list" != "x" ] ; do |
---|
276 | linux=`version_find_latest $list` |
---|
277 | case $linux in |
---|
278 | *.efi.signed) |
---|
279 | # We handle these in linux_entry. |
---|
280 | list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '` |
---|
281 | continue |
---|
282 | ;; |
---|
283 | esac |
---|
284 | gettext_printf "Found linux image: %s\n" "$linux" >&2 |
---|
285 | basename=`basename $linux` |
---|
286 | dirname=`dirname $linux` |
---|
287 | rel_dirname=`make_system_path_relative_to_its_root $dirname` |
---|
288 | version=`echo $basename | sed -e "s,^[^0-9]*-,,g"` |
---|
289 | alt_version=`echo $version | sed -e "s,\.old$,,g"` |
---|
290 | linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" |
---|
291 | |
---|
292 | initrd= |
---|
293 | for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \ |
---|
294 | "initrd-${version}" "initramfs-${version}.img" \ |
---|
295 | "initrd.img-${alt_version}" "initrd-${alt_version}.img" \ |
---|
296 | "initrd-${alt_version}" "initramfs-${alt_version}.img" \ |
---|
297 | "initramfs-genkernel-${version}" \ |
---|
298 | "initramfs-genkernel-${alt_version}" \ |
---|
299 | "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \ |
---|
300 | "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do |
---|
301 | if test -e "${dirname}/${i}" ; then |
---|
302 | initrd="$i" |
---|
303 | break |
---|
304 | fi |
---|
305 | done |
---|
306 | |
---|
307 | config= |
---|
308 | for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do |
---|
309 | if test -e "${i}" ; then |
---|
310 | config="${i}" |
---|
311 | break |
---|
312 | fi |
---|
313 | done |
---|
314 | |
---|
315 | initramfs= |
---|
316 | if test -n "${config}" ; then |
---|
317 | initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"` |
---|
318 | fi |
---|
319 | |
---|
320 | if test -n "${initrd}" ; then |
---|
321 | gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2 |
---|
322 | elif test -z "${initramfs}" ; then |
---|
323 | # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's |
---|
324 | # no initrd or builtin initramfs, it can't work here. |
---|
325 | linux_root_device_thisversion=${GRUB_DEVICE} |
---|
326 | fi |
---|
327 | |
---|
328 | if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then |
---|
329 | linux_entry "${OS}" "${version}" simple \ |
---|
330 | "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" |
---|
331 | |
---|
332 | submenu_indentation="$grub_tab" |
---|
333 | |
---|
334 | if [ -z "$boot_device_id" ]; then |
---|
335 | boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" |
---|
336 | fi |
---|
337 | # TRANSLATORS: %s is replaced with an OS name |
---|
338 | echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {" |
---|
339 | is_top_level=false |
---|
340 | fi |
---|
341 | |
---|
342 | linux_entry "${OS}" "${version}" advanced \ |
---|
343 | "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" |
---|
344 | if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then |
---|
345 | linux_entry "${OS}" "${version}" recovery \ |
---|
346 | "${GRUB_CMDLINE_LINUX_RECOVERY} ${GRUB_CMDLINE_LINUX}" |
---|
347 | # Added entry if exists only |
---|
348 | if [ -f /usr/share/initramfs-tools/scripts/init-bottom/lliurex-nsswitch ]; then |
---|
349 | linux_entry "${OS}" "${version}" lliurexfix \ |
---|
350 | "${GRUB_CMDLINE_LINUX_RECOVERY} ${GRUB_CMDLINE_LINUX} noplymouth lliurexfix" |
---|
351 | fi |
---|
352 | fi |
---|
353 | |
---|
354 | list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '` |
---|
355 | done |
---|
356 | |
---|
357 | # If at least one kernel was found, then we need to |
---|
358 | # add a closing '}' for the submenu command. |
---|
359 | if [ x"$is_top_level" != xtrue ]; then |
---|
360 | echo '}' |
---|
361 | fi |
---|
362 | |
---|
363 | echo "$title_correction_code" |
---|