Follow redcrown01 on Twitter
Time:

Cloning or Resizing Virtualbox Disks in Linux

Clone or resize a virtualbox disk with the vboxmanage utility.

This article describes a simple procedure for cloning or expanding the size of a Virtualbox disk image containing Windows 7, which is running on a Linux system. Resizing the disk image becomes necessary on many instances of virtualized Windows 7 because of update induced bloat. Even a bare bones system will bloat due to the constant addition of patches and fixes from Windows update, and the accumulation of cruft over time. While older versions of Virtualbox required complex methods to resize a virtual disk image, versions 4.0 and newer offer a single command to accomplish the task. There is no need to clone or copy the vdi! Simply use the built in vboxmanage utility to modify the size of the vdi file.

Note that the full path to the vdi file is given in the example below, and the new size is specified in megabytes. There is some whitespace in the filename, so single quotes are used to contain the path:

#  vboxmanage modifyhd '/home/aptosid/.VirtualBox/HardDisks/Windows 7.vdi' --resize 13000

Very quickly, the data is rewritten which specifies the maximum size of the dynamically expanding disk. At this point, the configuration resembles a large hard disk containing a small partition with Windows installed. For Windows to use the whole disk, the (virtual) partition must be expanded. The next series of steps must be accomplished within the Windows virtual machine.

Bear in mind that the virtual system detects the maximum possible size of the disk, and doesn't "know" it is actually a smaller virtual disk. As files are created or transferred to the client, it will grow up to the maximum allocated size. Boot the client machine, and when Windows has finished loading, expand the partition with the Diskpart utility. Diskpart is started with the following commands in a Windows terminal:

    C:\Users\schmoe\diskpart

Use the "list volume" command to see the number of the boot volume, usually the "C" drive, which will indicate the old size.

    DISKPART> list volume

    Volume ###   Ltr    Label                     Fs         Type            Size        Status     Info
    --------------------   ---    -----------------------       --------     ------------       -------------   ------------   -----
    
    Volume 0        D     VBOXADDITIO     CDFS    CD-ROM        31 MB    Healthy
    Volume 1               System Rese         NTFS    Partition      100 MB    Healthy    System
    Volume 2        C                                  NTFS    Partition          8 GB    Healthy    Boot
  

Use the "Select Volume" command to set up the utility for expanding the partition. In many cases, Virtualbox Guest Additions occupies volume 0, Volume 1 is taken by the system, and the "C" drive is found on volume 2. Issue the following command to select the proper volume:

    DISKPART> select volume 2

Use the "Extend" command to reconfigure the partition to use all available space:

    DISKPART> extend

After extending the partition to fully occupy disk, a look at the disk properties will indicate the new size. Windows alerts that the system's disk space is critically low will stop, and the system should operate normally.


Making a backup or clone of a Virtualbox Disk

Cloning a disk is useful for deploying large numbers of virtual systems in the field or simply backing up a functioning virtual system. For example, a computer security professional may have a particular "target" configuration upon which he tests viruses or malware. Once the testing is completed, the system can be forensically examined or deleted. Another user may have several specialized versions of Windows - one optimized for multimedia editing, another set up with forex trading platforms, and another configured for massive multiplayer gaming. Starting with one basic functional disk image, cloning and resizing is accomplished easily on the command line.

# vboxmanage clonehd '/home/sidux/.VirtualBox/HardDisks/Windows 7.vdi' 'Windows 7 backup.vdi'

The "vboxmanage clonehd" command duplicates a registered virtual hard disk image to a new image file with a new unique identifier (UUID). The new disk image can be transferred to another host system, stored as a backup, or imported into VirtualBox again using the Virtual Media Manager.




©2005 - 2012 AB9IL, All Rights Reserved. Information: About, Contact Us, Links, Privacy, XML Sitemap, and HTML Sitemap.
Again: Content found here may not be copied, re-published, or reproduced without explicit permission.