With the evolution of technology, it exists now many ways to store and organize data. This brings along new devices with a large amount of storage capacity. To manipulate such a large amount of capacity, you will need to use the appropriate partition table on the hard drive.
The GPT and MBR are the two popular which are used before choosing the filesystem when you think about keeping your data. As a system administrator, you might want to use either MBR (Master Boot Record) or GPT (GUID Partition Tables) while partitioning, so you must know the difference between the two.
In order to properly understand how they work, in this tutorial, we will need to explore some basic concepts about MBR and GPT to understand their advantages, limitations and differences.
What to know
Partitions are defined by data structures that are written to specified parts of the hard disk. When you have to store partition information on a drive, you must use MBR or GPT which tells to the operating system where exactly a partition begins and start, which sector belongs to each partition and which one is bootable. This is one of the main reasons we have to choose between MBR and GPT, before creating partitions on a hard drive.
Many computers are compatible with the two but they are not working together. Normally, MBR is the old one used before and it works along with Bios system. GPT is a new one that comes with the UEFI (Unified Extensible Firmware Interface) system. So it means that if you want to install an operating system on a hard drive, if you choose to use MBR, then GPT will not work and vice versa. It is possible to do a conversion from one to the other one but the process will cause the deletion of everything on the disk.
MBR for Master Boot Record stores its data in the first sector of the disk and contains partition and filesystem information, telling BIOS that this is a boot drive and where it can find a mountable filesystem. You should be aware that MBR only supports drives up to 2TB in size. To operate on MBR disks, you need to use the
When installing a system, the MBR compatibility comes with the Legacy BIOS mode on the bios configuration. It means that you can know at the start if you performing and MBR installation or not. On Ubuntu for example, if it shows you a purple color when you boot for the installation, you will know that it's an MBR installation
If you have already installed your Linux system such as Ubuntu and you want to check if it's MBR, you can use the
gdisk -l command
With this, you can confirm that you are using MBR.
The MBR architecture has its particularity because normally it supports only 4 primary partitions. It can support up to four partitions but there is a special condition to meet this requirement:
- The first three partitions should be primary partition,
- The last partition should be an extended partition which can be subdivided into smaller partitions called logical partitions.
The devices files with primary partition append a number indicating the partition on that hard disk. The first primary partition is given the number 1, the second primary partition is given the number 2, the third primary partition is given the number 3, and the fourth primary partition is given the number 4. When you have an extended partition, the logical volumes within are named starting with number 5
We can check for example the result of the
fdisk -l command on another MBR disk with primary and extended partitions
# fdisk -l Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x0000996b Device Boot Start End Blocks Id System /dev/sda1 2048 4196351 2097152 82 Linux swap / Solaris /dev/sda2 * 4196352 30679039 13241344 83 Linux /dev/sda4 30679040 41164799 5242880 5 Extended /dev/sda5 30681088 36540415 2929664 83 Linux
To properly understand the limitation of 4 primary partitions, let's take as an example during the manual partitioning during the installation of Ubuntu. For this example, let's say that we want to create 5 partitions, during the process:
- we will create first the
/bootpartition as a primary partition
- Let's do the same for the following partitions
/optby making them also primary partitions. Which means that we will have 04 primary partitions. We will see that the space left will be unusable because of the MBR partition numbers limitation
You can see that we can't add a new partition after reaching the limit of the 04 MBR primary partitions.
Another particularity of the MBR is that a single bit error can render a disk useless. For these reasons, and more, the Unified Extensible Firmware Interface (UEFI) specified that MBRs were to be replaced with GUID Partition Tables (GPT), which overcome these limitations.
GPTfor GUID Partition Tablesis part of Intel’s EFI specification. The GPT is a different format than the MBR, but for compatibility reasons, the MBR is stored in the first logical block and the GPT is stored on the second block. GPT allows disk with more than 2 TB and up to 128 partitions.
To operate on GPT disks, you need to use the
parted command. The
gdisk for GPT fdisk and uses an interface that is very similar to fdisk.
When you want to install your system on a GPT disk, you must enable the Unified Extensible Firmware Interface (UEFI) in the bios configuration. For example, if you want to install Ubuntu on your computer, you will have a black background-color at the boot like below
If you want to check if you are using the GPT partition, still use the
gdisk -l command
Mbr: protective is because GPT employs a protective MBR, which is a legal MBR definition that makes GPT unaware utilities think that the disk holds a single MBR partition that spans the entire disk.
With GPT there is no need for primary, extended partitions or logical drives, which means that all of the partitions are the same. Sure you can still consider primary for a better understanding. In practice, though, GPT partitions are usually numbered consecutively starting with 1 even if some gaps can occur in partition numbering. Let's have a look with another disk using GPT
# gdisk -l /dev/sda GPT fdisk (gdisk) version 1.0.1 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Disk /dev/sda: 976773168 sectors, 465.8 GiB Logical sector size: 512 bytes Disk identifier (GUID): 02F5A939-659C-46B7-8392-40F60B005D04 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 976773134 Partitions will be aligned on 2048-sector boundaries Total free space is 4077 sectors (2.0 MiB) Number Start (sector) End (sector) Size Code Name 1 2048 1050623 512.0 MiB EF00 2 1050624 99878911 47.1 GiB 8300 3 99878912 138940415 18.6 GiB 8300 4 138940416 155541503 7.9 GiB 8200 5 155541504 184838143 14.0 GiB 8300 6 184838144 595970047 196.0 GiB 8300 7 595970048 976771071 181.6 GiB 8300 DATA
You can see that we don't have the mention Extended anymore but only a list or many partitions and fortunately, we don't have gaps with the numbering.
Now let's try to create more than 4 partitions when installing our system such as Ubuntu for the example. So, we will start also to create the
Now do the same for the others partitions like
You can see that we have 05 GPT primary partitions and the possibility to create more partitions with the free space which is recognized.
As a system administrator, you should be at least somewhat familiar with GPT because of MBR’s inability to handle disks larger than 2TiB. You should retain that even if the two are different, there is some similarity to ensure compatibility. It is common for Linux servers to have several hard disks so it's important to understand that large hard disks with more than 2TB and many newer hard disks use GPT in place of MBR to allow for the additional addressing of sectors.