Methods of payment Abuse

How to increase the size of VirtualBox virtual disk

26.09.2021, 22:47

Virtual machines are ubiquitous these days for testing various operating systems and performing other tasks. A popular and free program for running virtual machines is VirtualBox. When you create a new machine, you need to create a hard disk for it and specify its size. But you can't always guess how much space a particular machine will take up. There are dynamic virtual disks that take up space only when you write files to them, but this is an incomplete solution to the problem, because you can't plan everything in advance.

Solving the problem

There are three main formats you can use in VirtualBox - VDI, VHD , and VDMK. Only VDI and VHD can be resized. There is a workaround for VDMK.

To increase the size you need to use a command in the terminal or command line, unfortunately there is no such function in the GUI. You also need to know the full path to your disk. Let's say our disk is located at ~/VirtualBox VMs/Ubuntu17.04/Ubuntu1610.vdi in Linux. Let's look at its information to know its current size:

$ VBoxManage showhdinfo ~/VirtualBox VMs/Ubuntu17.04/Ubuntu1610.vdi

The size is noted in the capacity field and in this example it is 22075 megabytes. It is important to know the capacity in megabytes because that is what we will use to enlarge the disk. To increase the size of the virtualbox virtual disk the same command is used, only with the modifyhd parameter:

$ VBoxManage modifyhd ~/VirtualBox VMs/Ubuntu17.04/Ubuntu1610.vdi --resize 32075

We have increased the volume by 10 GB. It is important that the amount you specify in the resize parameter is not less than the current disk size, otherwise the operating system data may be corrupted and the whole point of this operation becomes meaningless.

If your machine has state snapshots, you should resize them as well, otherwise nothing will work. To do this, you can use a loop like this:

$ for x in ~/VirtualBox VMs/Ubuntu17.04/Snapshots/*.vdi ; do VBoxManage modifyhd $x --resize 32075 ; done

Remember that the size and names must match in all commands for the same machine. VirtualBox does not support resizing VDMK format, but you can convert it to vdi, enlarge it as described above and convert it back:

$ VBoxManage clonehd "~/VirtualBox VMs/Ubuntu17.04/Ubuntu1610.vdmk" "~/VirtualBox VMs/Ubuntu17.04/Ubuntu1610.vdi" --format vdi
$ VBoxManage modifyhd "~/VirtualBox VMs/Ubuntu17.04/Ubuntu1610.vdi " --resize 32075$ VBoxManage clonehd "~/VirtualBox VMs/Ubuntu17.04/Ubuntu1610.vdi " "~/VirtualBox VMs/Ubuntu17.04/Ubuntu1610.vdi_resized.vmdk" --format vmdk

In Windows OS, the command will look a little different and the file path will start from the C: drive. To run the VBoxManage command you must first navigate to the VirtualBox executables folder:

cd “C:Program FilesOracleVirtualBox”

Run the command to increase the size of virtualbox as described before, replace the file path with your own:

$ VBoxManage showhdinfoC:UsersAdminVirtualBox VMsWindows 7Windows 7.vdi

And change the size of this disk, remember that the size must be specified in megabytes, and it must be larger than the current one.

$ VBoxManage modifyhd "C:UsersAdminVirtualBox VMsWindows 7Windows 7.vdi" --resize 32075

Increasing the file system

The fact that you have increased the available disk size does not change anything, as nothing will change the fact that you add a new hard disk to the system. Next you need to boot into your virtual machine to expand the virtualbox disk and increase the space occupied by the file system, for this you can use the Gparted utility. In Linux distributions it comes by default, run the utility:

You will see the grayed out available space at the end of the disk. Now you can resize for the last partition by right-clicking on it and bringing up the context menu, then selecting "resize/move":

When you are done, don't forget to click "Apply" to apply all operations.

We have seen how to increase the size of a virtualbox virtual disk using the command line and how to share the resulting space with your guest system.