Monday, March 21, 2016

Resizing a VirtualBox .vdi file from command line

Another quick one: Let's say I am running VirtualBox (or vbox for short) and have a Microsoft Windows virtual client. Let's date ourselves and make it a Windows 7 vm. And I just found out its disk, win7.vdi is a bit small (40GB)and I would like to up it a bit, say, to 60GB. And me being the klutz I am, or have this unexplained desire to do everything on command line so I can script it later, I do not know how to do that using the GUI. So, like many times before, cue in for some command line action!

The command we will be using today is vboxmanage modifymedium or, as it used to be called, vboxmanage modifyhd. Let's see which options we have avaiable:

Oracle VM VirtualBox Command Line Management Interface Version 5.0.16
(C) 2005-2016 Oracle Corporation
All rights reserved.


VBoxManage modifymedium     [disk|dvd|floppy] 
                            [--type normal|writethrough|immutable|shareable|
                            [--autoreset on|off]
                            [--property ]
                            [--resize |--resizebyte ]

Why we would modify a dvd? Well this is really not a real dvd, but one of those .vdi files, which you can build to pretend to be a DVD. Other formats are also supported but .vdi is the native one. Now, I usually try to run my examples in a Linux host unless they specifically only run on a different OS (try running Powershell in Linux). Since VirtualBox can run in OSX, Windows, and Linux, I chose Windows this time. So, let's try to add 20GB to it:

PS C:\Program Files\Oracle\VirtualBox> .\vboxmanage modifyhd \
'C:\users\raub\VirtualBox VMs\win7\win7.vdi' --resize +20480
Progress state: VBOX_E_NOT_SUPPORTED
VBoxManage.exe: error: Resize medium operation for this format is not implemented yet!
PS C:\Program Files\Oracle\VirtualBox>

You probably guessed I do not have the virtualbox binary path added to my default path, so I cheated and went to that directory. Of course you could have provided the full path to the binary, which would not be as lazy. In any case, it did not like my pretending this is a lv and I was expanding it of 20GB (i.e. the "+" did not work out). So, let's just tell it to do 60GB (I am cheating with the disk size) total and be done.

PS C:\Program Files\Oracle\VirtualBox> .\vboxmanage modifyhd \
'C:\users\raub\VirtualBox VMs\win7\win7.vdi' --resize 60000
PS C:\Program Files\Oracle\VirtualBox>

Of course now we have to resize the drive within the vm client itself, and that depends on the OS that is being run by that client.


  • I merged all snapshots before doing this. I did not test whether this would work with "snapshoted" disks.
  • I have read before about people having issues with vmdk files. I do not know if that still happens or not, but I thought it was worth mentioning. If you have errors, just do as the first reply and then convert it to vdi do your resizing, and then convert it back to vdmk.
  • I like to give the full path to the .vdi fle.

No comments: