4 # grub-mkconfig helper script.
5 # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
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.
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.
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/>.
22 if [ -f /etc/grub.d/10_linux ]; then
23 chmod -x /etc/grub.d/10_linux
26 # Disable 10_archlinux
27 if [ -f /etc/grub.d/10_archlinux ]; then
28 chmod -x /etc/grub.d/10_archlinux
33 datarootdir="/usr/share"
35 . "${datarootdir}/grub/grub-mkconfig_lib"
37 export TEXTDOMAIN=grub
38 export TEXTDOMAINDIR="${datarootdir}/locale"
40 CLASS="--class gnu-linux --class gnu --class os"
42 if [ "${GRUB_DISTRIBUTOR}" = "Antergos" ]; then
43 CLASS="--class arch ${CLASS}"
46 if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
50 CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
53 # loop-AES arranges things so that /dev/loop/X can be our root device, but
54 # the initrds that Linux uses don't like that.
55 case ${GRUB_DEVICE} in
56 /dev/loop/*|/dev/loop[0-9])
57 GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
61 if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
62 || ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
63 || uses_abstraction "${GRUB_DEVICE}" lvm; then
64 LINUX_ROOT_DEVICE=${GRUB_DEVICE}
66 LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
71 rootsubvol="`make_system_path_relative_to_its_root /`"
72 rootsubvol="${rootsubvol#/}"
73 if [ "x${rootsubvol}" != x ]; then
74 GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
77 rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
78 bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
79 LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
84 if test -e "/boot/intel-ucode.img" ; then
85 gettext_printf "Found Intel Microcode image\n" >&2
86 intel_ucode="$(make_system_path_relative_to_its_root /boot/intel-ucode.img)"
89 title_correction_code=
98 if [ "$os" == "Antergos Linux" ] || [ "$os" == "Arch Linux" ] || [ "$os" == "Manjaro Linux" ] || [ "$os" == "RebornOS" ]; then
102 if [ -z "$boot_device_id" ]; then
103 boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
105 if [ x$type != xsimple ] && [ "$is_arch" != True ]; then
108 title="$(gettext_printf "%s, with Linux %s (recovery mode)" "${os}" "${version}")" ;;
110 title="$(gettext_printf "RebornOS, with Linux %s (fallback initramfs)" "${os}" "${version}")" ;;
112 title="$(gettext_printf "RebornOS, with %s Kernel" "${os}" "${version}")" ;;
114 if [ x"$title" = x"$GRUB_ACTUAL_DEFAULT" ] || [ x"Previous Linux versions>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
115 replacement_title="$(echo "Advanced options for RebornOS" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
116 quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
117 title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
118 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")"
120 echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
122 if [ "$is_arch" ]; then
123 if [ x$type != xfallback ]; then
124 if [ "$version" == "linux" ]; then
125 title="$(gettext_printf "%s" "${os}")"
126 elif [ "$version" == "linux-lts" ]; then
127 title="$(gettext_printf "RebornOS LTS Kernel" "${os}")"
129 title="$(gettext_printf "RebornOS, with %s Kernel" "${os}" "${version}")"
132 if [ "$version" == "linux" ]; then
133 title="$(gettext_printf "RebornOS - Fallback" "${os}")"
134 elif [ "$version" == "linux-lts" ]; then
135 title="$(gettext_printf "RebornOS LTS Kernel - Fallback" "${os}")"
137 title="$(gettext_printf "RebornOS, with %s Kernel - Fallback" "${os}" "${version}")"
143 echo "menuentry '$(echo "$os" | grub_quote)' ${CLASS} \$menuentry_id_option 'gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
145 if [ x$type != xrecovery ] && [ x$type != xfallback ] ; then
146 save_default_entry | grub_add_tab
149 # Use ELILO's generic "efifb" when it's known to be available.
150 # FIXME: We need an interface to select vesafb in case efifb can't be used.
151 if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then
152 echo " load_video" | sed "s/^/$submenu_indentation/"
153 if grep -qx "CONFIG_FB_EFI=y" "${config}" 2> /dev/null \
154 && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" "${config}" 2> /dev/null; then
155 echo " set gfxpayload=keep" | sed "s/^/$submenu_indentation/"
158 if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
159 echo " load_video" | sed "s/^/$submenu_indentation/"
161 echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
164 echo " insmod gzio" | sed "s/^/$submenu_indentation/"
166 if [ x$dirname = x/ ]; then
167 if [ -z "${prepare_root_cache}" ]; then
168 prepare_root_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE} | grub_add_tab)"
170 printf '%s\n' "${prepare_root_cache}" | sed "s/^/$submenu_indentation/"
172 if [ -z "${prepare_boot_cache}" ]; then
173 prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
175 printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
177 message="$(gettext_printf "Loading %s kernel ..." ${version})"
178 sed "s/^/$submenu_indentation/" << EOF
179 echo '$(echo "$message" | grub_quote)'
180 linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} rw ${args}
182 if test -n "${initrd}" ; then
183 if [ "$is_arch" ] && [ x$type = xfallback ] ; then
184 initrd="initramfs-${version}-fallback.img"
186 # TRANSLATORS: ramdisk isn't identifier. Should be translated.
187 message="$(gettext_printf "Loading initial ramdisk ...")"
188 sed "s/^/$submenu_indentation/" << EOF
189 echo '$(echo "$message" | grub_quote)'
190 initrd ${intel_ucode} ${rel_dirname}/${initrd}
193 sed "s/^/$submenu_indentation/" << EOF
201 list=`for i in /boot/vmlinuz-* /vmlinuz-* /boot/kernel-* ; do
202 if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
205 list=`for i in /boot/vmlinuz-* /boot/vmlinux-* /vmlinuz-* /vmlinux-* /boot/kernel-* ; do
206 if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
211 i?86) GENKERNEL_ARCH="x86" ;;
212 mips|mips64) GENKERNEL_ARCH="mips" ;;
213 mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
214 arm*) GENKERNEL_ARCH="arm" ;;
215 *) GENKERNEL_ARCH="$machine" ;;
221 title_correction_code=
223 # Extra indentation to add to menu entries in a submenu. We're not in a submenu
224 # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
225 submenu_indentation=""
228 while [ "x$list" != "x" ] ; do
229 if [ $(echo $list | grep -q '[0-9]') ]; then
230 linux=`version_find_latest $list`
236 gettext_printf "Found linux image: %s\n" "$linux" >&2
237 basename=`basename $linux`
238 dirname=`dirname $linux`
239 rel_dirname=`make_system_path_relative_to_its_root $dirname`
240 version=`echo $basename | sed -e "s,vmlinuz-,,g"`
241 alt_version=`echo $version | sed -e "s,\.old$,,g"`
242 linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
245 for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
246 "initrd-${version}" "initramfs-${version}.img" \
247 "initrd.img-${alt_version}" "initrd-${alt_version}.img" \
248 "initrd-${alt_version}" "initramfs-${alt_version}.img" \
249 "initrd-linux-${version}" "initramfs-linux-${version}.img" \
250 "initrd-linux-${alt_version}" "initramfs-linux-${alt_version}.img" \
251 "initramfs-genkernel-${version}" \
252 "initramfs-genkernel-${alt_version}" \
253 "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
254 "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
255 if test -e "${dirname}/${i}" ; then
262 for i in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
263 if test -e "${i}" ; then
270 if test -n "${config}" ; then
271 initramfs=`grep CONFIG_INITRAMFS_SOURCE= "${config}" | cut -f2 -d= | tr -d \"`
274 if test -n "${initrd}" ; then
275 gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2
276 elif test -z "${initramfs}" ; then
277 # "UUID=" and "ZFS=" magic is parsed by initrd or initramfs. Since there's
278 # no initrd or builtin initramfs, it can't work here.
279 linux_root_device_thisversion=${GRUB_DEVICE}
282 # GRUB_DISABLE_SUBMENU=y is the documented value to disable the submenu, testing for true is for backwards compatibility with Antergos
283 # see https://wiki.archlinux.org/index.php/GRUB/Tips_and_tricks#Disable_submenu
284 if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ] && [ "x${GRUB_DISABLE_SUBMENU}" != xtrue ]; then
285 linux_entry "${OS}" "${version}" simple \
286 "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
288 submenu_indentation="$grub_tab"
290 if [ -z "$boot_device_id" ]; then
291 boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
293 # TRANSLATORS: %s is replaced with an OS name
294 echo "submenu '$(gettext_printf "Advanced options for %s" "RebornOS" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
298 linux_entry "${OS}" "${version}" advanced \
299 "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
300 if test -e "${dirname}/initramfs-${version}-fallback.img" ; then
301 initrd="initramfs-${version}-fallback.img"
303 if test -n "${initrd}" ; then
304 gettext_printf "Found fallback initramfs image: %s\n" "${dirname}/${initrd}" >&2
307 linux_entry "${OS}" "${version}" fallback \
308 "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
310 if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
311 linux_entry "${OS}" "${version}" recovery \
312 "single ${GRUB_CMDLINE_LINUX}"
315 list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '`
318 # If at least one kernel was found, then we need to
319 # add a closing '}' for the submenu command.
320 if [ x"$is_top_level" != xtrue ]; then
324 echo "$title_correction_code"