VirtualBox 

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

To be honest I don’t like it much, but it worked - plus it was quite popular, and you can’t beat free.

Useful Resources

virtualbox-kvm is a 2024 port of VirtualBox to use KVM as a hypervisor instead of ifs proprietary kernel module.

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).

macos-virtualbox automates the process of setting up a macOS VM on Windows and Linux.

Making the console faster

On 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 or servers like this, with 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 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

This page is referenced in: