How to Extend VM partition under Linux (CentOS)

By admin, April 21, 2011 8:12 am

I often extend partition live (without downtime) for Windows VM using either diskpart or extpart from Dell, but extending partition under Linux is a totally different thing, it’s a bit complex if you are from Windows world.

  1. Increase the disk from vCenter GUI, reboot the server. (Take a Snapshot)
  2. ls -al /dev/sda* to find out the last created partition, sda2 is the one in my case
  3. fdisk /dev/sda type n for new partition, then p and 3 for the partition number (ie, sda3), then accept all the default first and last cylinders and finally w to complete the partition creation, then finish with reboot.
  4. pvcreate /dev/sda3 create a new Physical Volume
  5. vgextend VolGroup00 /dev/sda3 add this new volume to default Volume Group VolGroup00.
    (Note: vgextend cl /dev/sda3 in CentOS 7)
  6. vgdisplay to show the FREE PE (size of the free disk space), lvdisplay to show the volume name.
  7. Extend the volume by lvextend -L +XXG /dev/VolGroup00/LogVol00, you can find out the exact path of the default Logical Volume by lvdisplay. (ie, lvextend -L +20G…)
    (Note: lvextend -L +XXG /dev/cl/root in CentOS 7)
  8. Resize the file system by resize2fs /dev/VolGroup00/LogVol00 to complete the whole process. (If everything works, remove the Snapshot)

Update: May 15, 2017
For CentOS 7 , use xfs_growfs /dev/cl/root as it’s use XFS file system instead of the traditional ext3/4 based file systems, also Group and volume name have been changed to cl (was VolGroup00) and root (was VolGroup00).

Leave a Reply