Before starting, make sure you have a backup, and make sure to have a linux live boot ready to rescue your system. It's easy to mess this up!
-
Use gdisk to convert the partition table to GPT.
gdisk /dev/sda
-
Create the "BIOS boot" partition that GRUB needs.
n
to create a new partition. Needs to be about 1MB. You can probably squeeze this in from sectors 34-2047. UseL
orl
to look up the code for "BIOS boot" (ef02). -
Write the new partition table.
w
-
Reload the partition table.
partprobe /dev/sda
-
Re-install the GRUB boot loader using the new partition scheme.
grub-install /dev/sda
Optionally reboot to verify it's working. If you just need GPT and not UEFI, you can stop here.
-
Use gdisk to add an "EFI System" partition (ESP). Officially should be 100-500MB, but mine only used 130kB. Can be anywhere on the disk, so consider putting it at the end if you're using non-resizable media like a physical disk.
gdisk /dev/sda
and usen
to create the partition. -
Give the ESP a distinctive label without whitespace like
EFI-system
, because we'll reference the partition label in fstab.c
to set the label. -
Write the partition table.
w
-
Reload the partition table.
partprobe /dev/sda
-
Build the filesystem for the ESP.
mkfs -t vfat -v /dev/disk/by-partlabel/EFI-system
-
Create the ESP mount point.
mkdir /boot/efi
-
Add the ESP to
/etc/fstab
. It should look like this:/dev/disk/by-partlabel/EFI-system /boot/efi vfat defaults 0 2
-
Mount the ESP.
mount /boot/efi
-
Install the GRUB EFI package.
apt install grub-efi
-
Install the GRUB EFI bootloader onto the disk.
grub-install --target=x86_64-efi /dev/sda
-
Reboot.
-
Change the BIOS from BIOS boot to UEFI boot.
-
Use the one-time boot menu to force boot the disk. You may have to navigate to the disk ->
EFI
->ubuntu
->grubx64.efi
. -
Re-install GRUB's EFI bootloader to update the UEFI boot selector.
grub-install
Resources:
- The author of
gdisk
has a verbose description of MBR, GPT, and UEFI. - https://serverfault.com/questions/765778/clonezilla-restore-mbr-disk-to-4tb-disk-convert-to-gpt-linux-not-windows covers the first part of the process.
Wonderful, it was a great help for me. I could convert my disk!
Some tips to include in the guide, as there can be some catches.
At the beginning of the guide, I would highlight the fact that it should be done on the system that boots the disk we need to convert. But! If you want to do it in a live boot or another system, go to 2.
If someone is already in trouble and cannot boot for some reason from the disk or has another system where there is a system disk already - that was my case:
Everything goes the same way as long you know which one is the disk you need to convert/fix. When you finish step 10, before you run 11, mount the root partition of the disk you want to fix:
a) Create mnt dir: mkdir -p /mnt/fixthis
b) Mount the partition to it (check the right disk and partition with lsblk): mount /dev/sdxy /mnt/fixthis
c) Change the root directory to it with chroot.
I have tested the following: you don't need to have anything between sectors 34-2047 as a BIOS boot partition if you only need EFI boot on modern systems. Not sure if creating the partition for BIOS boot as described in the first phase of this guide would make the disk boot in any system, be it BIOS legacy or EFI. I haven't tried that, but I'm okay with the EFI-only way.