[0x0][Systems] - Extend LVM partition without creating new one


Increase LVM partition’s storage of a Virtual Machine (VMWare for example), without creating new primary partition or losing data or even reboot.

The current solution can be applied on a virtualized environment or not.


Additional partitions cannot be created, because you have reached the maximum number of primary partitions created and have msdos label instead of gpt. In case you don’t know what msdos and gpt is, read this and this one

How To

First of all, add the required storage to the Virtual Machine.

While logged in as root, apply the following steps. Please note that the term sda may differs.

  • echo '1' > /sys/class/scsi_disk/0\:0\:0\:0/device/rescan force rescan SCSI bus for new disks. If the path does not exist, you should run this for i in 0 1 2 3 4 5 6; do echo "- - -" >> "/sys/class/scsi_host/host_${i}/scan" 2> /dev/null; done or this for i in 0 1 2 3 4 5 6; do echo "- - -" >> "/sys/class/scsi_host/host${i}/scan" 2> /dev/null; done
  • fdisk /dev/sda

Do not be afraid to delete the partition. The trick here is to play with fdisk in-memory, create a new partition at the beginning of the same sector of the partition we have deleted and then extend it to the maximum possible (+100%FREE). When and only when we hit w, we actually write the options to the disk.

  • partprobe -s or kpartx to update the kernel with our new settings
  • Resize the LVM physical volume pvresize /dev/sda4 # 4 is the number of the partition we deleted previously
  • Grab the name of your volume group vgdisplay # "centos" for example
  • Extend the LVM partition lvextend -l +100%FREE /dev/centos/root # root is the lvm
  • Grow the filesystem: If you have XFS xfs_growfs /dev/centos/root, else if you have EXT resize2fs /dev/centos/root
  • Validate with df -h