With the modifymedium
command, you can
change the characteristics of a disk image after it has been
created:
VBoxManage modifymedium [disk|dvd|floppy] <uuid|filename> [--type normal|writethrough|immutable|shareable| readonly|multiattach] [--autoreset on|off] [--property <name=[value]>] [--compact] [--resize <megabytes>|--resizebyte <bytes>] [--move <path>
Note
For compatibility with earlier versions of VirtualBox, the "modifyvdi" and "modifyhd" commands are also supported and mapped internally to the "modifymedium" command.
The disk image to modify must be specified either by its UUID
(if the medium is registered) or by its filename. Registered images
can be listed by VBoxManage list hdds
(see Section 8.4, “VBoxManage list” for more information).
A filename must be specified as valid path, either as an absolute path
or as a relative path starting from the current directory.
The following options are available:
-
With the
--type
argument, you can change the type of an existing image between the normal, immutable, write-through and other modes; see Section 5.4, “Special image write modes” for details. -
For immutable (differencing) hard disks only, the
--autoreset on|off
option determines whether the disk is automatically reset on every VM startup (again, see Section 5.4, “Special image write modes”). The default is "on". -
The
--compact
option can be used to compact disk images, i.e. remove blocks that only contains zeroes. This will shrink a dynamically allocated image again; it will reduce the physical size of the image without affecting the logical size of the virtual disk. Compaction works both for base images and for diff images created as part of a snapshot.For this operation to be effective, it is required that free space in the guest system first be zeroed out using a suitable software tool. For Windows guests, you can use the
sdelete
tool provided by Microsoft. Executesdelete -z
in the guest to zero the free disk space before compressing the virtual disk image. For Linux, use thezerofree
utility which supports ext2/ext3 filesystems. For Mac OS X guests, use thediskutil secureErase freespace 0 /
command line from an elevated Terminal.Please note that compacting is currently only available for VDI images. A similar effect can be achieved by zeroing out free blocks and then cloning the disk to any other dynamically allocated format. You can use this workaround until compacting is also supported for disk formats other than VDI.
-
The
--resize x
option (where x is the desired new total space in megabytes) allows you to change the capacity of an existing image; this adjusts the logical size of a virtual disk without affecting the physical size much.[39] This currently works only for VDI and VHD formats, and only for the dynamically allocated variants, and can only be used to expand (not shrink) the capacity. For example, if you originally created a 10G disk which is now full, you can use the--resize 15360
command to change the capacity to 15G (15,360MB) without having to create a new image and copy all data from within a virtual machine. Note however that this only changes the drive capacity; you will typically next need to use a partition management tool inside the guest to adjust the main partition to fill the drive.The
--resizebyte x
option does almost the same thing, except that x is expressed in bytes instead of megabytes. -
The
--move <path>
option can be used to relocate a medium to a different location <path> on the host file system. The path can be either relative to the current directory or absolute.
[39] Image resizing was added with VirtualBox 4.0.