Setting up a Headless Virtual Machine on a Linux Server Using VirtualBox

This shows you how to set up a VirtualBox VM on a linux server that has no X Windows installed. This is handy if you have a Linux server but require a Windows one for some reason, and don't want to pay for another server.

  1. Install Virtual box
    # For debian
    $ sudo apt-get install virtualbox-ose
    # For redhat
    $ sudo yum install VirtualBox-OSE
    Otherwise you can download the source and compile it from
  2. Create a Virtual Machine, I will make a Windows XP virtual machine:
  3. # Register the vm's name
    VBoxManage createvm --name "Windows" --register
    # setup the memory/acpi and boot device for the VM
    VBoxManage modifyvm "Windows" --memory 512 --acpi on --boot1 dvd
    # This command will make a brided NIC to the real network eth0
    # you can then dedicated IP address for the VM
    VBoxManage modifyvm "Windows" --nic1 bridged --bridgeadapter1 eth0
    # OR This will make a NATed NIC, to which you will have to forward ports
    VBoxManage modifyvm "Windows" --nic1 nat
    # Make the nic an intel device
    VBoxManage modifyvm "Windows" --nictype1 82540EM
    # Enable IOAPCI
    VBoxManage modifyvm "Windows" --ioapic on
    # give the vm a hard disk
    VBoxManage storagectl "Windows" --name="IDE Controller" --add ide
    VBoxManage createvdi --filename "WindowsXP-disk01.vdi" --size 10000 --register
    VBoxManage modifyvm "Windows" --hda "WindowsXP-disk01.vdi"
    # and a dvd drive containg the install media
    VBoxManage storageattach Windows --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium /path/to/iso
    # Eject the dvd
    VBoxManage storageattach Windows --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium emptydrive
    # display some info about he vm
    VBoxManage showvminfo "Windows" --details
  4. Now start your VM. This is best from within a screen session ( so you can disconnect from the server but keep the VM running.
    VBoxHeadless --startvm "Windows" --vnc --vncport 12345 --vncpass password
    You can now connect to it using VNCViewer