Categories
FreeBSD/Unix

Creating GUID Partition Table (GPT) in FreeBSD

Just wanted to share a very short how to on creating GPT partition table using part command. The reasons for using GPT instead of MBR are quite obvious as disk spaces increase. The MBR partition table restricts partition sizes to a maximum of 2.19 terabytes (2.19 × 1012 bytes) or almost exactly 2 TB (2,199,023,255,040 bytes or 4,294,967,295 (232?1) sectors × 512 (29) bytes per sector). GPT supports partition sizes up to 9.3 ZB or 8 ZiB?512 bytes (9,444,732,965,739,290,426,880 bytes or 18,446,744,073,709,551,615 (264?1) sectors × 512 (29) bytes per sector). MBR disks support only four partition table entries. If more partitions are wanted, a secondary structure known as an extended partition is necessary. Extended partitions can then be subdivided into one or more logical disks. Similarly GPT support 128 partitions on a single disk allowing much larger number of filesystems on a single device without doing extension structures.

To create an empty GPT partition table run:

# gpart create -s gpt mfid1

You can check the result:

# gpart show mfid1
=> 34 5857345469 mfid1 GPT (2.7T)
34 5857345469 - free - (2.7T)

Now create first a 50G partition:

# gpart add -t freebsd-ufs -s 50G mfid1
mfid1p1 added

Then second partition that uses rest of the drive

# gpart add -t freebsd-ufs mfid1
mfid1p2 added

And the result:

# gpart show mfid1
=> 34 5857345469 mfid1 GPT (2.7T)
34 104857600 1 freebsd-ufs (50G)
104857634 5752487869 2 freebsd-ufs (2.7T)

Then just initialize the file systems:

# newfs /dev/mfid1p1
...
# newfs /dev/mfid1p2
...