converting from a BIOS/CSM booted system to UEFI

Christoph Anton Mitterer calestyo at scientia.net
Thu Jul 8 20:37:24 BST 2021


Hey.

I was looking into converting my BIOS/CSM booted systems to UEFI.


First, what's documented there:
https://wiki.debian.org/GrubEFIReinstall
is IMO a bit unfortunate.

I think the process works just fine from a BIOS/CSM booted system,
without the use of any live CDs or foreign non-Debian images (like
rEFInd rescue media mentioned there).

These all have the risk that people don't (cryptographically) verify
them properly and even if, ... in the case of 3rd party images, one
never really knows what's inside them.


What I did was basically the following:
a) Preparations
- changed the partition type of my EF02  BIOS boot partition
  EF00  EFI system partition
- created a FAT32 on it mkfs.vfat -F 32 -n ESP /dev/...
- mkdir /boot/efi
- set up some /etc/fstab for it:
  /dev/disk/by-label/ESP          /boot/efi       vfat   
nouser,nodev,noexec,nosuid,noatime,dmask=7022,fmask=7133,discard       
0       2
- mount /boot/efi
- made a backup of /etc/default/grub
- doing the following in two steps seemed to work cleaner: 
  aptitude purge grub-pc
  rm -rf /boot/grub/
  aptitude install grub-efi-amd64
- merge back any changes from the backup of /etc/default/grub

b) first installation of grub-efi from the BIOS/CSM booted system
   (i.e. withOUT /sys/firmware/efi/)
- grub-install --target=x86_64-efi
  mkdir /boot/efi/EFI/BOOT
  #maybe some warning, that other bootloaders may already be in that
  #location
  cp -a /boot/efi/EFI/debian/grubx64.efi /boot/efi/EFI/BOOT/bootx64.efi
- update-grub
- reboot

c) "regular" installation of grub-efi from the UEFI booted system
   (i.e. with /sys/firmware/efi/)
- rm -rf /boot/efi/EFI/BOOT 
- grub-install
- update-grub


Maybe someone with edit rights on https://wiki.debian.org/ might want
to add this there (perhaps after some polishing) and maybe also to
README.Debian?




Anyway, this isn't the reason I'm writing :-)

I'd have two questions:


1) The UEFI finds the ESP by searching for the proper MBR/GPT partition
type. And there if finds the right bootloader by the settings in NVRAM
or by falling back to EFI/BOOT/... .
Right?

But how does the grub there then find grub.cfg within /boot/?

I've seen some Debians at the our institute's cluster which have:
/boot/efi/EFI/debian/grub.cfg:
        search.fs_uuid c8f2559f-1c5d-4f54-9487-5ec5d97d2c73 root
hd0,gpt2 
        set prefix=($root)'/boot/grub'
        configfile $prefix/grub.cfg

but that file doesn't seem to be generated by grub-install or update-
grub... and my system boots just fine without?

Should it be there? Can it get (auto-)generated by the grub-tools?



2) With grub-pc, a dpkg-reconfigure cause it to:
- ask for where it should be installed
- actually (re)install grub(-pc)

Okay the asking is probably irrelevant now, and Debian's grub simply
always requires the ESP to be mounted in /boot/efi, right?

But why does it not seem to re-install it even though it's in the
postinst?
*break*
Okay I accidentally had /boot/efi unmounted and it *does* reinstall it
properly when it's mounted.

But perhaps it should give a warning if /boot/efi is not mounted
instead of just saying nothing?
(Failing would be bad IMO, as people might have external boot devices,
like USB sticks für encrypted systems).


Thanks,
Chris.





More information about the Pkg-grub-devel mailing list