2 ################################################
3 ### Managed by someone's ansible provisioner ###
4 ################################################
5 # Part of: https://git.somenet.org/root/pub/somesible.git
6 # 2017-2024 by someone <someone@somenet.org>
10 # grub-mkconfig helper script.
11 # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
13 # GRUB is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
18 # GRUB is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
28 datarootdir="/usr/share"
32 gfxpayload_dynamic="0"
35 . "$pkgdatadir/grub-mkconfig_lib"
37 export TEXTDOMAIN=grub
38 export TEXTDOMAINDIR="${datarootdir}/locale"
40 {% if grub_pw_admin | default("") != "" %}
42 set superusers="admin"
43 password_pbkdf2 admin {{grub_pw_admin}}
46 CLASS="--class gnu-linux --class gnu --class os --unrestricted"
50 #set superusers="admin"
51 #password_pbkdf2 admin grub_pw_admin
55 CLASS="--class gnu-linux --class gnu --class os"
58 if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
61 case ${GRUB_DISTRIBUTOR} in
63 OS="${GRUB_DISTRIBUTOR}"
66 OS="${GRUB_DISTRIBUTOR} GNU/Linux"
69 CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
72 # loop-AES arranges things so that /dev/loop/X can be our root device, but
73 # the initrds that Linux uses don't like that.
74 case ${GRUB_DEVICE} in
75 /dev/loop/*|/dev/loop[0-9])
76 GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
77 # We can't cope with devices loop-mounted from files here.
78 case ${GRUB_DEVICE} in
85 : ${GRUB_CMDLINE_LINUX_RECOVERY:=single}
87 # Default to disabling partition uuid support to maintian compatibility with
89 : ${GRUB_DISABLE_LINUX_PARTUUID=true}
91 # btrfs may reside on multiple devices. We cannot pass them as value of root= parameter
92 # and mounting btrfs requires user space scanning, so force UUID in this case.
93 if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \
94 || ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
95 && [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \
96 || ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
97 && ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \
98 || ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then
99 LINUX_ROOT_DEVICE=${GRUB_DEVICE}
100 elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \
101 || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then
102 LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID}
104 LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
109 rootsubvol="`make_system_path_relative_to_its_root /`"
110 rootsubvol="${rootsubvol#/}"
111 if [ "x${rootsubvol}" != x ]; then
112 GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol},degraded ${GRUB_CMDLINE_LINUX}"
115 rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
116 bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
117 LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs%/}"
121 title_correction_code=
123 if [ -x /lib/recovery-mode/recovery-menu ]; then
124 GRUB_CMDLINE_LINUX_RECOVERY="${GRUB_CMDLINE_LINUX_RECOVERY} recovery"
126 GRUB_CMDLINE_LINUX_RECOVERY="${GRUB_CMDLINE_LINUX_RECOVERY} single"
128 if [ "$ubuntu_recovery" = 1 ]; then
129 GRUB_CMDLINE_LINUX_RECOVERY="$GRUB_CMDLINE_LINUX_RECOVERY nomodeset"
132 if [ "$vt_handoff" = 1 ]; then
133 for word in $GRUB_CMDLINE_LINUX_DEFAULT; do
134 if [ "$word" = splash ]; then
135 GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT \$vt_handoff"
147 if [ -z "$boot_device_id" ]; then
148 boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
150 if [ x$type != xsimple ] ; then
153 title="$(gettext_printf "%s, with Linux %s (%s)" "${os}" "${version}" "$(gettext "${GRUB_RECOVERY_TITLE}")")" ;;
155 title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;;
157 if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
158 replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
159 quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
160 title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
161 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")"
163 echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
165 echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
167 if [ "$quick_boot" = 1 ]; then
168 echo " recordfail" | sed "s/^/$submenu_indentation/"
170 if [ x$type != xrecovery ] ; then
171 save_default_entry | grub_add_tab
174 # Use ELILO's generic "efifb" when it's known to be available.
175 # FIXME: We need an interface to select vesafb in case efifb can't be used.
176 if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
177 echo " load_video" | sed "s/^/$submenu_indentation/"
179 if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
180 echo " load_video" | sed "s/^/$submenu_indentation/"
183 if ([ "$ubuntu_recovery" = 0 ] || [ x$type != xrecovery ]) && \
184 ([ "x$GRUB_GFXPAYLOAD_LINUX" != x ] || [ "$gfxpayload_dynamic" = 1 ]); then
185 echo " gfxmode \$linux_gfx_mode" | sed "s/^/$submenu_indentation/"
188 echo " insmod gzio" | sed "s/^/$submenu_indentation/"
189 echo " if [ x\$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi" | sed "s/^/$submenu_indentation/"
191 if [ x$dirname = x/ ]; then
192 if [ -z "${prepare_root_cache}" ]; then
193 prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
195 printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
197 if [ -z "${prepare_boot_cache}" ]; then
198 prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
200 printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
202 if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
203 message="$(gettext_printf "Loading Linux %s ..." ${version})"
204 sed "s/^/$submenu_indentation/" << EOF
205 echo '$(echo "$message" | grub_quote)'
208 sed "s/^/$submenu_indentation/" << EOF
209 linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
211 if test -n "${initrd}" ; then
212 # TRANSLATORS: ramdisk isn't identifier. Should be translated.
213 if [ x"$quiet_boot" = x0 ] || [ x"$type" != xsimple ]; then
214 message="$(gettext_printf "Loading initial ramdisk ...")"
215 sed "s/^/$submenu_indentation/" << EOF
216 echo '$(echo "$message" | grub_quote)'
220 for i in ${initrd}; do
221 initrd_path="${initrd_path} ${rel_dirname}/${i}"
223 sed "s/^/$submenu_indentation/" << EOF
224 initrd $(echo $initrd_path)
227 sed "s/^/$submenu_indentation/" << EOF
236 for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
237 if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
241 for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
242 if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
247 i?86) GENKERNEL_ARCH="x86" ;;
248 mips|mips64) GENKERNEL_ARCH="mips" ;;
249 mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
250 arm*) GENKERNEL_ARCH="arm" ;;
251 *) GENKERNEL_ARCH="$machine" ;;
254 case "$GENKERNEL_ARCH" in
255 x86*) GRUB_CMDLINE_LINUX_RECOVERY="$GRUB_CMDLINE_LINUX_RECOVERY dis_ucode_ldr";;
261 title_correction_code=
265 set gfxpayload="${1}"
267 if [ "$vt_handoff" = 1 ]; then
269 if [ "${1}" = "keep" ]; then
270 set vt_handoff=vt.handoff=7
280 # Use ELILO's generic "efifb" when it's known to be available.
281 # FIXME: We need an interface to select vesafb in case efifb can't be used.
282 if [ "x$GRUB_GFXPAYLOAD_LINUX" != x ] || [ "$gfxpayload_dynamic" = 0 ]; then
283 echo "set linux_gfx_mode=$GRUB_GFXPAYLOAD_LINUX"
286 if [ "\${recordfail}" != 1 ]; then
287 if [ -e \${prefix}/gfxblacklist.txt ]; then
288 if [ \${grub_platform} != pc ]; then
289 set linux_gfx_mode=keep
290 elif hwmatch \${prefix}/gfxblacklist.txt 3; then
291 if [ \${match} = 0 ]; then
292 set linux_gfx_mode=keep
294 set linux_gfx_mode=text
297 set linux_gfx_mode=text
300 set linux_gfx_mode=keep
303 set linux_gfx_mode=text
308 export linux_gfx_mode
311 # Extra indentation to add to menu entries in a submenu. We're not in a submenu
312 # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
313 submenu_indentation=""
315 # Perform a reverse version sort on the entire list.
316 # Temporarily replace the '.old' suffix by ' 1' and append ' 2' for all
317 # other files to order the '.old' files after their non-old counterpart
318 # in reverse-sorted order.
320 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$//')
322 if [ "x$GRUB_TOP_LEVEL" != x ]; then
323 reverse_sorted_list=$(grub_move_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_list})
327 for linux in ${reverse_sorted_list}; do
328 gettext_printf "Found linux image: %s\n" "$linux" >&2
329 basename=`basename $linux`
330 dirname=`dirname $linux`
331 rel_dirname=`make_system_path_relative_to_its_root $dirname`
332 version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
333 alt_version=`echo $version | sed -e "s,\.old$,,g"`
334 linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
337 for i in ${GRUB_EARLY_INITRD_LINUX_STOCK} \
338 ${GRUB_EARLY_INITRD_LINUX_CUSTOM}; do
339 if test -e "${dirname}/${i}" ; then
340 initrd_early="${initrd_early} ${i}"
345 for i in "initrd.img-${version}" "initrd-${version}.img" \
346 "initrd-${alt_version}.img.old" "initrd-${version}.gz" \
347 "initrd-${alt_version}.gz.old" "initrd-${version}" \
348 "initramfs-${version}.img" "initramfs-${alt_version}.img.old" \
349 "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
350 "initrd-${alt_version}" "initramfs-${alt_version}.img" \
351 "initramfs-genkernel-${version}" \
352 "initramfs-genkernel-${alt_version}" \
353 "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
354 "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
355 if test -e "${dirname}/${i}" ; then
362 if test -n "${initrd_early}" || test -n "${initrd_real}"; then
363 initrd="${initrd_early} ${initrd_real}"
366 for i in ${initrd}; do
367 initrd_display="${initrd_display} ${dirname}/${i}"
369 gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2
373 for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
374 if test -e "${i}" ; then
381 if test -n "${config}" ; then
382 initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
385 if test -z "${initramfs}" && test -z "${initrd_real}" ; then
386 # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's
387 # no initrd or builtin initramfs, it can't work here.
388 if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \
389 || [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then
391 linux_root_device_thisversion=${GRUB_DEVICE}
393 linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID}
397 # The GRUB_DISABLE_SUBMENU option used to be different than others since it was
398 # mentioned in the documentation that has to be set to 'y' instead of 'true' to
399 # enable it. This caused a lot of confusion to users that set the option to 'y',
400 # 'yes' or 'true'. This was fixed but all of these values must be supported now.
401 if [ "x${GRUB_DISABLE_SUBMENU}" = xyes ] || [ "x${GRUB_DISABLE_SUBMENU}" = xy ]; then
402 GRUB_DISABLE_SUBMENU="true"
405 if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then
406 linux_entry "${OS}" "${version}" simple \
407 "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
409 submenu_indentation="$grub_tab"
411 if [ -z "$boot_device_id" ]; then
412 boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
414 # TRANSLATORS: %s is replaced with an OS name
415 echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
419 linux_entry "${OS}" "${version}" advanced \
420 "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
421 if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
422 linux_entry "${OS}" "${version}" recovery \
423 "${GRUB_CMDLINE_LINUX_RECOVERY} ${GRUB_CMDLINE_LINUX}"
427 # If at least one kernel was found, then we need to
428 # add a closing '}' for the submenu command.
429 if [ x"$is_top_level" != xtrue ]; then
433 echo "$title_correction_code"