Resizing a virtual hard disk

No matter what size hard disk you have, sooner or later you’ll find it’s too small. This is just as true for virtual hard disks as it is for physical ones. One of the benefits of virtialization is that you can change your ‘hardware’ setup on a whim. Want an extra gigabyte of memory? No problem, just assign it in your virtual machine config. So long as your host machine has capacity and the guest O/S supports it, this is easy to do.

Frustratingly though, none of the main VM software vendors (VMWare, Microsoft Virtual PC / Server and Sun VirtualBox) offer a way to resize a disk from the standard user interface. It is possible, but it takes a little fiddling to get it to work.

Broadly, there are two ways to achieve this:

  1. Create a new virtual disk the size that you want, use a disk cloning tool (such as gparted) to copy data from the old virtual disk to the new one then expand the partition to fill the virtual disk.
  2. Use some tool to expand your existing virtual disk, then expand the partition to fill the virtual disk.

I’m going to concentrate on the second method as this is the only one I’ve tried so far. I’ve demonstrated this on VMWare and Microsoft Virtual PC disks. The process is roughly the same and seems to work nicely. I’m not sure it would work for Sun VirtualBox though as I don’t know of a tool to expand the virtual disk.

Step 1 – Expand your virtual disk

While the standard UI of VMWare and Virtual PC do not offer a way to resize a virtual disk file, tools do exist to do this.

VMWare is supplied with such a tool called vmware-vdiskmanager.exe. It can be found in the VMWare directory inside Program Files (on Windows) and can be run from the command line like this:

The -x option specifies the new size of the disk (16GB). Make sure that you specify the vmdk (virtual disk) file, not the -flat.vmdk file. I found this took about 5 minutes with very little feedback so be patient.

Microsoft does not supply such a tool but there are a couple of third party ones out there. I’ve used one called VhdResizer. It has a nice simple graphical UI.  Just select your existing VHD file and specify the name of a target VHD and it will create a shiny new virtual disk the size that you need. You might need to leave this running over lunch as it will take a while. I found it took over an hour to resize a 16GB disk to 24GB. And obviously it will hog your system resources while it does it.

Step 2 – Expand the partition

You’ll find that if you try to boot your virtual machine with your newly resized virtual disk, the guest O/S will not recognise the extra capacity. This is because even though the virtual disk has expanded, the partition on the disk has not changed at all. To use the extra space, you’ll need to expand the partition into the newly created space. I believe that later versions of Windows have a disk partition tool built in. This can be accessed by right clicking ‘Computer’ from the start menu and selecting ‘Manage’. The stuff you want is under ‘Disk Management’. If this is not available, I find that GParted run from a System Rescue live CD works nicely instead.

First, download the System Rescue ISO then have VMWare / Virtual PC mount the ISO image as a CD drive for your virtual machine. Start your virtual machine and boot to the CD drive (you may need to hold ESC or F8 or alter BIOS settings to make it do this). Once the System Rescue O/S has loaded, type ‘wizard’ to load the graphical UI, then type ‘gparted’ to open the disk partition software.

In GParted, right click on the disk bar at the top and choose to Resize / Move. Drag the right hand bar so that the partition fills all available disk space. Then ckick the Apply button. This should take just a minute or two. Note that I found that System Rescue loads without mouse support under Virtual Server. So you may need to use the keyboard shortcuts instead.

Once that’s complete, restart your VM and boot into the usual O/S. You’ll find that a Windows guest O/S will want to run chkdisk after the partition resize (best to let it). Once the O/S loads, you should find that the newly created space on your virtual disk is now available to you.

Leave a Reply

Your email address will not be published. Required fields are marked *