grub: save ang read default menu item
If the ISO image has a FAT partition and the image is written to a flash drive, then it is possible to write to this partition of the flash drive. This is necessary, for example, if the user does not want to install the system, but wants to constantly work in LiveCD mode with or without recording sessions. In order for this code to work, you need to make changes to the FAT partition of the image on the flash drive: Add the 1st line to the grub.cfg file: set pfxfat=${prefix} Write a 1kb file grubenv. If grub.cfg contains a line like '^default=id', then the read value is not used.
This commit is contained in:
parent
aed27a30f8
commit
efec47fa42
@ -10,3 +10,15 @@ if [ "$grub_platform" = "efi" -a "$grub_cpu" = "x86_64" ]; then
|
||||
fi
|
||||
if [ "$grub_platform" = "pc" ]; then set linux_suffix='16'; fi
|
||||
if [ ! "$lang" ]; then lang=@LOCALE@; fi
|
||||
if [ -s $pfxfat/grubenv ]; then
|
||||
load_env --file $pfxfat/grubenv
|
||||
set default="${saved_entry}"
|
||||
else
|
||||
default=@default_id@
|
||||
fi
|
||||
function savedefault {
|
||||
if [ -z "${boot_once}" -a -s $pfxfat/grubenv ]; then
|
||||
saved_entry="${chosen}"
|
||||
save_env --file $pfxfat/grubenv saved_entry
|
||||
fi
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
|
||||
default='linux'
|
||||
|
||||
menuentry $"Install "'@distro@' --hotkey 'i' --id 'linux' {
|
||||
echo $"Loading Linux vmlinuz$KFLAVOUR ..."
|
||||
linux$linux_suffix /boot/vmlinuz$KFLAVOUR fastboot @initrd_bootargs@ @stagename@=altinst ramdisk_size=@altinst_size@ vga=@bootvga@ @bootargs@ $EFI_BOOTARGS lang=$lang
|
||||
|
@ -1,4 +1,5 @@
|
||||
menuentry $"LiveCD (no hard disk needed)" --id 'live' {
|
||||
savedefault
|
||||
echo $"Loading Linux vmlinuz$KFLAVOUR ..."
|
||||
linux$linux_suffix /boot/vmlinuz$KFLAVOUR fastboot live @initrd_bootargs@ @stagename@=live ramdisk_size=@live_size@ showopts lowmem vga=@bootvga@ @bootargs@ $EFI_BOOTARGS lang=$lang
|
||||
echo $"Loading initial ramdisk ..."
|
||||
|
@ -1,4 +1,5 @@
|
||||
menuentry $"LiveCD with sessions support" --id 'session' {
|
||||
savedefault
|
||||
echo $"Loading Linux vmlinuz$KFLAVOUR ..."
|
||||
linux$linux_suffix /boot/vmlinuz$KFLAVOUR fastboot live @initrd_bootargs@ @stagename@=live ramdisk_size=@live_size@ showopts live_rw vga=@bootvga@ @bootargs@ $EFI_BOOTARGS lang=$lang
|
||||
echo $"Loading initial ramdisk ..."
|
||||
|
@ -1,4 +1,5 @@
|
||||
menuentry $"Rescue LiveCD" --id 'rescue' {
|
||||
savedefault
|
||||
echo $"Loading Linux vmlinuz$KFLAVOUR ..."
|
||||
linux$linux_suffix /boot/vmlinuz$KFLAVOUR changedisk fastboot live @initrd_bootargs@ @stagename@=rescue ramdisk_size=@rescue_size@ splash=0 showopts @rescue_bootargs@ $EFI_BOOTARGS
|
||||
echo $"Loading initial ramdisk ..."
|
||||
|
@ -1,4 +1,5 @@
|
||||
menuentry $"Rescue with sessions support" --id 'rescue_session' {
|
||||
savedefault
|
||||
echo $"Loading Linux vmlinuz$KFLAVOUR ..."
|
||||
linux$linux_suffix /boot/vmlinuz$KFLAVOUR changedisk fastboot live @initrd_bootargs@ @stagename@=rescue ramdisk_size=@rescue_size@ splash=0 showopts @rescue_bootargs@ $EFI_BOOTARGS live_rw
|
||||
echo $"Loading initial ramdisk ..."
|
||||
|
@ -36,8 +36,11 @@ if [ -n "$GLOBAL_GRUB_DEFAULT" ]; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
DEFAULT="$(grep -i '\-\-id ' "$CFG" | head -1 | rev| cut -f2 -d' ' |rev)"
|
||||
if grep -i '@default_id@' "$CFG"; then
|
||||
sed -i "s/@default_id@/$DEFAULT/" "$CFG"
|
||||
fi
|
||||
if ! grep -i '^\s*\(set\s\+\)\?default=' "$CFG"; then
|
||||
DEFAULT="$(grep -i '\-\-id ' "$CFG" | head -1 | rev| cut -f2 -d' ' |rev)"
|
||||
if [ -n "$DEFAULT" ]; then
|
||||
echo "default=$DEFAULT" >> "$CFG"
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user