Expand LVM disk on Linux in VMware
April 1st, 2008 . by DaveSure VMware can increase disk sizes quickly and easily but thats not much use unless you can expand the paritions on that disk.
In this example I have a Linux install built on LVM. I want to increase the size of the virtual disk in VMware and then increase the size of the LVM Volumegroup.
Here’s my filesystem, notice I only have 11GB on the root partition;
# df -h
| Filesystem | Size | Used | Available | Use% | Mounted on |
| /dev/mapper/VolGroup00-LogVol00 | 11G | 1.3G | 9.2G | 12% | / |
| /dev/sda1 | 99M | 19M | 77M | 19% | /boot |
| tmpfs | 125M | 0 | 125M | 0% | /dev/shm |
OK, lets start.
Power off VM
First, increase the size of the virtual disk (VMDK) by 10GB for example
vmware-vdiskmanager -x 10GB /path/machineName.vmdk
(VirtualCentre users can increase disk sizes easier via the Settings dialog of the VM)
Powered on VM
Now lets create a partition on the new space
# fdisk /dev/sda
Create a new primary partition, and set the filesystem type to LVM (AKA 8e)
Reboot VM
Create a physical volume for LVM:
# pvcreate /dev/sda3
Physical volume “/dev/sda3″ successfully created
Add the new physical volume to the volume group:
#vgextend VolGroup00 /dev/sda3 Volume group “VolGroup00″ successfully extended
Extend the logical volume over the new space in the volume group.
In the next command you will see I extended the volume by 9.6GB and not 10GB!? If you try 10GB you will receive an error because there won’t be sufficient space.
I found the 9.6GB figure by running “vgdisplay” and used the value from the “Free PE/Size”. This is how much space is available to expand the volume.
# lvextend -L+9.6G /dev/VolGroup00/LogVol00
Rounding up size to full physical extent 9.06 GB
Extending logical volume LogVol00 to 20.34 GB
Logical volume LogVol00 successfully resized
Then grow the file system into the new space of the volume.
# resize2fs /dev/VolGroup00/LogVol00
Filesystem at /dev/VolGroup/LogVol00 is mounted on /; on-line resizing required.
Performing an online-resize of /dev/VolGroup00/LogVol00 to 5332992 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 5332992 blocks long.
Now here is my bulky new disk layout (df -h)
| Filesystem | Size | Used | Available | Use% | Mounted on |
| /dev/mapper/VolGroup00-LogVol00 | 20G | 1.3G | 18G | 7% | / |
| /dev/sda1 | 99M | 19M | 77M | 19% | /boot |
| tmpfs | 125M | 0 | 125M | 0% | /dev/shm |