I’ve upgraded my home FreeBSD 8 server’s instance of VirtualBox to 4.1.8_OSE, and ran across an issue with my Windows 7 VM. The VM’s primary virtual hard drive (C:) was initially created as 20GB, and I was running out of space to install new applications. This post notes the VirtualBox magic required to resize a previously-created virtual HDD image.
The trick
The central step in resizing is the VBoxManage command:
VBoxManage modifyhd <diskUUID> --resize <NewsizeInKByte>
You can resize .vdi disk images, but not .vmdk disk images, so you might also need:
VBoxManage clonehd <diskUUID> <newHDDfilename> --format vdi
(You may alternatively use the filename of the disk image instead of diskUUID in both of the above commands.)
Resizing Windows 7 disks
Strictly speaking, my Windows 7 VM had two virtual HDDs — one 20GB (C: drive) and one 5GB (a somewhat arbitrary E: drive). The C: drive was a .vmdk image, whilst the E: drive used a .vdi image. The UUIDs of each disk can be found with “VBoxManage list hdds
“:
gja@gjabkup2.space4me.com :VBoxManage list hdds [..] UUID: 5dbf3695-a840-494f-97cb-14dff912e9dc Parent UUID: base Format: VMDK Location: /home/gja/.VirtualBox/HardDisks/Win7-64bit-booted.vmdk State: created Type: normal Usage: Win7Swin (UUID: 7289cca0-f1c1-49fa-b71c-300711414fba) [..] UUID: 7f128c7b-08bf-48e7-b0f2-2db1b8829ec2 Parent UUID: base Format: VDI Location: /home/gja/.VirtualBox/HardDisks/Win7-spare-disk1.vdi State: created Type: normal Usage: Win7Swin (UUID: 7289cca0-f1c1-49fa-b71c-300711414fba) [..] gja@gjabkup2.space4me.com :
Growing the 5GB drive is painless. First, shut down the Win7 VM and then use VBoxManage like so:
gja@gjabkup2.space4me.com :VBoxManage modifyhd 7f128c7b-08bf-48e7-b0f2-2db1b8829ec2 --resize 8000 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% gja@gjabkup2.space4me.com :
“VBoxManage showhdinfo
” confirms the new size
gja@gjabkup2.space4me.com :VBoxManage showhdinfo 7f128c7b-08bf-48e7-b0f2-2db1b8829ec2 UUID: 7f128c7b-08bf-48e7-b0f2-2db1b8829ec2 Accessible: yes Logical size: 8000 MBytes Current size on disk: 487 MBytes Type: normal (base) Storage format: VDI Format variant: dynamic default In use by VMs: Win7Swin (UUID: 7289cca0-f1c1-49fa-b71c-300711414fba) Location: /home/gja/.VirtualBox/HardDisks/Win7-spare-disk1.vdi gja@gjabkup2.space4me.com :
Rebooted the Win7 VM, and the 2nd drive is recognised as now being an 8GB HDD, with E: taking 5GB (as one would expect).
Selecting this disk under “Disk Management” (inside the Win7 VM) allowed me to “extend volume” so the E: drive now uses the new extra space on the drive.
I shutdown the Win7 VM again, and adjusted the 20G C: drive in two steps — convert the underlying virtual HDD file from .vmdk to .vdi, then resize the .vdi version.
First, shutdown the VM again and convert the HDD format using “VBoxManage clonehd
“
gja@gjabkup2.space4me.com :VBoxManage clonehd 5dbf3695-a840-494f-97cb-14dff912e9dc Win7-64bit-booted-new.vdi --format vdi 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% Clone hard disk created in format 'vdi'. UUID: b7a3d209-d8b3-4065-994d-6b66ebbf7fb1 gja@gjabkup2.space4me.com :
I used the VirtualBox GUI to switched my VM from using Win7-64bit-booted.vmdk to using Win7-64bit-booted-new.vdi. The VM rebooted just fine, suggesting the copy is functionally identical as far as the VM is concerned.
Shutdown the VM again, and resized the newly created Win7-64bit-booted-new.vdi image:
gja@gjabkup2.space4me.com :VBoxManage modifyhd Win7-64bit-booted-new.vdi --resize 50000 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% gja@gjabkup2.space4me.com :
The resize process completed without error. “VBoxManage showhdinfo
” confirms the new size.
gja@gjabkup2.space4me.com :VBoxManage showhdinfo Win7-64bit-booted-new.vdi UUID: b7a3d209-d8b3-4065-994d-6b66ebbf7fb1 Accessible: yes Logical size: 50000 MBytes Current size on disk: 19601 MBytes Type: normal (base) Storage format: vdi Format variant: dynamic default In use by VMs: Win7Swin (UUID: 7289cca0-f1c1-49fa-b71c-300711414fba) Location: /home/gja/.VirtualBox/HardDisks/Win7-64bit-booted-new.vdi gja@gjabkup2.space4me.com :
Rebooted my VM and confirmed that the C: drive appears to now be located on a 50GB HDD.
From inside the VM I used Windows 7′s Disk Manager to extend the C: partition to cover the rest of the new space (which finally gave me enough room to perform the installation of, and update to, Windows 7′s service pack 1).
