Extend CentOS partition - Already have 4 Primary Partitions

5,543

Solution 1

You could do it like described here: https://nacko.net/resizing-a-raw-virtual-machine-lvm-partition-using-fdisk/

Restating the main points: you can unmount the partition, delete it using a partitioning tool, then recreate it with identical data, except the end of partiton, which can be greater. You can only do this to the last partition on the disk.

Be aware that this requires extra caution, please have backups before doing this.

After that you should make sure that the changes are picked up.

Once that is done, you can pvresize, lvextend and finally resize2fs.

Solution 2

There is another method that would do the job. I happened to encounter such an issue with one of our customers and this method worked. It is a comparatively low risk as you are not removing any partition. But a proper back is in any case very important.

Instead of increasing the space for the existing hard disk in VMWare, just add another VMDK. This will appear in fdisk as /dev/sdb or any subsequent hard disk to the existing one. The number of primary partition restrictions is only applicable to that particular hard disk. You can add as many hard disks as you want and have individual partition tables.

Create a new partition in the new hard disk and then you can do pvcreate, vgextend, and then resize2fs.

This method worked for me getting rid of the risk of converting an existing Primary partition to an Extended partition and possible chances of data loss.

Share:
5,543

Related videos on Youtube

Jake
Author by

Jake

Updated on September 18, 2022

Comments

  • Jake
    Jake over 1 year

    I have a CentOS server, acting as my syslog server (CentOS Linux release 7.4.1708 (Core)). As my syslogs have grown in size, we've had to extend the volume a couple time. Now the main disk is 500 GB. We recently increased the size in VMWare up to 800 GB. I have been following this excellent document https://www.rootusers.com/how-to-increase-the-size-of-a-linux-lvm-by-expanding-the-virtual-machine-disk/.

    Here is what my disk looks like:

    fdisk -l
    
    Disk /dev/sda: 859.0 GB, 858993459200 bytes, 1677721600 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: 0x000a207b
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     1026047      512000   83  Linux
    /dev/sda2         1026048    62914559    30944256   8e  Linux LVM
    /dev/sda3        62914560   524287999   230686720   83  Linux
    /dev/sda4       524288000   943718399   209715200   8e  Linux LVM
    
    
    lsblk
    
    NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
    fd0               2:0    1     4K  0 disk 
    sda               8:0    0   800G  0 disk 
    ├─sda1            8:1    0   500M  0 part /boot
    ├─sda2            8:2    0  29.5G  0 part 
    │ ├─centos-root 253:0    0 447.5G  0 lvm  /
    │ └─centos-swap 253:1    0     2G  0 lvm  [SWAP]
    ├─sda3            8:3    0   220G  0 part 
    │ └─centos-root 253:0    0 447.5G  0 lvm  /
    └─sda4            8:4    0   200G  0 part 
      └─centos-root 253:0    0 447.5G  0 lvm  /
    sr0              11:0    1  1024M  0 rom  
    

    When attempting to create a new partition, I receive the following error message:

    If you want to create more than four partitions, you must replace a primary partition with an extended partition first.
    

    It appears that I have reached the limit of 4 primary partitions, so now I'm trying to figure out my options. Is there a way to extend onto this new 300 GB without formatting the drive? Can I convert one my current primary partitions to an extended partition without destroying my data?

  • Jake
    Jake over 4 years
    Great solution! I just ran this on a clone of this machine to test, and it seems to have working perfectly. I'll try it out on my prod system next. Thanks!
  • Jake
    Jake over 4 years
    I performed this on my prod server last night, and it worked like a champ. Thanks again for the solution.