I had a major oops moment that led to my VirtualBox guest VM's hard drive being larger than the host's hard drive. I rushed through reading the commands for resizing a virtual hard drive. As such, I wound up resizing my virtual hard drive from 25 GB to 45 TB.

My research on how to shrink VirtuaBox VDI's says to log into the guest system, zero out all the free space, and then compact the hard drive using VBoxManage commands. This would work, if the max size of the VDI was smaller than the host system. It is untenable for my situation, because writing zeros into the free space of my resized VDI will try to fill up 45 TB with zeros. Since my Mac has a 750 GB hard drive, 45 TB of zeros is going to blow it away.

Some forums say that the virtual max size is not a big deal, as a dynamic hard drive will only take up host disk space that corresponds to data in the guest. This is true, but that upper limit of 45 TB scares me. What if a process in my guest goes crazy and keeps logging until it fills up both the guest and the host hard drives? That will bring down both my machines, and it is not a possibility I want to allow.

So my question is: how do you really reduce the max size of a VirtualBox dynamic virtual hard drive?

Host: Mac OS X
Guest: Windows 8
I have not started the VM since I resized the VDI

Short answer: you can't shrink the max size, you can only increase it. You can, however, create a VDI with the size you want and clone the old VDI into the new VDI. There are some gotchas, so read on.

Cloning the old VDI into the new VDI works only if you can guarantee the following things:

  1. You have enough space on the host physical hard drive to support cloning
  2. If the VM has re-partitioned its hard drive to use any of the space allocated by its new max size, then the VDI you clone onto must be exactly the same size or bigger as the guest's entire partition scheme. (I would use a bigger VDI just to be on the safe side.)

If you can guarantee these things, you can press on...

First, create a new VDI with the size you wanted in the first place:

VBoxManage createhd --filename Windows\ 8\ Improved.vdi --size 50000

--size is in MB. This example will create a dynamic VDI that has a max size of 50 GB.

Then clone the old VDI onto the new VDI (my old VDI is named Windows 8.vdi):

VBoxManage clonehd Windows\ 8.vdi Windows\ 8\ Improved.vdi --existing

You then use the VirtualBox GUI (or VBoxManage) to use Windows 8 Improved.vdi as your primary hard disk.

The key here is the --existing part. As long as the space occupied by the partition scheme in the old VDI is smaller than the size of the new VDI, the clone should succeed with room to spare. When you boot into the VM using the new VDI, the guest OS will still have the old partition scheme, but will see a bigger hard drive. At this point you can safely use a suitable partition manager (such as GParted) to expand the guest hard drive into the new space.

  • To add to the good answer above: If you just increased the VDI size, without changing the partition sizes in the guest OS, the extra space added to the VDI will never be used by the guest OS anyway. So you can safely start the VM. Look how much disk-space the guest OS thinks there is used for its partitions. Then create the cloned-HD with slightly more space than that. In your specific case just make a 45 GB clone. That was you intention all along wasn't it ?
    – Tonny
    Oct 15 '14 at 6:03
  • That is a more succinct way to state the solution...I just needed to document what I did to get myself out of the max virtual size of 45 TB. And since I skimmed the docs the first time rather than reading and understanding them, I thought it was a good idea to put the whole procedure in the answer rather than leave it to interpretation :)
    – Snapman
    Oct 15 '14 at 17:32
  • Grin: I wasn't quite awake when I posted that comment... Never noticed you answered your own question. Nevertheless I think my comment further clarifies the last paragraph of your answer. Yours is good, but maybe not entirely clear to everybody. PS. I always keep a GPartEd ISO right next to the VirtualBox GuestAdditions ISO so I can attach it as a virtual CD to whatever VM that needs messing about with. I have seen some people burn the ISO first and then attach it via the host CD-drive... Never ceases to amaze me how thick otherwise smart people can sometimes be :-)
    – Tonny
    Oct 15 '14 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.