Expanding VirtualBox Dynamic VDIs

There is no way to increase the maximum size of a dynamic VDI. You can, however, clone a smaller VDI to a larger one. Using this method, you can give your guest OS some more breathing room.

A commonly asked question in the VirtualBox IRC channel (#vbox on FreeNode) is some variant of “How can I make my dynamic disk image bigger?”

VirtualBox allows you to create dynamically expanding virtual disk images (VDIs) for your VMs. This means the file containing the virtual hard disk on the host only takes up as much space as the guest is actually using. When you create the dynamic VDI, the size you specify is the maximum size the VDI will expand to. This allows your guest OS to make the assumptions it needs to about drive geometry, etc.

There is no way to increase the maximum size of a dynamic VDI. You can, however, clone a smaller VDI to a larger one. Using this method, you can give your guest OS some more breathing room.

Update: As of version 4.0, VirtualBox has support for resizing dynamic VDIs and VHDs. Read the fine manual for more information. If you’re not using a VDI or a VHD (or if you’re not using a dynamic variant of one of those), read on… The technique described here should work for any image type VirtualBox supports.

Update: Windows users may want to check out mpack’s CloneVDI tool. It provides a user friendly GUI interface for a lot of VDI management tasks (including this one)

WARNING: This process will not work if your current VDI is smaller than 4GB. If your current VDI is smaller than 4GB, do not attempt this method (Update: The 4GB restriction no longer applies as of version 4.0). Also, do not delete your original VDI before you’re sure the new one works.

The basic process is as follows:

  1. Create a new (larger) VDI
  2. Clone the existing VDI to the new one
  3. Detach the old VDI from the VM and attach the new one
  4. Expand the partition on the VDI
  5. Boot the VM and make sure everything works
  6. Once you’re sure the new VDI is working properly, delete the old one.

So, let’s break those steps down a bit…

To create a new VDI, you can either use the Virtual Media Manager in the GUI (look in the File menu), or you can use VBoxManage in a terminal window, like so (note: if you’re using a Windows host, open a command window and run: cd “C:\Program Files\Sun\xVM VirtualBox”):

VBoxManage createhd –filename my_filename.vdi –size 50000 –remember

This will create a 50GB (50,000MB) dynamic VDI called “my_filename.vdi” and store it in the default location (on Linux, this is usually ~/.VirtualBox/HardDisks). The ‘–remember’ flag will automatically register the VDI with VirtualBox, so that we can use it later.

Now that we’ve created the new VDI, we need to clone the old one to it. You have to use VBoxManage for this step, since cloning isn’t supported in the GUI.

VBoxManage clonehd old.vdi new.vdi –existing

Obviously you should replace “old.vdi” and “new.vdi” with the appropriate filenames. You can either specify absolute paths, or just specify the filenames if the VDIs are stored in the default folder. This process will take some time, so grab some coffee and we’ll pick back up in a few minutes…

Once you’ve cloned the VDI, you need to attach it the VM (and detach the old one). It’s probably easiest to do this in the settings page for the VM in the GUI, but it can also be done with VBoxManage. If your VDI is attached to the Primary Master IDE slot for the VM (which is the default), then you can use the following commands:

VBoxManage modifyvm MyVMName –hda none

VBoxManage modifyvm MyVMName –hda new.vdi

Obviously you’ll want to replace “MyVMName” and “new.vdi” with the appropriate values for your set environment. Once you’ve done this, you’ll need to expand the partition on the new VDI, to let it know it can use all the new space you’ve given it. The details of how to do this are outside the scope of this post, but the general idea would be to boot the VM with some sort of partitioning tool (GParted is a good Free option) and use that to expand the partition.

Once you’ve expanded the partition, boot the VM normally and make sure everything works. Once you’re sure everything works, unregister and delete the old VDI (again, this is easy enough to do in the GUI, but you can use VBoxManage as well).

VBoxManage closemedium disk old.vdi

rm /path/to/old.vdi

That’s all there is to it. The obvious downside to this method is that it takes up some extra disk space during the process, but if you’re looking to expand your VDI by any significant amount anyway, then this probably isn’t an issue.

25 thoughts on “Expanding VirtualBox Dynamic VDIs”

  1. Very helpful post, exactly what I was looking for. Thanks a lot!

    (For Windows equivalent of “rm”, IIRC “del” should do the trick on Vista and earlier. On 7’s Power Shell, “rm” will work, too.)

  2. Excellent article! well written! I needed to install VS2008 and sql2008 but didn’t want to rebuild my existing environment. This is a huge time saver for me, thanks! I just wish Sun would automate some of this stuff and/or give us a GUI for vboxmanage.

  3. Thanks a LOT – you helped me out of deep doo-doo. Things are so easy with Linux nowadays and it’s articles like this that make it all even easer and more enjoyable.
    “Kubuntu 9.10, 2 Virtual XP’s – one for CS3 and one for CS4”

  4. Thanks worked for me.

    But under Win7 / Vista etc. Choose via right click on Computer -> Mangage Hardisk. Right click on Drive and choose “enlarge”. That’s it.

  5. Hi, good article.

    Note that I had to detach the media in the GUI media manager before I could
    perform the
    VBoxManage clonehd

    Maybe this is a change in the latest version of VirtualBox?

  6. The most helpful I found. I followed the steps. The storage manager has the new disk but my guest xp (on the new disk) still does not see the full amount allocated.

  7. One step was missing in my case. Therefore my guest xp didn’t see the full new disk until I used diskpart.exe to extend the new volume. Specifically, bofore detaching old.vdi, attach the new.vdi as secondary. Boot into the old.vdi one more time. Within xp, run diskpart.exe. Extend volume 2 (new.vdi). Then you can detach old.vdi and attach new.vdi as the primary.

  8. liao,

    That’s certainly one way to do it. Another way is mentioned near the end of the post (attach the new VDI as primary and boot the VM with GParted to resize the partition).


  9. I tried to use qtparted to expand the partition of the new vdi and it destroyed all the data on it. I’ve used qtparted in the past and expanded partitions without destroying the data so I don’t know what happened here.

  10. What if i want to create the new HD.vdi in External HD? I tried VBoxManage createhd –filename “F:\Virtual Disk\Ex_Win_Lab.vdi” –size 50000 –remember but didnt work.

  11. I’m running CentOS, and I followed these instructions and successfully started the VM in the new virtual disk. However, when I connect to it through Remote Desktop, the screen comes up and tells me
    FATAL: Could not read from the boot medium! System halted

    What can I do to fix this?

  12. For some reason, I can’t get VBoxManage to navigate to the directory and file where the .vdi files are. It keeps coming up with:

    VBoxManage: error: Could not find file for the medium ‘/home/dustin/VirtualBox_VMs/Gayoung/Gayoung.vdi’ (VERR_FILE_NOT_FOUND)
    VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component Medium, interface IMedium, callee nsISupports
    Context: “OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, AccessMode_ReadWrite, pMedium.asOutParam())” at line 209 of file VBoxManageDisk.cpp

    I’ve checked the path and tried multiple variations, but the path it gives in the error message is exactly what the folders are called and exactly where they are. I tried “cd VirtualBox_VMs” but that comes up “no such file or directory” (even though cd works fine for all the other folders).

    I know this must be something simple I’m overlooking, but can’t figure it out. Any help? Your solution looks really helpful except I can’t get past this step.

  13. One solution I just thought of was to copy the .vdi files out into the mother directory and then perform the VBoxManage command, and the data should be safe if I only replace Gayoung1.vdi in the original folder with the new file, right?

    1. Yeah, working with a copy should be just fine. It’s a little odd that you have an underscore in the directory name “VirtualBox_VMs”. Every installation I’ve ever seen has had a space there.

  14. Sorry. That didn’t work as it knew there were originals. Now I’ve been able to direct it to the correct path, after deleting the copies, but it says the second file (“newhd.vdi”) is an invalid parameter. Any ideas?

  15. Yes, the underscore was the problem for determining the path. When I had just used the file names without the exact path, it said no such file, but now that I fixed to the correct path (without the underscore) it says there’s a syntax error with the second file being an invalid parameter. Here’s what I had:

    VBoxManage clonehd –existing ~/VirtualBox VMs/Gayoung/Gayoung.vdi Gayoung1.vdi

    Oracle VM VirtualBox Command Line Management Interface Version 4.0.4_OSE (C) 2005-2011 Oracle Corporation All rights reserved.

    VBoxManage clonehd |
    [–format VDI|VMDK|VHD|RAW|]
    [–variant Standard,Fixed,Split2G,Stream,ESX]

    Syntax error: Invalid parameter ‘Gayoung1.vdi’

    I checked and re-checked the name of the .vdi file, but can’t figure out what’s hanging it up.

    Thanks again

  16. Dustin Tower: you should either quote or escape paths when they have spaces, thus:

    VBoxManage clonehd –existing “~/VirtualBox VMs/Gayoung/Gayoung.vdi” Gayoung1.vdi


    VBoxManage clonehd –existing ~/VirtualBox VMs/Gayoung/Gayoung.vdi Gayoung1.vdi

    1. grr, that last bit had its escaping eaten by something:
      VBoxManage clonehd –existing ~/VirtualBox\ VMs/Gayoung/Gayoung.vdi Gayoung1.vdi

Leave a Reply

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