Converting to GPT in Ubuntu

GPT stands for “GUID Partition Table” and it refers to a relatively new format for disk partition tables. It was designed to get around the limitations of the MBR format, namely that you can have more than 4 primary partitions and partitions can be more than 2.2 terabytes in size. GPT is part of the EFI standard but it can also be used on standard BIOS only machines i.e. most non-MAC PCs. Converting to GPT will allow you to future proof your partitions. 2 TB disks are becoming common and it won’t be long before the 2.2TB limit of MBR will stop people using all their disk space in one partition, so in the name of usability and flexibility GPT is the way forward.

The procedure is as follows:-

  1. Backup, backup and thrice I say backup!
  2. Make sure you have enough space at the start of your disk for a “BIOS boot partition”.
  3. Make sure you have enough space at the end of you disk for the backup/redundant partition table.
  4. Install and run gdisk otherwise known as “GPT disk”.
  5. Reinstall grub to the boot sector.
  6. Reboot and cross your fingers.

Backup, backup and thrice I say backup!

I’m not going to go into too much detail here. Suffice to say, make sure you have recourse if everything goes mammarys up. Suggestions include using Rsnapshot to backup the whole of the machine to another and using dd to backup the existing boot sector and partition table i.e. for dd:

dd if=/dev/sda of=bootsect.img bs=512 count=1

Or instead of using rsnapshot you could use dd, gzip and SSH to copy each partition to another machine on your network i.e. :

dd if=/dev/sda1 | gzip | ssh root@192.168.x.x dd of=/backup/laptopsda1.img

Once you are sure everything is backed up and available if needed, continue on.

Make sure you have enough space at the start of your disk for a “BIOS boot partition”.

Happily if you have done a “fresh” install of Lucid Lynx a.k.a. Ubuntu 10.04 LTS, your partitions will be aligned to a 1MB boundary for new disk and SSD performance reasons, which will leave just enough space of nearly 1MB to install the GPT version of Grub 2.

Happily for me, although my Ubuntu install has been in existence for a few years, I already manually aligned the partitions.

If you are in neither of the above camps I can only recommend running GParted Live, to move the start of the first existing partition, and make the required space.

Make sure you have enough space at the end of you disk for the backup/redundant partition table.

Because I have home on it’s own separate partition, I was able log out, shut down GDM, and unmount the last partition on the drive while the system is running, like so:

service gdm stop

umount /dev/sda3

e2fsck -f /dev/sda3

resize2fs /dev/sda3 xxGB

fdisk /dev/sda

partprobe /dev/sda3

Making sure when deleting and recreating the partition that it isn’t smaller than the file system size.

Alternatively you could again use the GParted Live CD to free up the space (probably safer anywho).

Install and run gdisk otherwise known as “GPT disk”.

 apt-get install gdisk

gdisk /dev/sda

When you start gdisk for the first time it will automatically convert the partition tables to GPT, but it will not save them unless you exit by hitting “w”. If you haven’t managed to create a megabyte or 2 of space at the end of the disk gdisk will complain about the redundant partition table “overlapping the last partition by xx blocks”. Assuming you have got this far your partition layout should look something like this when you press “p” to print:

Number  Start (sector)    End (sector)  Size       Code  Name
 1            2048          309248   150.0 MiB   0700  Linux/Windows data
 2          311296        17577984   8.2 GiB     0700  Linux/Windows data
 3        17580032       125206494   51.3 GiB    0700  Linux/Windows data

We then need to create the “BIOS boot partition” where part of Grub 2 will reside. Type “n” and return. Hit return again to accept the next available partition number. Type “34” and return for the first sector and hit return again to accept the default last sector (which should be 2047). Type “ef02″ and return to set the partition type. Partition layout should now look something like this:

Number  Start (sector)    End (sector)  Size       Code  Name
 1            2048          309248   150.0 MiB   0700  Linux/Windows data
 2          311296        17577984   8.2 GiB     0700  Linux/Windows data
 3        17580032       125206494   51.3 GiB    0700  Linux/Windows data
 4              34            2047   1007.0 KiB  EF02  BIOS boot partition

At this stage you should be able to type “v” and return and get similar output to this:

No problems found. 4094 free sectors (2.0 MiB) available in 2
segments, the largest of which is 2047 sectors (1023.5 KiB) in size

At this point if you are happy everything thus far has gone to plan you can type “w” and return to save the partition layout to disk.

Reinstall grub to the boot sector.

At this point you should be able to run

grub-install /dev/sda

and get no errors.

This will install the GPT version of the bootloader into the little BIOS boot partition we created earlier.

All that remains then is to reboot and fingers crossed your machine will come up. Happy days!

References:-

Wikipedia GPT definition – http://en.wikipedia.org/wiki/GUID_Partition_Table

GPT Disk tutorial from the author – http://www.rodsbooks.com/gdisk/

Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.

4 thoughts on “Converting to GPT in Ubuntu”

  1. Thanks for taking the time to tell me about that. You are, of course, absolutely correct. I’d say there are a few more typos littered about the place aswell. Must get my reading glasses on and check it all again.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>