Skip to content

Instantly share code, notes, and snippets.

@xenithorb
Last active February 10, 2018 20:17
Show Gist options
  • Save xenithorb/a7cd12c3482a2c5de73fd4e90a24b793 to your computer and use it in GitHub Desktop.
Save xenithorb/a7cd12c3482a2c5de73fd4e90a24b793 to your computer and use it in GitHub Desktop.
Add redundant menuentries in GRUB with extra cmdline paramaters
# IMPORTANT: Add the following to /etc/default/grub first!
#
# export GRUB_CMDLINE_LINUX_APPEND='<your_extra_cmdline_params>'
# export GRUB_OS_NAME_APPEND='<your_appended_id>'
#
# Note: ^ The export at the beginning is imperative unlike the rest
#
# Also maybe of interest (to save the selection):
#
# GRUB_DEFAULT=saved
# GRUB_SAVEDEFAULT=true
#
GRUB_DISABLE_RECOVERY=true
GRUB_LINUX_MAKE_DEBUG=false
OS_VERS="$(eval $(grep ^VERSION= /etc/os-release) ; echo ${VERSION})"
OS_VERS+=" ${GRUB_OS_NAME_APPEND}"
GRUB_CMDLINE_LINUX+=" ${GRUB_CMDLINE_LINUX_APPEND}"
menuentry_id_append=$(sed 's|[[:space:]]|_|g;s|[[:punct:]]||g;s|\(.*\)|\L\1|' <<< "${GRUB_OS_NAME_APPEND:-custom}" )
fifo="${0}_fifo"; mkfifo "$fifo"
sed -e '/^[ ]*OS_VERS=.*/d;/^[ ]*local OS_VERS/d;/^#/d' \
-e 's|advanced standard \\|advanced-'"${menuentry_id_append}"' standard \\|' \
${0%/*}/10_linux > "$fifo" &
source "$fifo"
rm "$fifo"
@xenithorb
Copy link
Author

Small revision to the grub entry duplicator

https://gist.github.com/xenithorb/a7cd12c3482a2c5de73fd4e90a24b793/revisions#diff-3ba936fd2b2a7eb91978a384d602ba46

Due to:

 root  /  etc  grub.d  cat /etc/grub2.cfg | grep 'gnulinux-4.14.18-300.fc27.x86_64'
menuentry 'Fedora (4.14.18-300.fc27.x86_64) 27 (Twenty Seven)' --class fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-4.14.18-300.fc27.x86_64-advanced-/dev/map
menuentry 'Fedora (4.14.18-300.fc27.x86_64) 27 (Twenty Seven) (HTPC VIDEO)' --class fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-4.14.18-300.fc27.x86_64-adva
 root  /  etc  grub.d 
 root  /  etc  grub.d  grub2-editenv /boot/grub2/grubenv list
saved_entry=gnulinux-4.14.18-300.fc27.x86_64-advanced-/dev/mapper/fedora-root
15:08

They would previously be generated with the same "id" and thus grub would pick the first one when savedefault is used ... so it picks the wrong one - with this patch it adds a lowered/trimmed version of GRUB_OS_NAME_APPEND to the id to make it unique.

So now with:

GRUB_SAVEDEFAULT=true
GRUB_DEFAULT=saved

It produces (in /boot/grub2/grubenv):

saved_entry=gnulinux-4.14.18-300.fc27.x86_64-advanced-htpcvideo-/dev/mapper/fedora-root

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment