]> git.somenet.org - root/pub/somesible.git/blob - roles/base/grub/templates/10_linux.j2
roles/service/mattermost/defaults
[root/pub/somesible.git] / roles / base / grub / templates / 10_linux.j2
1 #! /bin/sh
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>
7 #
8 set -e
9
10 # grub-mkconfig helper script.
11 # Copyright (C) 2006,2007,2008,2009,2010  Free Software Foundation, Inc.
12 #
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.
17 #
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.
22 #
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/>.
25
26 prefix="/usr"
27 exec_prefix="/usr"
28 datarootdir="/usr/share"
29 ubuntu_recovery="0"
30 quiet_boot="0"
31 quick_boot="0"
32 gfxpayload_dynamic="0"
33 vt_handoff="0"
34
35 . "$pkgdatadir/grub-mkconfig_lib"
36
37 export TEXTDOMAIN=grub
38 export TEXTDOMAINDIR="${datarootdir}/locale"
39
40 {% if grub_pw_admin | default("") != "" %}
41 cat << EOF
42 set superusers="admin"
43 password_pbkdf2 admin {{grub_pw_admin}}
44 EOF
45
46 CLASS="--class gnu-linux --class gnu --class os --unrestricted"
47 {% else %}
48 # no pw defined.
49 #cat << EOF
50 #set superusers="admin"
51 #password_pbkdf2 admin grub_pw_admin
52 #EOF
53 # no pw defined.
54
55 CLASS="--class gnu-linux --class gnu --class os"
56 {% endif %}
57
58 if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
59   OS=GNU/Linux
60 else
61   case ${GRUB_DISTRIBUTOR} in
62     Ubuntu|Kubuntu)
63       OS="${GRUB_DISTRIBUTOR}"
64       ;;
65     *)
66       OS="${GRUB_DISTRIBUTOR} GNU/Linux"
67       ;;
68   esac
69   CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
70 fi
71
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
79       /dev/*) ;;
80       *) exit 0 ;;
81     esac
82   ;;
83 esac
84
85 : ${GRUB_CMDLINE_LINUX_RECOVERY:=single}
86
87 # Default to disabling partition uuid support to maintian compatibility with
88 # older kernels.
89 : ${GRUB_DISABLE_LINUX_PARTUUID=true}
90
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}
103 else
104   LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
105 fi
106
107 case x"$GRUB_FS" in
108     xbtrfs)
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}"
113         fi;;
114     xzfs)
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%/}"
118         ;;
119 esac
120
121 title_correction_code=
122
123 if [ -x /lib/recovery-mode/recovery-menu ]; then
124     GRUB_CMDLINE_LINUX_RECOVERY="${GRUB_CMDLINE_LINUX_RECOVERY} recovery"
125 else
126     GRUB_CMDLINE_LINUX_RECOVERY="${GRUB_CMDLINE_LINUX_RECOVERY} single"
127 fi
128 if [ "$ubuntu_recovery" = 1 ]; then
129     GRUB_CMDLINE_LINUX_RECOVERY="$GRUB_CMDLINE_LINUX_RECOVERY nomodeset"
130 fi
131
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"
136     fi
137   done
138 fi
139
140 linux_entry ()
141 {
142   os="$1"
143   version="$2"
144   type="$3"
145   args="$4"
146
147   if [ -z "$boot_device_id" ]; then
148       boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
149   fi
150   if [ x$type != xsimple ] ; then
151       case $type in
152           recovery)
153               title="$(gettext_printf "%s, with Linux %s (%s)" "${os}" "${version}" "$(gettext "${GRUB_RECOVERY_TITLE}")")" ;;
154           *)
155               title="$(gettext_printf "%s, with Linux %s" "${os}" "${version}")" ;;
156       esac
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")"
162       fi
163       echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
164   else
165       echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
166   fi
167   if [ "$quick_boot" = 1 ]; then
168       echo "    recordfail" | sed "s/^/$submenu_indentation/"
169   fi
170   if [ x$type != xrecovery ] ; then
171       save_default_entry | grub_add_tab
172   fi
173
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/"
178   else
179       if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
180           echo "        load_video" | sed "s/^/$submenu_indentation/"
181       fi
182   fi
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/"
186   fi
187
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/"
190
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)"
194     fi
195     printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
196   else
197     if [ -z "${prepare_boot_cache}" ]; then
198       prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
199     fi
200     printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
201   fi
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)'
206 EOF
207   fi
208   sed "s/^/$submenu_indentation/" << EOF
209         linux   ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args}
210 EOF
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)'
217 EOF
218     fi
219     initrd_path=
220     for i in ${initrd}; do
221       initrd_path="${initrd_path} ${rel_dirname}/${i}"
222     done
223     sed "s/^/$submenu_indentation/" << EOF
224         initrd  $(echo $initrd_path)
225 EOF
226   fi
227   sed "s/^/$submenu_indentation/" << EOF
228 }
229 EOF
230 }
231
232 machine=`uname -m`
233 case "x$machine" in
234     xi?86 | xx86_64)
235         list=
236         for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
237             if grub_file_is_not_garbage "$i" ; then list="$list $i" ; fi
238         done ;;
239     *)
240         list=
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
243         done ;;
244 esac
245
246 case "$machine" in
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" ;;
252 esac
253
254 case "$GENKERNEL_ARCH" in
255   x86*) GRUB_CMDLINE_LINUX_RECOVERY="$GRUB_CMDLINE_LINUX_RECOVERY dis_ucode_ldr";;
256 esac
257
258 prepare_boot_cache=
259 prepare_root_cache=
260 boot_device_id=
261 title_correction_code=
262
263 cat << 'EOF'
264 function gfxmode {
265         set gfxpayload="${1}"
266 EOF
267 if [ "$vt_handoff" = 1 ]; then
268   cat << 'EOF'
269         if [ "${1}" = "keep" ]; then
270                 set vt_handoff=vt.handoff=7
271         else
272                 set vt_handoff=
273         fi
274 EOF
275 fi
276 cat << EOF
277 }
278 EOF
279
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"
284 else
285   cat << EOF
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
293       else
294         set linux_gfx_mode=text
295       fi
296     else
297       set linux_gfx_mode=text
298     fi
299   else
300     set linux_gfx_mode=keep
301   fi
302 else
303   set linux_gfx_mode=text
304 fi
305 EOF
306 fi
307 cat << EOF
308 export linux_gfx_mode
309 EOF
310
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=""
314
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.
319
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$//')
321
322 if [ "x$GRUB_TOP_LEVEL" != x ]; then
323   reverse_sorted_list=$(grub_move_to_front "$GRUB_TOP_LEVEL" ${reverse_sorted_list})
324 fi
325
326 is_top_level=true
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}"
335
336   initrd_early=
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}"
341     fi
342   done
343
344   initrd_real=
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
356       initrd_real="${i}"
357       break
358     fi
359   done
360
361   initrd=
362   if test -n "${initrd_early}" || test -n "${initrd_real}"; then
363     initrd="${initrd_early} ${initrd_real}"
364
365     initrd_display=
366     for i in ${initrd}; do
367       initrd_display="${initrd_display} ${dirname}/${i}"
368     done
369     gettext_printf "Found initrd image: %s\n" "$(echo $initrd_display)" >&2
370   fi
371
372   config=
373   for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
374     if test -e "${i}" ; then
375       config="${i}"
376       break
377     fi
378   done
379
380   initramfs=
381   if test -n "${config}" ; then
382       initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
383   fi
384
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
390
391         linux_root_device_thisversion=${GRUB_DEVICE}
392     else
393         linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID}
394     fi
395   fi
396
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"
403   fi
404
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}"
408
409     submenu_indentation="$grub_tab"
410
411     if [ -z "$boot_device_id" ]; then
412         boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
413     fi
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' {"
416     is_top_level=false
417   fi
418
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}"
424   fi
425 done
426
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
430   echo '}'
431 fi
432
433 echo "$title_correction_code"