Q: How to convert from legacy MBR to GPT required for UEFI?

A: Follow ServerFault: How do I convert my linux disk from MBR to GPT with UEFI

  • Creating the “BIOS boot partition” is only needed if you want to do the conversion in small steps, e.g. convert to GPT first and still use grub-pc for booting. You can skip this step if you convert to GPT and grub-efi-amd64-bin at the same time.

Some more notes:

# Install software
apt-get install gdisk dosfstools grub-efi-amd64-bin efibootmgr

# Create EFI System Partition at end of disk
gdisk /dev/sda
# n
# <free>
# -1G
# <default>
# EF00
# w

# Format EFI partition
mkfs -t vfat -v /dev/disk/by-partlabel/EFI

# Mount EFI partition
raw="$(readlink /dev/disk/by-partlabel/EFI\\x20system\\x20partition)"
uuid="$(find /dev/disk/by-uuid -lname "${raw}" -printf '%f\n')"
install -m 0700 -d /boot/efi
echo "UUID=${uuid}	/boot/efi	vfat	umask=0077	0	2" >>/etc/fstab
mount /boot/efi

# Install EFI GRUB
grub-install /dev/sda --target=x86_64-efi --efi-directory=/boot/efi/ --bootloader-id=debian
efibootmgr -v
# efibootmgr -B -b X

# <F12> -> boot-mager -> local file -> EFI\debian\shimx64.efi

# Remove legacy GRUB
apt-get purge grub-pc grub-pc-bin
rm -rf /boot/grub/i386-pc
Written on March 10, 2022