Ubuntu – How to change a drive’s partition table from MBR to gpt without losing an NTFS partition at the end of the drive

gptpartitioning

Long story short, I have an external USB hard drive formatted using a MBR partition table, and I want to install Ubuntu in UEFI mode in a ~23.40 GB unallocated space before a ~442.33 GB NTFS partition that I need to keep:

screenshot

To install Ubuntu in UEFI mode I need the partition table of the drive to be formatted as gpt.

I don't think there's an easy / direct way to convert a MBR partition table to a gpt partition table, so I'm also looking for the complicated / indirect way.

For example I think something can be done by noting down the NTFS partition start, writing the new partition table and adding the NTFS partition to the new partition table, but I've never done this and I have no idea where to start; furthermore I don't wish to try this for the first time in this case, since I'm not really confident with this stuff and I can't afford losing the NTFS partition I need to keep.

Best Answer

There actually is an easy way to do it: Run gdisk on the disk and then type w to save the changes (which, if you do nothing else, consist of converting from MBR to GPT, which gdisk does automatically). That said, there are a few caveats:

  • If the disk is bootable, it will cease to be bootable after the conversion. Bootability can often be restored by installing a suitable boot loader. NTFS implies Windows, which would mean a conversion from BIOS-mode to EFI-mode booting. Making this change is possible, but is a bit tedious. Here is one page that describes how to do it. If the disk is strictly a data (non-boot) disk, then this issue isn't important for you.
  • If the final partition on the disk ends too close to the end of the disk, it may need to be shrunk by a small amount -- just a few sectors, normally, although many tools will require rounding to 1MiB units, so you may lose 1MiB or so. GParted often ignores tiny gaps like this, so it's unclear from your screen shot if you'd need to do this.
  • If the first partition begins too close to the start of the disk, its start point may need to be moved. That's obviously not the case for your disk.
  • Some meta-data, like partition type codes, won't be correctly converted. This isn't an issue for your disk.

For more on this subject, see my GPT fdisk documentation on MBR-to-GPT conversions. (Note: I'm the author of gdisk, which is installed by default with recent versions of Ubuntu; so that page can be considered official documentation.)