I have had a number of virtual linux machines that have run out of disk space and have found it difficult in the past to find one solution to increasing the virtual disk and expanding free space into a logical volume.
The most recent example was when I needed to extend from 8GB to 20GB and using the Gnome Partition Editor, Gparted, would not work as it doesn’t currently have LVM support.
There are some linux commands that get around this problem so first I extended the VMware virtual disk.
Expand the disk
Turn off the virtual machine that you wish to administer.
Open a command prompt and change directory to C:’Program Files’VMWare’VMWare Server or C:’Program Files’VMware’VMware Workstation depending upon what product you are running.
Run this command to expand the virtual disk: vmware-vdiskmanager -x 20GB "My harddisk.vmdk"
In my case I would like to increase the disk to 20GB so substitute your value. Include the full file location for the vmdk file and use quotes if there are spaces in the folder and/or filename
The disk expansion should complete successfully
Restart the VMware virtual machine and open a terminal session
Issue the df -k command which here shows us that the logical volume is at 100% usage
We need to create a partition on /dev/sda
Type ls -al /dev/sda* which lists the existing partitions
Our new partition will be /dev/sda3
Type fdisk /dev/sda then type’n’ for new partition
Enter ‘p’ and 3 for the partition number (in this instance..obviously enter the partition number that matches your environment)
Also accept the default First and Last cylinders
Finally type ‘w’ to write table to disk and exit
If prompted to reboot then do so to ensure that the new partition table is written.
After a restart, type ls -al /dev/sda* to verify whether the new partition was created
Now that the partition has been created we need to create a physical volume and add it to the volume group
Type pvcreate /dev/sda3
Type vgextend VolGroup00 /dev/sda3
We need to extend the logical volume
Which shows that there is 11.97GB free that we can add to the volume group
To extend the volume type lvextend -L+11.97G /dev/VolGroup00/LogVol00
I then had an error message that stated that there was ‘Insufficient free space: 384 extents needed but only 383 available’
After a quick search:
It seems that I needed to select a slightly smaller size. I selected 11GB rather than 11.97GB which solved this problem.
Finally we need to resize the file system by typing resize2fs /dev/VolGroup00/LogVol00
Type df -k to see if the new space is available to the logical volume
The logical volume has now been resized and now has used space of just 35%!