« // »

Cloning a VirtualBox Hard Disk

Sure it’s easy to install an operating system from scratch in VirtualBox, but it’s much easier (and quicker) to keep a base library of OS images and simply clone the disk and add the specific software you need (want).

You cannot just simply copy a disk file, all disks in VirtualBox contain a unique identifier (a UUID) and two disks with the same UUID cannot be in the media catalog at the same time.

VirtualBox, however, provides the ability to change the UUID (from the command line) using vboxmanage; the syntax is simply vboxmanage internalcommands setvdiuuid <disk file name>.

You can easily create a script for cloning a VirtualBox disk by doing something like this in windows (I put it in a file called clonevdi.bat)

@echo off
REM clonevdi <source> <destination>
set v=%ProgramFiles%\sun\virtualbox
copy %1 %2
“%v%\vboxmanage.exe” internalcommands setvdiuuid %2
set v=

or this in ‘nix (I put it in a file called clonedvi and it needs to be set to have execute [x] mode)

#!/bin/bash
# clonevdi <source> <destination>
cp -p $1 $2
vboxmanage internalcommands setvdiuuid $2

Then you just call it with the disk file you want to clone, and the new name for the clone.

Remember, if you’re cloning a Windows OS disk, you should download a tool like NewSID (from Sys Internals, now Microsoft) and run that after you boot your cloned disk to change the security identifier (SID).

NOTE:  Pay attention to the licensing requirements from Microsoft on duplicating Windows OS disks (even virtual ones) and as of Nov 2009 the only “official” way Microsoft supports changing SIDs is through the use of SysPrep (Microsoft System Preparation Utility for Microsoft Windows operating system deployment).

Originally posted 2010-04-08 02:00:30.

« // »