Make those VirtualBox virtual disks larger without loosing data
If you have ever used virtualization software to make virtual machines (VMs) then you know how easy it is to add and remove hardware resources to modify the VM to be configured the way you want it to be. Even though you can do far more things hardware wise to a VM than you can to a physical computer (without actually adding more physical hardware) there are still some limitations and things to look out for.
VirtualBox is a virtualization platform designed by Oracle and is free alterative to VMware's vSphere and Microsoft’s Hyper-V software. It allows you to create virtual machines that run on your local computer and use your computer's hardware resources as its own. One catch is that you have to share things like your hard disk space and RAM with all the VMs you make so if you are running 3 VMs with 6GB of RAM each then that's 18GB out of your total RAM that will be used by them assuming you have that much in your computer to begin with.
So let's say you have your VM created and exactly the way you want it except for you realized you didn’t make the hard drive big enough and you already used all the available space to make a volume in Windows. So what do you do? Unfortunately it's not as easy as going into the setting for the VM and simply making it bigger. But that doesn't mean it's not possible but rather that you have to put a little more work into resizing the drive.
As you can see for the settings of a VM named Windows7 there is a virtual disk called Windows7.vdi and its 25GB in size and set to dynamically allocate storage which means grow the disk file as needed. Now we are going to expand the size of the disk to 30GB. You should always backup your data before doing something like this in case something goes wrong.
To do this we need to open a command prompt and go to the VirtualBox installation directory after shutting down the VM in question which should be C:\Program Files\Oracle\VirtualBox.
Next we need to use the VBoxManage modifyhd command to resize a disk named Windows7.vdi located on our D drive under D:\VirtualDisks. By default your virtual disks will be located at C:\Users\username\VirtualBox VMs but not in our case. So the command we need to run will be
VBoxManage modifyhd "D:\VirtualDisks\Windows7.vdi" --resize 30720
Notice the quotes around the path and the 2 dashes before the word resize. 30720 is 30GB in MB.
Here is the output of our command.
Now when we go to the properties of the VM and look at the size of the Windows7.vdi disk it's now 30GB.
Then we can go into Windows and extend the volume and that can be done with Disk Management. Simply select the original volume and right click on it and choose Extend Volume. Then allocate the rest of the space to the volume.
So as you can see it's not too difficult to enlarge the size of a virtual disk in VirtualBox and it really just takes one command to do so. So next time you are sizing a disk for a new VM you don't have to worry about not making it large enough because you now know how to make it bigger if needed!