Linux – change an existing partition from MBR to GPT

gptlinuxlvmmbrpartition

I needed to add extra 2.5TB to the existing 400GB disk (sda) on my system. I added new virtual disks with 2.5TB (sdb), proceeded to create the partition table with fdisk.

Used pvcreate /dev/sdb1, to create the physical volume, then extended the volume group and finally extended the logical volume.

At the end I used the xfs_grow2fs for the filesystem to recognize. Only until then I realized that I only got 2TB out of the 2.5TB on the new disk due to MBR limitation.

Can I convert this drive to GPT without affecting sda? Will this movement affect the filesystem due to xfs_grow2fs being used? The worst case scenario would be having .5TB missing.

Using CentOS 7.

lsblk command output

NAME                 MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
fd0                    2:0    1     4K  0 disk 
sda                    8:0    0   420G  0 disk 
├─sda1                 8:1    0   500M  0 part /boot
└─sda2                 8:2    0 419.5G  0 part 
  ├─centos_sftp-root 253:0    0    15G  0 lvm  /
  ├─centos_sftp-swap 253:1    0     2G  0 lvm  [SWAP]
  └─centos_sftp-home 253:2    0   2.4T  0 lvm  /home
sdb                    8:16   0   2.5T  0 disk 
└─sdb1                 8:17   0     2T  0 part 
  └─centos_sftp-home 253:2    0   2.4T  0 lvm  /home
sr0                   11:0    1  1024M  0 rom  

lvs command

  LV   VG          Attr       LSize  Pool Origin Data%  Meta%  Move Log 
Cpy%Sync Convert
  home centos_sftp -wi-ao----  2.39t                                                    
  root centos_sftp -wi-ao---- 15.00g                                                    
  swap centos_sftp -wi-ao----  2.00g      

df command

Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/centos_sftp-root   15G  2.7G   13G  18% /
devtmpfs                      2.9G     0  2.9G   0% /dev
tmpfs                         2.9G     0  2.9G   0% /dev/shm
tmpfs                         2.9G  8.6M  2.9G   1% /run
tmpfs                         2.9G     0  2.9G   0% /sys/fs/cgroup
/dev/mapper/centos_sftp-home  2.4T  103G  2.3T   5% /home
/dev/sda1                     497M  171M  326M  35% /boot
tmpfs                         581M     0  581M   0% /run/user/1000
tmpfs                         581M     0  581M   0% /run/user/0

I used xfs_growfs to extend home to use the additional 2.5TB but only got 2TB from the new disk due to MBR limits.

output of fdisk -l /dev/sdb

Disk /dev/sdb: 2748.8 GB, 2748779069440 bytes, 5368709120 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
Disk label type: dos
Disk identifier: 0x3633c5d9

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  4294967294  2147482623+  8e  Linux LVM

Best Answer

The MBR partition /dev/sdb1 starts at the offset 1MB. This is good, because the first GPT partition would also start at the offset 1MB.

So delete the current partition with fdisk and use g to create a new GPT partition. Choose type LVM for this partition. Make sure that the new partition starts at the same offset as the old one, before you use the w command. Otherwise you will lose all your data.

You can now use the full extent of the 2.5TB instead of the 2TB limit on MBR. Write the changes on disk and reboot. Use fdisk -l to check that changes on sdb are okay. Now we read 2.5TB available. Time to resize the volume groups and physical volumes.

Use pvresize /dev/sdb1 to resize to the new additional space appropriately. Afterwards use lvresize to resize the logical volume group. And finally xfs_growfs to increase the filesystem. Use df to confirm the changes at the end.

For this last part you may refer to this article.

Related Question