I recently tried rebooting my NAS into a thumb drive with a custom Arch Linux maintenance image (containing the ZFS kernel modules and directly accessible over SSH).
After a quick Google, I found that
efibootmgr should be capable of doing that in one command — until I realized that I was booted in BIOS mode, not UEFI.
Some investigation later, I think the reason is that I used a non-UEFI-compatible GPU for the installation, which caused the Mainboard to boot in CSM mode.
Of course, nice features like choosing what to reboot into do not work in BIOS compatibility mode, so I need to get that sorted out. I do not have access to an unused UEFI-compatible GPU at the moment, but I figured I would do what I could until then.
I found a guide on serverfault which I was able to adapt for my needs. Since I was already using the GPT partitioning scheme, I did not need to convert from MBR and could skip the first 5 steps.
Freeing up space
I needed to make space for the EFI System Partition (ESP). Thankfully, I use LVM on root and had a lot of breathing room, so I did not need to resize the root FS or even the LV or VG, but only the PV (LVM physical volume).
Just to be sure that a reboot would work, because I have little experience with LVM, I also checked a few things:
- Do the UUIDs still match the values in the fstab?
- Do the LV and VG UUIDs still match the values passed to the kernel? (
sudo vgdisplay && sudo lvdisplay && cat /boot/grub/grub.cfg) where grub.cfg contains ‘lvmid/$VGUUID/$LVUUID’ multiple times.
If this hadn’t matched, I would have run
sudo update-grub and hoped for the best.
But apparently LVM UUIDs are independent of partition UUIDs, so I did not run into any problems with this at any step, even after resizing the physical partition.
Creating an ESP
Now, the next step is to resize the partition containing the LVM PV. To be sure I don’t overwrite everything, I left some buffer between the partitions. And just to remove any unit conversion ambiguity, I calculated everything in sector sizes.
PSize here is the size of the partition in sectors. The physical partition size can be viewed with
parted /dev/sdd unit s p.
Partitions cannot be resized, so the LVM partition needs to be deleted and re-created smaller.
Be sure to use the sector size shown in
pvs as the new partition size.
Now we can create the ESP, which I did using
gdisk to easily set the label (to “ESP” because I am very creative). Let’s update the kernel’s view of the drive with
sudo partprobe /dev/sdd. The final step is to create the file system – UEFI expects FAT32/VFAT – and mount the partition:
Next Step: re-installing GRUB for UEFI
I need to get another UEFI-capable GPU first. Then, I think it boils down to a few steps: