Tuesday, June 21, 2011

Convert Virtual Box in to VHD and boot from the VHD File


It’s after long time since my last post. Finally I thought to share some experience I had with the VHD files and Oracle virtual boxes.  I was trying to install and configure SharePoint 2010 Server in my home PC.  
After several attempts I configured a Oracle Virtual Box by installing Windows Server 2008 R2,Active Directory, Visual Studio 2010, SQL Server 2008 and finally Share Point with all prerequisites. Finally I found out my resources I have in my PC is not enough to run the SharePoint ( I have only 4GB RAM and my instructor worn me about it already but I didn’t care about it :D )
Finally I had to go for some other options
Boot VHD is a good option and for implement it, I had to created new VHD and install all the software again in to the new VHD that was a hard task then I found there is a possibility to convert vdi (virtual Box File) in to VHD format. Then I had to try it
VboxManage utility comes with inbuilt to the Oracle virtual box

Steps to convert VDI file to VHD
  1.     .  First of all if there is any snap shots related to your virtual box vdi file, delete them (delete them through virtual box console it will merge snap shot and current state of the virtual box) and bring the vhd in to one stable point .
  2.        Uninstall virtual box guest additions if you already installed them in to your virtual box.
  3.    . Release and remove the vhd file form the virtual media manager in the oracle virtual box. Otherwise it will generate an error saying “cannot register the hard disk …etc .”
  4.    .DO NOT REMOVE THE PHYSICALE FILE of the virtual hard disk.
  5.      Go to Command prompt and navigate in to your virtual box program folder     “C:\Program Files\Oracle\VirtualBox\”
  6.  Type  vboxmanage clonehd “Path to your Virtual box vdi file” “path to newly creating VHD File” - - format VHD    C:\Program Files\Oracle\VirtualBox> vboxmanage clonehd “F:\myVirtualBox.vdi” “F:\myVHD.vhd
  7. Then above command will create a .vhd file which is located in the F drive in above example.

8.       Depending on resources of your host machine, it will take some time. Mine it took several hours so be patient.

Next step is attach vhd file and boot from vhd.
Steps to attach vhd file and boot
There were several articles on the web explained how to create new vhd file and install os in to that file. But only few which explains how to attach existing vhd and boot from it.
If you already attached your vhd  from disk management you have to remove it using diskpart utility
How to remove the vhd (detach vdisk)
1.        1. Go to command prompt and type diskpart
a.       C:> DISKPART
2.       2. Then type select vdisk file =”file path”
DISKPART:> SELECT VDISK FILE =”F:\ myVHD.vhd”
DISKPART> detach vdisk
DISKPART> exit
3.       3. Then you have to use the bcdedit utility to copy the boot load entry for new boot option in the start up. 
     NOTE: your computer will give error saying access denied or you do not have permission then you have to go to Startmenu -> All programs -> Accessories -> write click on command prompt and click on “Run As Administrator”
4.     4.   Then type following command in the command prompt
a.       bcdedit  /copy {current} /d “name you like to use in boot menu
5.      5.   It will create a new boot menu entry with the name you gave. (Long string {GUID} will display after the message copy it and save it you will need it in next steps ) You will be able to check it by type bcdedit and press enter that will display all the boot loader entries
6.      6.  Then type the following commands with previously saved GUID
bcdedit  /set  {GUID} device VHD=”path to vhd file”  ( example for path F:\ myVHD.vhd) 
bcdedit  / set {GUID} osdevice VHD=”path to vhd file”
bcdedit  /set  {GUID} detecthal on
NOTE : sometimes there will be an error saying about the path then try it with “[locate] “ instead of your drive letter it will find the drive and do the execution that option worked for me
bcdedit  /set  {GUID} device VHD=[locate]\myVHD.vhd







No comments:

Post a Comment