May 18, 2011

Headless Virtualbox on Ubuntu 10.04 LTS

Updated Scripts (06/07/2012):

VBoxManage createvm -name centos6 --ostype RedHat -register
VBoxManage modifyvm centos6 --memory 1024 --pae on --acpi on --boot1 dvd --nic1 nat --natpf1 "guestssh,tcp,,2222,,22"
VBoxManage modifyvm centos6 --natpf1 "www,tcp,,1888,,80"
VBoxManage storagectl centos6 --name IDE0 --add ide --controller ICH6
VBoxManage createhd -filename ~/centos6/sda.vdi -size 20000
VBoxManage storageattach centos6 --storagectl IDE0 --port 0 --device 0 --type hdd --medium ~/centos6/sda.vdi
VBoxManage storageattach centos6 --storagectl IDE0 --port 1 --device 0 --type dvddrive --medium ~/bigfiles/CentOS-6.2-i386-minimal.iso

To enable VRDE:


VBoxManage modifyvm centos6 --vrde on --vrdeport 3392

After installation is finished, boot hdd:
VBoxManage modifyvm centos6 --boot1 disk

To add hostonly interface:
# sudo tunctl -u $USER # add tap0 device
# sudo ifconfig tap0 192.168.100.1 netmask 255.255.255.0
VBoxManage modifyvm centos6 --nic2 hostonly --hostonlyadapter2 tap0

To add the second interface as bridged interface:

VBoxManage modifyvm centos6 --nic2 bridged --bridgeadapter2 eth0

Original Post:
http://tuxnetworks.blogspot.com/2010/05/howto-virtualbox-31-headless-on-lucid.html

That's it, Virtualbox should be installed and ready to go.
Now we can move on to creating a virtual machine
Create a machine named "io"

VBoxManage createvm -name io --ostype Ubuntu -register

Configure it with a nic bridged to eth0, 256Mb RAM, enable acpi and set to boot from DVD

VBoxManage modifyvm io --memory 256 --pae on --acpi on --boot1 dvd --nic1 bridged --bridgeadapter1 eth0

Create a virtual IDE controller

VBoxManage storagectl io --name IDE0 --add ide

Create a virtual HDD

VBoxManage createvdi -filename ~/.VirtualBox/Machines/io/sda.vdi -size 48000 -register

Attach the virtual HDD

VBoxManage storageattach io --storagectl IDE0 --port 0 --device 0 --type hdd --medium ~/.VirtualBox/Machines/io/sda.vdi

Create and attach a virtual DVD drive to the controller and insert the DVD image

VBoxManage storageattach io --storagectl IDE0 --port 1 --device 0 --type dvddrive --medium /store/archive/ISO/ubuntu-10.04-server-i386.iso

The default vrdp port for machines is 3389, however, if you intend to run more than one guest then each one will need to listen on a different port. I use the 3xxx range with the xxx being the last octet of the machines IP address. For example, 192.168.0.1 would be 3001.

VBoxManage modifyvm io --vrdpport 3001

And thats it, your machine has been created. Time to start it up and give it a test drive!

Using the virtual machine

Start the machine

nohup VBoxHeadless -startvm io &

On a GUI workstation, establish a remote desktop connection to the machine. In my case, the host server is called "jupiter" so I type;

rdesktop -a 8 jupiter:3001

After you have installed the OS, you need to tell the machine to boot from the hdd.

VBoxManage modifyvm io --boot1 disk

You can also deregister the dvd image if you don't intend to use it again.

VBoxManage unregisterimage dvd /store/archive/ISO/ubuntu-10.04-server-i386.iso

To Stop VM/Hibernate/Save Sate:

vboxmanage controlvm centos6 savestate

To Power Off VM:
vboxmanage controlvm centos6 poweroff


Here are some other useful commands;

VBoxManage showvminfo io
VBoxManage list hdds
VBoxManage list runningvms
VBoxManage controlvm io poweroff
VBoxManage unregistervm io --delete
VBoxManage controlvm io savestate
VBoxManage closemedium disk UUID
VBoxManage modifyhd UUID --type immutable

1 comment:

  1. Thanks so much for posting this. It sped my efforts along substantially. I have a CentOS virtual machine running on a ubuntu headless server. Everything worked first time. Quite fun to see the remote desktop there waiting the first time you connect to perform the OS install.

    ReplyDelete