Difference between revisions of "Virtualbox"

From Ever changing code
Jump to navigation Jump to search
Line 11: Line 11:
</source>
</source>
Startup the VM, and you will see the unallocated space in the Disk Management utility.
Startup the VM, and you will see the unallocated space in the Disk Management utility.
= Resize .vmdk disk on Linux =
Convert .vmdk format to .vdi and then resize. You can change format back after the resizing.
<source lang="bash">
VBoxManage clonehd "ubuntu-xenial-16.04-cloudimg.vmdk" "ubuntu-xenial-16.04-cloudimg.vdi" --format vdi # .vmdk -> .vdi
VBoxManage clonehd "ubuntu-xenial-16.04-cloudimg.vdi" "ubuntu-xenial-16.04-cloudimg.vmdk" --format vmdk #.vdi -> .vmdk
</source>
= Resize .vdi disk on Windows =
= Resize .vdi disk on Windows =
  cd "C:\Program Files\Oracle\VirtualBox"
  cd "C:\Program Files\Oracle\VirtualBox"

Revision as of 10:48, 18 June 2018

Resize disks in VirtualBox with Snapshots

It is quite straightforward to resize a disk in VirtualBox as stated here and there. It becomes tricky though if the virtual machine,aka VM, has snapshots attached. The virtual disk thus is persisted across multiple VHD files, and the old trick will generally take not effect. This is also a known bug hanging there for more than three years.

The suggested approach is to delete all snapshots and wait patiently for VirtualBox Manager to merge all the VHD files for you. It is a painfully lengthy process, so I decide to take a shortcut.

  1. First, shutdown the VM and backup the whole virtual machine folder.
  2. Then modify the size of all .vdi files in the root of the VM and Snapshots subdirectory.
VBoxManage modifyhd "Windows 8.1.vdi" --resize 81920
for x in Snapshots/*.vdi ; do VBoxManage modifyhd $x --resize 81920 ; done

Startup the VM, and you will see the unallocated space in the Disk Management utility.

Resize .vmdk disk on Linux

Convert .vmdk format to .vdi and then resize. You can change format back after the resizing.

VBoxManage clonehd "ubuntu-xenial-16.04-cloudimg.vmdk" "ubuntu-xenial-16.04-cloudimg.vdi" --format vdi # .vmdk -> .vdi
VBoxManage clonehd "ubuntu-xenial-16.04-cloudimg.vdi" "ubuntu-xenial-16.04-cloudimg.vmdk" --format vmdk #.vdi -> .vmdk

Resize .vdi disk on Windows

cd "C:\Program Files\Oracle\VirtualBox"
VBoxManage.exe modifyhd "C:\Users\piotr\VirtualBox VMs\vm-ubuntu64\vm-ubuntu64.vdi" --resize 20480

Note it also can resize VHD (Hyper-V) file formats.

Generalize Windows

If you wish to re use your Windows VM image it needs to be generalized:

C:\Windows\System32\Sysprep
sysprep.exe /oobe /generalize /shutdown /mode:vm