Linux “fdisk” vs “gdisk”. What, Why and How!
What…
The story is quite long but I will keep it simple. We (I) was taught to use fdisk to partition disks for use on Ubuntu or any other Linux distro, but I soon came to learn of gdisk which in my own opinion is less stressful when compared to the former.
Why…
Now to understand the background to all this we look at the different disk partition table scheme or method now available. We have MBR (Master Boot Record) used by BIOS (Basic Input and Output) and the GPT (Globally Unique Disk Identifier Partition Table) used by UEFI (Unified Extensible Firmware Interface). In the MBR scheme we can have just four primary partitions and if we need more we create a logical partition and add as many extra partitions therein, but in the GPT scheme we can have up to 128 primary partitions.
A noteworthy difference is the partition size, MBR’s [2 Terabytes], and GPT’s [2³³ terabytes], don’t ask me ask Google but it’s fair to say the latter takes more than we would really need as ordinary folks. This is my favourite reason for using GPT as I don’t need to bother about “what’s after a partition” as I will demonstrate in a minute.
Now how would an MBR scheme look like, here it is:
sda
├─sda1 vfat 7AE7-E0CE /boot/efi
├─sda2 ext4 xxx-xxx-xxx /
├─sda3 LVM2_member xxx-xxx-xxx
│ └─myvg-mylvm ext4 xxx-xxx-xxx /mylvm
├─sda4
├─sda5 linux_raid_member george-VirtualBox:0 xxx-xxx-xxx
│ └─md127 ext4 xxx-xxx-xxx /myraid
└─sda6 linux_raid_member george-VirtualBox:0 xxx-xxx-xxx
└─md127 ext4 xxx-xxx-xxx /myraid
Note that the last two partitions /dev/sda5, and /dev/sda6 are derived from the logical partition /dev/sda4.
And the GPT would look like this:
sda
├─sda1 vfat 4CDB-E085 /boot/efi
├─sda2 ext4 e401768e-e7b3-4cd5-a1b1-5c1a965ea2b5 /
├─sda3 ext4 a98f7047-3987-4269-ad0a-eae829ec1fa9 /part3
├─sda4 ext4 284af069-3007-44cc-b016-6c46a771eba7 /part4
├─sda5 ext4 2a676692-3393-444f-9074-bc7053f3843f /part5
├─sda6 ext4 f3ae7d99-5bcd-460e-b442-bde470d79ce8 /part6
└─sda7 ext4 ea3eb54a-f236-4000-9a6c-938a0f320913 /part7
How…
How do you set up a MBR partition scheme, well you use the Linux tool fdisk but you plan ahead to avoid embarrassing your self when you discover that you have somehow run out of space even when you know you had enough space. Let’s use a simple case like the one in my diagram [for MBR] above where I made three primary partitions and one logical one. I initially made a virtual machine of [VHD] (virtual hard disk) size 60G and used only 30G to create it. So I had 30G left to use. With MBR I would create three primary partitions and then a logical one and here is where the real trick comes into play. Say you wanted to make two more partitions of sizes 300M each but in creating [logical] partition 4 I gave it a size of 300M, well when I try to create the sixth (6) of size 300M having made one previously of the same size the tool (fdisk) would complain that I had overshot the size limit. Now why is that? That’s because the logical size of the parent container [partition 4] was 300M and not 600M, which would have accommodated both partitions 5 and 6.
So to avoid this situation we should have created a logical container (partition 4) with size of at least 700M and with that we will be OK. But again that means that the remaining free space on the disk would be unusable. So advanced planning is really needed with MBR schemes.
Now the case with GPT is very different as the tool gdisk would easily create all the partitions without any fear of making the spaces after the last one unusable. This is one of the reasons I love GPT scheme.