How to increase the size of a VMware vmdk file formatted as linux lvm

VMware can run many cool operating systems on a single host computer. But, having run the software for an extended amount of time, i eventually always run out of space on my guest OSes. This happened a few times before, but it wasn’t until my VM really froze up on me that i figured it was time to look into extending or expanding the current virtual disk i had in use.

Have you ever tried increasing the size of a vmdk file / virtual hard disk ?
It’s not that easy.. and it’s kind of confusing.

So, once i finally figured out how to do it, i thought it would be useful to write it down so that i wouldn’t forget next time this happened. Here goes..

In my example i have:
- a Windows Vista host OS running a Fedora Core guest OS
- an 8GB vmdk file (formatted as Linux LVM – fedora fs) on the guest OS which i have backed up before attempting anything here !!!

I want to:
- increase the 8GB vmdk file to 16GB
- not lose any data saved on the vmdk file
- not move any data off/on the vmdk file

Follow these Steps:

  1. Download and Install: VMware Workstation for Windows (trial)
  2. Note the location of the VMware Workstation folder (after install) – in my case it’s “C:\Program Files\VMware\VMware Workstation”
  3. Open a Windows Command Prompt and navigate to the folder where your vmdk file resides and execute the following command:
    "C:\Program Files\VMware\VMware Workstation\vmware-vdiskmanager.exe" -x 16GB "Name of Your Virtual Disk File.vmdk"
    Ok, now you just made the disk twice as big but you can’t use the space yet because it’s inactive, unpartitioned, unformatted, and still utterly useless to us. (but not for long)
  4. Next, boot up the guest OS and log in as root. Verify that there is in fact a large amount of unallocated space/sectors by typing the command: fdisk -l
  5. Then we’ll partition and format the new portion of the disk. First select the disk: fdisk /dev/sda
  6. Type “n” at the fdisk menu to create a new partition
  7. Type “p” for primary partition, and then select the appropriate partition number, as well as first and last cylinders to set how large to make the new partition (defaults – ie: use all the free space – worked well for me here)
  8. Type “t” to change the partition’s system id, then type “8e” to switch it to Linux LVM
  9. Type “w” to write the table to disk and exit fdisk. You might get a warning about needing to reboot for changes to take effect – either way, reboot your guest OS just to be safe.
  10. Once rebooted, log in as root again and verify the new partition exists. Type “fdisk -l” to see a list of partitions. In my case, the new partition is: /dev/sda3
  11. Now comes the confusing part. We’re going to merge the new partition into the current Volume Group (which is just what fedora calls it’s own virtual disks that are made up of a bunch of virtual LVM partitions). So, first, to “create” the necessary “physical volume” from our newly created disk partition (/dev/sda3) first type: pvcreate /dev/sda3
  12. You need to find out the name of the Volume Group before you can extend it to include the newly created physical volume. Type: vgdisplay and look for the first line, “VG Name” – in this case it was VolGroup00 [thanks agm]
  13. Next, you need to extend the Volume Group to include the newly created physical volume. Type: vgextend VolGroup00 /dev/sda3
  14. Then, type: pvscan You should see the new partition (/1dev/sda3) in the list of partitions and the total should read approximately 16GB (the amount we set earlier). In my example, it said 15.75GB
  15. Now type: lvextend -L+8GB /dev/VolGroup00/LogVol00 to increase / extend the Logical Volume by 8GB (to a total of 16GB).
  16. Finally, to resize the filing system type: resize2fs /dev/VolGroup00/LogVol00

Now your fedora guest OS should have twice the amount of space and your VM should be running smoothly.
Repeat this process if / when the vmdk file gets filled up again and runs out of space ;)

Comments 6

  1. andrei g. wrote:

    thanks.
    it’s works

    Posted 09 Jan 2010 at 6:38 pm
  2. elran wrote:

    hey, you’re welcome andrei
    glad to see it’s worked for others too!

    Posted 13 Jan 2010 at 2:23 pm
  3. agm wrote:

    elran, thanks
    the only part was diff for fedora12 is VolGroup00
    vgdisplay to find display attributes of your local volume groups
    otherwise pretty straight forward steps.
    agm

    Posted 26 Feb 2010 at 2:51 pm
  4. elran wrote:

    thanks agm, that’s true!
    it looks like the default name for your volume groups in FC12 is your hostname with a prefix of “vg_” – so if your hostname for your machine is linuxbox, the name of your volume group would be vg_linuxbox (by default).

    Posted 04 Mar 2010 at 10:41 am
  5. tuan wrote:

    It works like a charm (winXP, fedora 8). Thanks a lot.

    Posted 25 Apr 2010 at 6:28 pm
  6. elran wrote:

    @tuan – glad it worked for you!

    Posted 27 Apr 2010 at 11:59 am

Post a Comment

Your email is never published nor shared. Required fields are marked *