Disclaimer: This article is not a step-by-step guide for beginners! I did this on Arch Linux, the paths may differ slightly on Ubuntu. Playing with the master boot record and partition table of your system is always a risk. Make a backup! I don’t take any liability for your lost data!
This article describes, how you can switch your system from the old MSDOS style partition table to the new GUID Partition Table (GPT) format. GPT is part of the EFI specification and will therefor probably become the standard for partitioning in most desktop computers in the near future. Apple is already using EFI and GPT in their desktops and notebooks and IA64 based servers and workstations do too. However, you can also use GPT on your BIOS based system.
MSDOS style partition tables are stored in the so called Master Boot Record (MBR), the first sector (512 Bytes) on the disk. It also contains the boot loader, which already takes up 440 Bytes. The partition table must fit into 64 Bytes. This is the reason why you can create only 4 partitions at max (with each entry taking up 16 Bytes of space) in an MBR partition table. Because the size of MBR partitions is stored as 32 bit, each one can be 2 TB large.
If you are, like me, fed up with the limits imposed by MBR partition tables and don’t want to use that hack with extended partitions anymore, you may want to try GPT. A GPT can hold 128 partitions each with a maximum of 8192 Exabytes in size.
What you need
The fdisk tool can not handle GPT. You will need gdisk, which is used in almost the same way. You will also need a compatible boot loader: the old grub 0.97 needs a patch, but grub2 handles GPT fine. However I use extlinux from the syslinux package (>=4.0), because I don’t like the complex configuration system of grub2.
You will also need to move your first partition by 33 sectors (because that’s the space, GPT takes up). If you have a separate boot partition, like me, this is pretty easy. If you don’t, you should probably wait until the next fresh reinstall.
Compatability
Linux can use GPT and boot from it. Make sure your kernel is compiled with the necessary support:
$ zgrep CONFIG_EFI_PARTITION /proc/config.gz
CONFIG_EFI_PARTITION=y # we're ready to go
FreeBSD can also boot from GPT, but I didn’t test it. Windows cannot boot from GPT partitions in BIOS systems! So if you have a dual booting machine with Windows, you shouldn’t do this.
Let’s rock’n'roll
First, I installed syslinux and gdisk from the repository. You will need syslinux 4.0 or newer. If you did not already update to Ubuntu 10.10, you will have to build it yourself.
I then installed extlinux with my MBR still intact, so I could test if it works. Change sda to your needs! Remember to mount your boot partition!
$ dd if=/usr/lib/syslinux/mbr.bin of=/dev/sda # Copy bootloader to MBR
$ mkdir /boot/extlinux
$ extlinux --install /boot/extlinux
$ cp /usr/lib/syslinux/menu.c32 /boot/extlinux
Create and edit /boot/extlinux/extlinux.conf as described in `man syslinux`, fitting your system. Mine looks like this. Yours should most probably look different!
default menu.c32
prompt 0
menu title Arch Linux
timeout 30
label linux
menu label Linux
kernel ../vmlinuz26
append initrd=../kernel26.img root=/dev/sda3 ro resume=/dev/sda2 quiet
After I had a working extlinux config, I rebooted with System Rescue CD. You can not do the following steps on your running system, because you will need to change the partition table and install the boot loader afterwards using the new table. But the kernel will only reload the table at reboot. However you cannot reboot into your system as long as you didn’t install the boot loader.
With the sysresccd running, I mounted my partitions and backed up my /boot.
$ mkdir /mnt/host
$ mount /dev/sda3 /mnt/host
$ mount /dev/sda1 /mnt/host/boot
$ cd /mnt/host
$ tar cf boot.tar boot/
$ umount boot/
Now I started gdisk. It will tell you, that you have a MBR table, which it converted to GPT and that you will have to delete or move your first partition. Delete and recreate it accepting the standards and mark it as legacy BIOS bootable.
$ gdisk /dev/sda
Command (? for help): d
Partition number (1-4): 1
Command (? for help): n
Partition number (1-128, default 1): 1
First sector (34-312581774, default = 34) or {+-}size{KMGTP}:
Last sector (34-112454, default = 112454) or {+-}size{KMGTP}:
Current type is 'Linux/Windows data'
Hex code or GUID (L to show codes, Enter = 0700):
Changed type of partition to 'Linux/Windows data'
Command (? for help): x
Expert command (? for help): a
Partition number (1-4): 1
Known attributes are:
0: system partition
1: hide from EFI
2: legacy BIOS bootable
60: read-only
62: hidden
63: do not automount
Toggle which attribute field (0-63, 64 or <Enter> to exit): 2
Attribute value is 0000000000000004. Set fields are:
2 (legacy BIOS bootable)
Command (? for help): w
You have now converted your partition table to GPT. Last step: restore the contents of your boot partition and install extlinux again, but this time with the boot loader code for GPT partitions (gptmbr.bin).
$ mkfs.ext2 /dev/sda1
$ mount /dev/sda1 /mnt/host/boot
$ cd /mnt/host
$ tar xf boot.tar
$ dd if=/mnt/host/usr/lib/syslinux/gptmbr.bin of=/dev/sda
$ extlinux --install /mnt/host/boot/extlinux
If everything went well, you can now reboot into your GPT system. Good luck.
References