You can easily expand the hard disk size VirtualBox using the command:
VBoxManage modifyhd --resize.
--resizeoption allows you to change the capacity of an existing image; this adjusts the logical size of a virtual disk without affecting the physical size. It works only for expanding the capacity of VDI and VHD virtual disk formats, and only dynamically allocated not fixed size disks. But this is a way to add more space to a virtual disk without needing to create a new image, attach and copy all the data across within a virtual machine.
This is a command-line application, so you need to open a Terminal session in in order to run the command and change directory to the path where your virtual disk is stored.
Two important notes:
- Shutdown the running virtual machine before you mess with the disk!
- Backup the existing disk image, or at least any volatile data, before you alter it!
VBoxManage modifyhd XP_newdisk.vdi --resize 10240
- VBoxManage is the utility suite that comes with VirtualBox:
- modifyhd is the command to resize the virtualdisk
- XP_new.vdi is my example disk name; you'll need to change it to match your disk name and don't forget the .vdi suffix. Under Linux it's also case sensitive.
- --resize 10240 Next is the desired new size for the virtual disk. That's two dashes before the word "resize" followed by a number in kilobytes; 10240 being equivalent to 10Gb.
Note that .vmdk disks cannot be expanded by modifyhd commands. Try this command line and you'll get the error:
VBoxManage: error: Resize hard disk operation for this format is not implemented yet!
You can find the manual for Oracle VirtualBox, indexed by each topic on the website. VBoxManage is Chapter 8:
where the full syntax of the command looks like this:
VBoxManage modifyhd <uuid>|<filename>
[--resize <megabytes>|--resizebyte <bytes>]
The --compact option can be used to shrink disk images, that is, remove blocks of empty space (containing zeroes). This will shrink a dynamically allocated image by reducing the physical size of the image without affecting the logical size of the virtual disk.
However, free space in the guest system must first be zeroed. For Windows guests, you can use the sdelete tool provided by Microsoft; running sdelete -c in the guest will zero the free disk space. Under Linux, the zerofree utility supports ext2/ext3 filesystems to do the same. You can then compact (compress) the virtual disk image. RC