NOTE: check the vboxcontrol section for up to date information. This article is a bit stale.

Today, uptime of Far Fewer Toes suffered. That’s because we’ve bought a new computer to host the site on. Previously, we were hosting on an old Pentium III 600, which badly needed a replacement. We also needed to free up another box, in order to use it for real reviews and tests (as opposed to in VirtualBox).

Yesterday evening and today I’ve been working on setting everything up, and this site is now hosted in a VirtualBox instance on the new machine: an AMD Athlon64 x2 4400+ with 4 GB of RAM.

Now, VirtualBox doesn’t come with some kind of init script to automatically start all virtual machines on boot of the host, and after searching how others solved this problem, i stumbled on the blog of Mandriva’s Adam Williamson. He has written a blog post containing among other things the required steps to set up VirtualBox with host-based networking.

His post didn’t cover how to start everything on boot of the host machine, and shutting down VirtualBox and all virtual machines gracefully on reboot or shutting down of the host.

After some more reading around, I’ve created an initial working version of a VirtualBox init.d script, which does the following things for you:

  • Configure and bring up the bridge tap network interfaces on startup
  • Start VirtualBox and the Virtual Machines in vrdp mode
  • Send an ACPI power down command to your virtual machines, and waits for them to gracefully shut down completely
  • Disable the tap and bridge configuration on shutting down/stopping the service

The script was developed on and for Ubuntu 7.10 Gutsy Gibbon, and needs some modifications if you want to run it on other distributions.

Also, the script assumes a few things:

  • The script does not work with the OSE edition, since the machines are started in VRDP mode. But hey, since Sun has acquired InnoTek, it can’t be long before the VRDP support is Open Source as well, right? :-)
  • Network Roaming should be disabled (on Ubuntu, turn off roaming support in System -> Administration -> Network)
  • The user under which VirtualBox is running should be in the ‘vboxusers’ group

Instructions to install the script on Ubuntu 7.10:

  • Put the script in the /etc/init.d/ directory
  • Make the script executable:
    chmod 0755 /etc/init.d/VirtualBoxMachines
  • Put a br0 entry in /etc/network/interfaces:
    inet br0 inet dhcp
  • Create a new directory called /etc/virtualbox
  • Create a file called /etc/virtualbox/config with the following lines:

    HOST_IF="eth0"
    HOST_IP="192.168.1.5"
    VM_USER="jochem"
    TAPS="tap0 tap1"

    Change all values appropriately for your system.
    HOST_IF is the interface which VirtualBox uses to bridge.
    HOST_IP is the standard ip address of the host.
    VM_USER is the user under which all VM’s will run.
    TAPS are the tap interfaces you want to set up. Use one for each VM, seperate them by a space.
  • Create a file called /etc/virtualbox/machines_enabled with a virtual machine
    name on each line. Example:

    Debian Webserver
    OpenBSD Fileserver
  • Set up VirtualBox to use the specified tap interfaces for your machines (in the Network settings screen for your VM, set ‘Attached To’ to ‘Host Interface’, and ‘Interface Name’ to ‘tap0′ for the first VM, ‘tap1′ for the second VM, etc.
  • Let the script start up at boot:
    update-rc.d VirtualBoxMachines defaults 99 10
    (this command starts the machine at the latest possible time, when everything else has already booted, and at reboot/shutdown it’s executed in the beginning of the shutdown procedure)


Note: the script is kind of hackish, and is open to improvements. I’ve released it without a license, in the public domain

Update 20080311: configure your virtual machines to have a static ip address if your host is also the dhcp server for your network. The reconfiguring of your network interfaces at boot doesn’t work well with a running dhcp service.

Update 20080331: uploaded new version of script. Cleaned it up, added bridge-up/bridge-down, taps-up/taps-down methods, rename setup_* to enable_*, show VM names in ’status’ output, and check if taps are already configured before bringing them up

Update 20080511: Renamed the script to vboxcontrol, cleaned it up put it some more functionality (requested in the comments), and gave it its own section on farfewertoes.

Download and instructions here!