Biosias / uefi-mkconfig

grub-mkconfig inspired script for automatically managing uefi entries for booting linux kernel directly without bootloader
Apache License 2.0
7 stars 3 forks source link

wrong boot order on old EFI BIOSes #11

Closed glorg closed 2 months ago

glorg commented 2 months ago

It was noticed that on at least one server the boot order is reset on reboot and sorted by ID with booting the lowest number regardless of boot order set before reboot.

In other words, if the following command is issued

# efibootmgr -o 0103,0104,0105,0102,0100,0101,010A,0107,0109
# reboot

then in fact the item with ID 0100 is booted in this case. As the uefi-mkconfig script adds items with ascending order and processes partitions in reverse order, in the structure of

boot
└── EFI
    └── Gentoo
        ├── amd-uc.img
        ├── vmlinuz-6.9.6-gentoo-x86_64.efi
        └── vmlinuz-6.9.7-gentoo-x86_64.efi

/boot2
└── EFI
    └── Gentoo
        └── vmlinuz-6.9.6-gentoo-x86_64.efi

/boot3
└── EFI
    └── Gentoo
        └── vmlinuz-6.9.6-gentoo-x86_64.efi

the image vmlinuz-6.9.7-gentoo-x86_64.efi (the most recent kernel version) residing on first partition (mounted to /boot) is thus added last and gets ID of 0105 or 0107 (depending on number of other items), so on system reboot the oldest kernel (in the example above it will be /boot3/EFI/Gentoo/vmlinuz-6.9.6-gentoo-x86_64.efi gets the lowest ID (0100) and thus on reboot the system boots into the oldest kernel. To fix this, kernel list should be first built (for example, an array) and then added in the very order the kernels should be booted, so the newest kernel should be added first. However, on some BIOSes this will lead to setting the most recently added kernel (thus, the oldest /boot3/EFI/Gentoo/vmlinuz-6.9.6-gentoo-x86_64.efi in the example above) last and setting the boot order to boot last added kernel first. To deal with both BIOS behaviors, it might be good to a) on adding kernels, set the boot order before exiting the script and (b) make the order kernels are added reversible, so the user could change the configuration according to behavior of the particular BIOS. This will turn, however, into having special configuration file specifying the order kernel items are to be processed: oldest to latest or vise versa.

Biosias commented 2 months ago

Is fixed in next version