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 |
Great! Thanks a load.
[...] thanks to swizzling.org, who’s tutorial I modified minimally for my own benefit here. Leave a [...]
Nice! Note, on ESX3.5 the command to extend is changed from:
vmware-vdiskmanager -x 10GB /path/machineName.vmdk
to
vmkfstools -X 10G /path/machineName.vmdk
NOTE: Must be a CAPITAL ‘X’ and the disk space flag is a single ‘G” no longer ‘GB’.
Of course if you want to add more disk to a Volume Group and Logical Volume without needing to power off the VM, you can assign a new VMDK disk to the VM and run a script to “find” the newly hot added “SCSI” disk.
Then partition the new disk (8e) LVM, pvcreate it, Vgextend the Volume Group, lvextend the Logical Volume, then run an ext2online /home (ext2online command is included in the ext2resize package on ubuntu ‘apt-get install ext2resize’).
FYI I use: http://www.garloff.de/kurt/linux/rescan-scsi-bus.sh to rescan the SCSI bus on the fly. It works well.
Cheers!
Thanks
You rock, This tutorial saved me a lot of work! thanks
Just wanted to let you know that you are a saint!
This was killing me.
Thanks again -
Bubs
pvs will show your freespace and extents as well
The line:
lvextend -l +100%FREE /dev/vg_0/lv_1_root
will extend to all available free space (at least on LVM 2.02.26, not sure if this has always been there)
well done~ good job.
great tip!!! thanks so much! saved me tons of time and effort, worked perfectly!
Thank you, this helped me out!
Thanks for the great step-by-step. Just wanted to note that in many situations you won’t be able to use resize2fs on a mounted filesystem. If you receive such an error and you can’t unmount (e.g. a system mount), try using ext2online instead.
Dave, Chris, you guys are truly Linux Gods. Thank you so much. I just did all of this mostly on my own, and finally stumbled onto Dave’s writeup here. I got all the way up to resize2fs which failed because my LV is on /. *DOH* So after trying all sorts of off-line boot CD’s (Knoppix, Fedora Rescue, etc) I was about to give up – Then I scrolled down and saw Chris’ comments. OMFG, what a life saver. I had no idea ext2online existed and furthermore, how EASY it would be to actually extend the FS *LIVE* on /. It worked like a charm in all of 30 seconds. AMAZING! THANKS ALL!!
ThankyouThankyouThankyou
I know naff all about Linux so most online help is way over my head or assumes prior knowledge of the OS.
You’ve pitched this guide at exactly the right level for me which is a life saver. After trying on a test system we just extended a live virtual DB server – no problemo.
Thanks again.