- Edited
So Eric asked me the other day if I had ideas about how to integrate options to the installer to provide auto install for UEFI.
Things the installer cannot provide:
- The user having fully understood the requirements and prepared a partitioning layout and table necessary to boot this way.
Things the installer could provide:
- Either an option somewhere whether to install for UEFI or BIOS which in return would influence the options of bootloaders when prompted - or when prompted for the bootloader the option to install either for BIOS or UEFI. I personally think that the first approach is less invasive to users who don't care.
- The choice between either GRUB or EFISTUB.
- The automatic execution of the necessary commands (GRUB x 2; EFISTUB x 1)
It would be a nice user experience if the script could automatically detect the setup and decide, but due to mixed layouts this is not possible. People can prepare a MBR table but use UEFI or make a GPT table and boot with BIOS. Also unexperienced users may mix up things to begin with. So if this was to be implemented it would have to be an option as described above. Probably an "expert option"?
It could/should be a verbose option. Something along the lines: "Firmware interface to use: BIOS/UEFI" where it defaults to BIOS (according to the instructions in the Wiki).
Also when thinking about it a lot of people possibly wouldn't know if they wanted to install UEFI or BIOS. They just "know" somehow that their computer uses a "BIOS" to get into their operating system. Even when todays motherboards don't even have a real BIOS anymore, rather a legacy emulation module for BIOS boot. So anything called different possibly ain't an option for them. As a consequence I think for now it actually should be an expert option indeed.
(Personally I'd promote default UEFI on any modern equipment for any OS, but that's just me ;)
So let's say the user prepared a GPT disk and an ESP as outlined in the manual, formatted and mounted everything accordingly.
What would the script need to do?
Once the the script is free to go, the option should trigger a choice of the two outlined bootloaders in the Wiki when the user chooses to "install a bootloader?"
Use a simple if condition (kinda verbose notation, I didn't look into the actual obarun-install script yet):
As for the GRUB installation:
Should be pretty straight forward (two lines inside of the corresponding conditional from above):
As for EFISTUB:
(Needs a few more lines to make it fool proof)
Although I outline microcode and the resume kernel parameter in the manual, it is not a hard requirement for the system to be able to boot. Still it should be mentioned during the install that the script does not cover those and needs manual recreation of the NVRAM entry.
In short it's rather simple really:
Create the option
> If option is changed from "BIOS": Run the checks and make a conditional select in bootloader prompt
> Install based on choice
I'd also be ready to test this on VMs once it's in some dev branch.
Things the installer cannot provide:
- The user having fully understood the requirements and prepared a partitioning layout and table necessary to boot this way.
Things the installer could provide:
- Either an option somewhere whether to install for UEFI or BIOS which in return would influence the options of bootloaders when prompted - or when prompted for the bootloader the option to install either for BIOS or UEFI. I personally think that the first approach is less invasive to users who don't care.
- The choice between either GRUB or EFISTUB.
- The automatic execution of the necessary commands (GRUB x 2; EFISTUB x 1)
It would be a nice user experience if the script could automatically detect the setup and decide, but due to mixed layouts this is not possible. People can prepare a MBR table but use UEFI or make a GPT table and boot with BIOS. Also unexperienced users may mix up things to begin with. So if this was to be implemented it would have to be an option as described above. Probably an "expert option"?
It could/should be a verbose option. Something along the lines: "Firmware interface to use: BIOS/UEFI" where it defaults to BIOS (according to the instructions in the Wiki).
Also when thinking about it a lot of people possibly wouldn't know if they wanted to install UEFI or BIOS. They just "know" somehow that their computer uses a "BIOS" to get into their operating system. Even when todays motherboards don't even have a real BIOS anymore, rather a legacy emulation module for BIOS boot. So anything called different possibly ain't an option for them. As a consequence I think for now it actually should be an expert option indeed.
(Personally I'd promote default UEFI on any modern equipment for any OS, but that's just me ;)
So let's say the user prepared a GPT disk and an ESP as outlined in the manual, formatted and mounted everything accordingly.
What would the script need to do?
- efibootmgr is already part of the script (no effort)
- Have the grub package included (very little effort)
- Offer the option to use UEFI (very little effort)
- For advanced user experience do a post-check on the layout after choosing this option to warn the user of possible misconfigurations (some effort)
(store the variables globally for later access):- Check for the partition table type (store and compare to string):
DISK=`lsblk -o MOUNTPOINT,NAME | grep "/mnt" | tail -c 5 | sed s/.$//` && TABLE=`sfdisk -l /dev/$DISK | grep "Disklabel" | sed 's/Disklabel\ type:\ //'`
- And throw a warning if its not GPT (Cannot simply evaluate true to msdos as there are many others [script must not exit here, user might wanna run UEFI on MBR]):
[[ $TABLE != "gpt" ]] && echo "Warning: Your disk was not formatted with a GUID Partition Table! \nTo boot with UEFI it is highly recommended to use a GPT table."
- Check for the ESP (store and compare to false):
ESP=`lsblk -p -o PARTTYPE /dev/$DISK | grep 'c12a7328-f81f-11d2-ba4b-00a0c93ec93b'`
- Throw an error if it doesn't exist (optionally exit out of the script, need to evaluate the user experience at this point [Thinking about it rather make it a prompt whether to exit out of the script since the user might decide to uncheck the option/use default BIOS instead]):
[[ ! $ESP ]] && echo "Error: No EFI system partition found! \nManually check your disk layout before continuing." && echo -n "Exit the script to review partitions? "; read CHOICE
- Else just keep going
- Check for the partition table type (store and compare to string):
Once the the script is free to go, the option should trigger a choice of the two outlined bootloaders in the Wiki when the user chooses to "install a bootloader?"
Use a simple if condition (kinda verbose notation, I didn't look into the actual obarun-install script yet):
if [[ $FIRMWARE = "UEFI" ]]; then
echo "You can choose one of these bootloaders: "
Create your recent up/down selection menu (PS3 select?) with GRUB/EFISTUB instead of Yes/No
if [[ $GRUB ]]; then
install GRUB (see below)
else
install EFISTUB (see below)
else
install syslinux
fi
As for the GRUB installation:
Should be pretty straight forward (two lines inside of the corresponding conditional from above):
- Get the ESPs mount point (This should be /efi for GRUB as outlined in the Wiki but the user might not care and use the deprecated /boot instead):
EFIMOUNT=`lsblk -p -o PARTTYPE,MOUNTPOINT /dev/$DISK | grep 'c12a7328-f81f-11d2-ba4b-00a0c93ec93b' | sed 's/c12a7328-f81f-11d2-ba4b-00a0c93ec93b //'`
- Chroot into /mnt (Use `arch-chroot`!!!!!) to install and configure Grub. Other chroots do NOT work without bugs/nuisances/errors at this point (Unsure whether the call to the variable would work in this context, might become local to the chroot environment?)!
arch-chroot /mnt grub-install --target=x86_64-efi --efi-directory=$EFIMOUNT --bootloader-id=grub && grub-mkconfig -o /boot/grub/grub.cfg
- Done. Continue script
As for EFISTUB:
(Needs a few more lines to make it fool proof)
Although I outline microcode and the resume kernel parameter in the manual, it is not a hard requirement for the system to be able to boot. Still it should be mentioned during the install that the script does not cover those and needs manual recreation of the NVRAM entry.
- Check the ESPs mount point (This should be /boot for the script to work. Need to error out if it's not [because it's possible but needs customization of the --loader option]):
EFIMOUNT=`lsblk -p -o PARTTYPE,MOUNTPOINT /dev/$DISK | grep 'c12a7328-f81f-11d2-ba4b-00a0c93ec93b' | sed 's/c12a7328-f81f-11d2-ba4b-00a0c93ec93b //'` [[ ! $EFIMOUNT = "/boot" ]] && echo "Error: Your EFI system partition is not mounted at /boot! \nThis script needs it to be mounted at that location. \nExit the script now?"; read CHOICE
- Get several more system details and store as variable (only locally as they'll not be need elsewhere):
(the tail command counts line breaks so we need to cut off what we want + 1)PARTITION=`lsblk -p -o PARTTYPE,NAME $DISK | grep 'c12a7328-f81f-11d2-ba4b-00a0c93ec93b' | tail -c 2` ROOT=`lsblk -p -o MOUNTPOINT,PARTUUID $DISK | grep "/mnt" | tail -c 37`
- Make the NVRAM entry:
(Make sure the single quotes are correct! the --unicode option is a string, so it needs to be escaped right for variables to be used)efibootmgr -c -d $DISK -p $PARTITION -L 'Obarun' -l \vmlinuz-linux -u 'root=PARTUUID='$ROOT' ro initrd=\initramfs-linux.img'
- Inform the user about manual intervention:
echo "Notice: Microcode and custom kernel parameters require manual reconstruction of the NVRAM entry. \nRefer to https://wiki.archlinux.org/index.php/EFISTUB# efibootmgr and efibootmgr(8)"
- Done. Continue script
In short it's rather simple really:
Create the option
> If option is changed from "BIOS": Run the checks and make a conditional select in bootloader prompt
> Install based on choice
I'd also be ready to test this on VMs once it's in some dev branch.