Can I change an existing partition from MBR to GPT?

7,969

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.

Share:
7,969

Related videos on Youtube

Dagonar
Author by

Dagonar

Updated on September 18, 2022

Comments

  • Dagonar
    Dagonar over 1 year

    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
    
    • Dagonar
      Dagonar about 6 years
      Output is available.
    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' about 6 years
      I see. You evidently didn't run pvcreate sdb, but pvcreate /dev/sdb1. Please copy-paste the actual commands you ran, otherwise it's hard to help you. It's also confusing that you refer to 2TB as the filesystem size, but you have a 2.4TB filesystem, your problem is the size of the partition /dev/sdb1 which doesn't span the whole disk unlike what you intended. And now post the output of fdisk -l /dev/sdb.
    • Dagonar
      Dagonar about 6 years
      I followed the commands listed on this tutorial. The only thing changing is the names of the groups displayed.
    • Dagonar
      Dagonar about 6 years
      WARNING: The size of this disk is 2.7 TB (2748779069440 bytes). DOS partition table format can not be used on drives for volumes larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID partition table format (GPT). This is what makes me think I need to change sdb to GPT.
    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' about 6 years
      Edit your question to post the output of fdisk -l /dev/sdb
    • Dagonar
      Dagonar about 6 years
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' about 6 years
    This worked, not because the new disk contains no data, but because the GPT partition you created started at the same offset as the original MBR partition.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' about 6 years
    @sourcejedi The reason it worked is that the procedure actually doesn't overwrite anything in sdb except the partition table. Crucially, the content of the partition wasn't modified.
  • user2948306
    user2948306 about 6 years
    @Gilles I have edited for an amusing typo, and to be even more explicit about the safe sequence, and changed my downvote to upvote :).
  • user2948306
    user2948306 about 6 years
    @Gilles I reverted "Reboot the machine if you feel like it but you shouldn't need to." See unix.stackexchange.com/questions/441789/…
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' about 6 years
    @sourcejedi I think partprobe works in this case on modern systems, but better safe than sorry.
  • user2948306
    user2948306 about 6 years
    @Gilles I think either you're the one who is out of date, or there is some disagreement between distros :). See comment unix.stackexchange.com/questions/441789/…
  • Dagonar
    Dagonar about 6 years
    I actually used partprobe at the end, but the system did not manage to recognize the changes and asked me to reboot afterwards.