VirtualBox 


VirtualBox is an Open Source virtualization solution similar to Parallels and Fusion that I’ve started using as my primary VM solution simply because a) it is available on pretty much all OSes I deal with and b) it is easier to install than Fusion (simply because VMware took a while to understand that their downloads section was a hassle).

To be honest I don’t like it much, but it works - plus it’s currently very popular, and you can’t beat free.

Useful Resources

phpVirtualBox is a great, nearly full-featured web interface for remote management. It allows you to do just about everything you need to remote VMs, including reconfiguring storage and network (as well as basic cloning).

Making the console faster

On Ubuntu VMs, edit /etc/modprobe.d/blacklist-framebuffer.conf and add:

blacklist vga16fb

(tip via Quentin)

Command-line management of VMs

I keep using (and forgetting about) this, so here goes:

VBoxManage startvm "chewie" --type headless
VBoxManage controlvm "chewie" poweroff

I usually run Ubuntu or Debian servers like this, with SSH mapped to a host port (set in the config, so I don’t need to specify it on the command line). If you need something more sophisticated, you can always use Vagrant.

init.d script

I eventually cobbled together from other examples the following init script for Debian environments, which I have repeatedly failed to convert to an upstart script.

It assumes that there is a single user and multiple VMs to be run under that user:

#!/bin/bash
#VirtualBox

VBOX_USER="user"
VMS="c3p0 r2d2 tarkin lando"

SU="su $VBOX_USER -c"
VBOXMANAGE="VBoxManage -nologo"
VBOXHEADLESS="VBoxHeadless"

# Send the ACPI powerbutton event to the virtual machine
vbox_powerbutton() {
    $SU "$VBOXMANAGE controlvm \"$1\" acpipowerbutton"
}

# Poweroff the machine
vbox_poweroff() {
    $SU "$VBOXMANAGE controlvm \"$1\" poweroff"
}

# Start the virtual machine
vbox_start() {
    $SU "$VBOXHEADLESS -s \"$1\" > /dev/null &"
}

# List all running VMs
vbox_list() {
    $SU "$VBOXMANAGE list runningvms"
}

start() {
    echo "Starting VirtualBox..."
    for machine in $VMS; do
       vbox_start $machine
            if [ $? -gt 0 ]; then
                echo "WARNING: FAILED STARTING $machine"
            fi
    done
}

stop() {
    echo "Stopping VirtualBox..."
tries=0
        while [ $tries -lt $VBOX_RETRY ]; do
            for machine in `vbox_list`; do
                vbox_powerbutton $machine
                sleep $VBOX_WAIT
            done;
            tries=$((tries + 1))
        done
        for machine in `vbox_list`; do
            echo "WARNING: UNCLEAN SHUTDOWN $machine"
            vbox_poweroff $machine
        done
}

status() {
    vbox_list
}

case "$1" in

    start)
        start
        ;;

    stop)
        stop
        ;;

    restart|reload|force-reload)
        stop
        start
        ;;

    status)
        status
        ;;

    *)
        echo "Usage: /etc/init.d/virtualbox {start|stop|reload|force-reload|restart|status}"
        exit 1

esac

exit 0

See Also: