Convert an MBR disk into a GPT disk in Linux

Ahmed Mansouri
7 min readJul 28, 2023

--

In various scenarios, you may encounter an instance or Virtual Machine (VM) with a data (secondary) volume or disk formatted using the MBR (Master Boot Record) partition table and a size less than 2 TiB. Over time, you might find the need to extend the disk size beyond 2 TiB. However, a limitation of the MBR partitioning is its inability to support sizes larger than 2 TiB, unlike GPT (GUID Partition Table), which does support such capacities.

In this article, I will guide you through the process of converting the partition table from MBR to GPT and demonstrate how to successfully extend the disk size. Follow the step-by-step instructions below to achieve a seamless transition and efficiently extend your disk’s capacity.

MBR and GPT

Master Boot Record (MBR) disks use the standard BIOS partition table. GUID partition table (GPT) disks use the Unified Extensible Firmware Interface (UEFI). One advantage of GPT disks is that you can have more than four partitions on each disk. GPT is also required for disks larger than 2 terabytes (TB). For more details , check this link.

I — Initial state of the server

First, in my case, I’m using an AWS EC2 Nitro instance (t3), and the OS is RHEL 7. Therefore, the disks attached to the instance are NVMe and their names will be like this nvmeXn1 where the X is the number of the disk

  • Let’s check our server and the details of our secondary disk :
# lsblk -f

The disk that I want to extend its size and convert its partition table is nvme1n1 . Currently it is with 10 GiB.

  • Use gdisk command to check the current partition table type.
# gdisk -l /dev/nvme1n1

As you can see, the current partition table of the disk nvme1n1is “MBR”

Note that the same thing can be checked using the command fdisk , but it is better to install the gdisk from now as we will need it to convert the partition table later.

# fdisk -l /dev/nvme1n1

Note : “dos” is the same as “MBR

II — Increase the volume/disk size to more than 2 TiB

/!\ : Before proceeding with any action, it is strongly recommended to create a backup of your disk to mitigate any potential risks that may occur.!!!

Depending on the environment that you are using, you can increase the volume or disk size. In my case, I’m using an AWS EC2 instance, so I modified the volume to 2.1 TiB.

  • Let’s check again the disk from the OS level after increasing its size :
# lsblk
# df -hT

=> We can see that only the disk size changed to 2.1 TiB, however the partition size didn’t change and it is still equal to 10 GiB.

** Performing a test with MBR **

(it is just a test that will not help increasing the partition size to the one we need , but I will perform it just to illustrate the need of GPT here)

  • Okay , let’s now try increasing the partition size using the “growpart” tool.

What is growpart utility?

1. growpart is one of the utility to extend the last partition of the disk to fill the available free space on the disk. It changes the sector position to the end sector of the disk.

2. It only extends the last partition. It doesn’t create or delete any existing partition.

3. It can be run online. Dry run test can also be done to check the same.

More details in this link : https://access.redhat.com/solutions/5540131

If the “growpart” is not installed in your server , then install it using the appropriate package management tool in your OS. Here I’m using RHEL 7, so the command to install it is:

# yum install -y cloud-utils-growpart 

Let’s use it now :

# growpart /dev/nvme1n1 1

Here “1” is the number of the partition that we want to extend . As I have only one partition in my disk, I want to extend the first partition nvme1n1p1 in my disk which is number 1 here.

  • Let’s check what happened to our disk :
# lsblk

==> You can see here that the partition size wasn’t extended to 2.1 TiB, but it is less than that (52 GiB in this case) !!

III — Convert MBR to GPT

We saw that as long as the partition table is MBR , the partition will not be able to take the size of the disk (2.1 TiB)

In order to convert the partition table from MBR to GPT , I will create a new partition in the disk, then I will remove it later . Creating the new partition will help changing the partition table type of the disk. Let’s see how it works.

  • Create a new partition using “gdisk” tool :

Here just press “n” for new partition and then use the default values by pressing Enter each time , and finally press “w” for write.

# gdisk /dev/nvme1n1
  • Let’s check again the partition table of our disk :
# gdisk -l /dev/nvme1n1

==> The partition table changed now to GPT

  • We need now to delete the second partition that we created for the conversion purpose :
# gdisk  /dev/nvme1n1
  • Run the command “partprobe” to inform the kernel about the new changes.
# partprobe

IV — Increase the partition size

  • Let’s now increase our partition size again using the “growpart” tool
# growpart /dev/nvme1n1 1
  • Okay , what about the “lsblk” output now !
# lsblk

==> Cool , the partition size changed correctly to 2.1 TiB !

  • That’s it ? NO ! let’s check the file system size of the partition :
# df -Th

The partition file system size is still 10 GiB ! We need to increase it also to the new size.

To do that , we need to extend the file system using the appropriate tool for it.

For example here I’m using “xfs” then I need to use “xfs_growfs” to extend the file system. If you are using “ext4” then the command to use is “resize2fs”. For other file system types , check the appropriate tool for that.

Before extending the file system , let’s check if there was any issue happened to the file system during the conversion :

  1. Unmount the partition :
# umount /dev/nvme1n1p1

2. Check the file system :

# xfs_repair /dev/nvme1n1p1

There is no issue with it !

  • Let’s now increase the file system size :
  1. Mount again the partition
# mount /dev/nvme1n1p1 /mnt

2. Increase the file system size :

# xfs_growfs -d /dev/nvme1n1p1
  • Let’s check now the partition and its file system again :
# df -hT

# lsblk

 ==> Done correctly :) !!

If you found the post enjoyable and helpful, WHY LEAVE WITHOUT ANY REACTION 😔? At least show your support by clapping, leaving a comment, and following me. 😄

— Thanks

--

--