How to Extend VM partition under Linux (CentOS)
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.
- Increase the disk from vCenter GUI, reboot the server. (Take a Snapshot)
- ls -al /dev/sda* to find out the last created partition, sda2 is the one in my case
- 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.
- pvcreate /dev/sda3 create a new Physical Volume
- vgextend VolGroup00 /dev/sda3 add this new volume to default Volume Group VolGroup00.
(Note: vgextend cl /dev/sda3 in CentOS 7) - vgdisplay to show the FREE PE (size of the free disk space), lvdisplay to show the volume name.
- 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) - 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).