Monday, 17 May 2010

Computer virtualization with VirtualBox: Guest OS copying and extending

1 comment
Virtualization is one of the greatest technologies and there are numerous practical aspects of it together with cool factors which provides a huge advantage for businesses. The main benefit is a money-saving aspect related to a minimised hardware cost, systems' replication, disaster recovery, software testing. Since computer virtualization allows a number of operating systems to be used on a single machine that facilitate the beneficial computer resource utilisation.
Virtualization allows easy creation of base computing environment, software / network testing, application deployment, etc. Virtualization can help tremendously especially if it is free, lightweight and easy to use. This is where Sun VirtualBox comes to play.
VirtualBox is a great desktop virtualization solution which has a number of advantages such as free to use (for personal and evaluation purpose), open source, less resource usage in host, performance benefits, snapshots, save and resume time of virtual machine (VM). ( more here )
It is very flexible and there is a good article "Virtualisation for Developers with VirtualBox" (can be found here) which provides a great inside on how to create, configure and fast start virtual machine (VM) using VirtualBox.
Once a basic Guest OS configuration created it might be copied into a safe place in order to be reused which would save a valuable time creating a new VM. However, managing VM cloning/copying and Hard drive expansion are not so straightforward as they are used in VMware Workstation or Virtual PC.
A number of posts on the web explain how to handle these in one or the other way. The article here describes both clone and copy ways.
I would like to put it in more details though. Below is how we can copy VM:
- Find your VM file, which is located in your user folder within .VirtualBox/HardDisks folder (by default) with .vdi extension.

- Copy your .vdi file and rename.
- Open Windows command line from VirtualBox installation folder and issue the following command: VBoxManage internalcommands setvdiuuid "Path_to_copied_vdi". The setvdiuuid command will create a new UUID and assign it the copied disk.- Copy your .vdi file and rename.

- Create a new VM and attach the new copied disk.

Now new VM is ready for use.

Working with VM and adding software might quickly lead to a full hard drive situation. There would be a need to increase the hard disk size in such cases. Below is how we can do that:
- Shut down the Guest OS.
- Create second .vdi hard drive image with a bigger size by going to the File > Virtual Media Manager and click New button to start Create New Virtual Disk wizard.

- Click on the Settings button for your Guest OS, and choose the Storage category. Click on Add Attachment under Storage tree and add the created .vdi file as a hard disk. It should be set as IDE Primary Slave on the Attribute panel.

- Download and install a free edition of HDClone here
- Click on the Settings button for your VM, and choose the Storage category. Mount hdclone.iso (located in the bootimages folder of the HDClone's installation) in CD/DVD Device.

- Ensure the boot order is set to CD-ROM first and start the VM.

- Follow HDClone wizard and select Drive- - Once a complete copy is created, quit HDClone, unmount the hdclone.iso in VirtualBox, set new hard drive as master and start VM.
- The old hard drive can be deleted or reformatted.
That's it. Enjoy it!