VirtualBox Tips
Convert VHD to VDI
Recently I needed to convert Microsoft virtual machine for Windows Server 2008 x64 to VirtualBox disk. Use this code to convert VHD to VDI and then create regular MS machine, add VDI and boot from it.
VBoxManage clonehd "\path-to-location\microsoft-vmachine.vhd" "\path-to-location\vbox-disk.vdi" --format vdi
BIOS Time Offset
VirtualBox doesn’t support changing time in BIOS but you can set time offset. I needed this to test my web application. First you need to calculate number of days between current day and the day you want to go back in time, next you multiply number of days with 86400000 to get number of miliseconds. Then you can run this code to offset your VBox machine time. And if you like to do things by hand you can edit your VBox machines XML file and change TimeOffset value. In this example I will go back in time 10 days which is 864000000 miliseconds.
VBoxManage modifyvm "name-of-your-machine" -biossystemtimeoffset -864000000
Run Headless Webserver Silently
I needed to create headless web server and start it silently. First I created Ubuntu virtual machine (named it “webserver”) and installed it, then I created batch file in its folder.
VBoxHeadless -s "webserver"
Then I created VBScript file in the same folder and made shortcut on my desktop so I can start it anytime I want.
Set WshShell = WScript.CreateObject("WScript.Shell") obj = WshShell.Run("webs.bat", 0) set WshShell = Nothing
Poweroff Headless Machine from command line
Options are: pause, resume, reset, poweroff, savestate, acpipowerbutton and acpisleepbutton.
VBoxManage controlvm "name-of-your-machine" poweroff
Clone VBox Disk
VBoxManage clonevdi /directory/source.vdi /directory/target.vdi --format VDI
Though you can also use standard file copy as it might be faster but after that you will have to change UUID of target VDI.
VBoxManage internalcommands sethduuid /directory/target.vdi
Note: clonevdi command is obsolete and you should use new “clonehd” command like this:
VBoxManage clonehd /directory/source.vdi /directory/target.vdi
Category: Software, Updated October 17, 2011 from admin | Log in