Ubuntu 12.04 Convert MBR to GPT and Legacy BIOS to UEFI using GRUB2

Category: Misc

Today I decided to finally take the leap and convert the disk containing my work Ubuntu 12.04 installation from an MBR-based partition table to the shiny and new GPT system.

I had been reading about the necessary steps, and the perils of doing so, for a few days and up until the very last minute I'd been going back and forth on the decision to bite the bullet. Unfortunately most of the information on the web was at least a year old with most posts dated in 2011 or 2012. So naturally a lot of them are slightly misleading and much of the information seems to be geared to people that own Macs or who want to dual-boot Windows 7 or 8 and Ubuntu.

My setup was not a dual boot and it was not a Mac. Everything I mention in the rest of this post refers to converting an already installed Ubuntu 12.04 deployed on a Dell Latitude E6410 with no other operating systems installed.

The Ubuntu installation was configured up with the GRUB2 bootloader and had a kernel installed. I had a separate /boot partition for GRUB and the kernel images.

The first step for me was to back everything up on an external hard drive. I've used clonezilla and backed everything up to the external USB hard drive.After I backed everything up I actually took the time to verify that the back up could be restored to a blank hard drive that I had lying around; this is highly recommended not only for peace of mind but in many cases the recovery could prove harder than actually taking the backup in the first place so it's really, really worth the time to verify that backups actually work!

Once I had everything backed up I used an Ubuntu 13.10 LiveCD to convert the previous MBR-based disk to GPT.

  1. boot into the LiveCD
  2. run gparted and resize & move the partitions as necessary to make room for an ESP (EFI System Partition) at the start of the disk, as well as make sure the rest of partitions are properly aligned to MiB boundaries, and that there is enough free space at the end of the disk
  3. install gdisk using sudo apt-get install gdisk
  4. run gdisk and accept the warning message stating that the disk has an MBR partition and it is about to be converted to GPT
  5. create a new partition at the beginning of the disk as an ESP partition (type 0xef00 in gdisk) at least 100 MiB in size
  6. once it was complete the disk was almost ready

At this point the disk was ready and fully converted from a partition table stand point. All that was left to do was to figure out how to get the EFI boot process going. And here is where the details got really murky on the web.

In the end, the easiest solution that worked for me was to reboot into the Ubuntu 13.10 LiveCD and use the boot-repair tool to reinstall and configure GRUB2 to operate in EFI mode

Initally I've had a lot of bad luck with boot-repair because it was not seeing the EFI System Partition and so it kept prompting me to repair GRUB in MBR/legacy mode.

The aspect that I found lacking on the web that finally did the trick was the fact that in order for the boot-repair tool to correctly recognize that GRUB should be installed in EFI mode the following conditions must be met:

  1. boot the LiveCD in UEFI mode
  2. make sure the EFI System Partition partition exists on the disk
  3. make sure the EFI System Partition is formatted using FAT32 (or other supported file-system)
  4. make sure the EFI System Partition has a label that reads EFI
  5. in my case I had also added the EFI System Partition to the /etc/fstab configuration to be mounded under /boot/efi

I'm not sure whether step 5 above is really necessary but step 4 seemed to be critical in getting boot-repair to see that I was trying to get GRUB working in EFI mode.

is the founder of Donaq, a software development consulting company with a focus on mobility. You can find Mike on Google+ and on LinkedIn.