VirtualBox: startup guest machine in background

October 31st, 2010 mysurface Posted in VBoxHeadless, VBoxManage, VirtualBox | Hits: 157266 | 4 Comments »

Usually we start our virtual machine by clicking through the GUI. If your guest machine is a server, it would be making more sense to be run as background process.

Well, my case, I have ‘gentoo’ installed in virtual box, which expose to outside world through ssh. I would like it to start as background process, how can I do that?

Virtual Box allows you to start your virtual machine through command line VBoxHeadless, by adding ‘&’, you can make the process run as background.

VBoxHeadless -s [guestname] &

I wrote a bash script to help myself perform the background startup, reboot, poweroff and status query. Assume my guest machine name as ‘gentoo’, I wrote a script name as ‘gentoo’. Now I can do ‘gentoo start’ to start it at background.

#!/bin/bash

if [[ -z "$1" ]]
then
    echo "Usage:"
    echo "      gentoo [status|start|reboot|poweroff]"
    exit
fi

if [[ $1 == "status" ]]
then
    # print out the machine state
    VBoxManage showvminfo gentoo | grep State
elif [[ $1 == "start" ]]
then
    # start without vrdp
    VBoxHeadless -s gentoo --vrdp=off &
elif [[ $1 == "reboot" ]]
then
    # send ctrl+alt+del to guest machine
    VBoxManage.exe controlvm gentoo keyboardputscancode 1d 38 53 b8 9d
elif [[ $1 == "poweroff" ]]
then
    # simulate pressing power off button, will power cut immediately
    VBoxManage controlvm gentoo poweroff
fi

With the capabilities of command line to manipulates the guest machine, it helps to support for more customization and automation. This is the main reason I like about VirtualBox.

Have fun :)

4 Responses to “VirtualBox: startup guest machine in background”

  1. Hi there,

    another useful thing is a little bash-function i wrote to get all installed machines with their current state.

    vboxlist ()
    {
    vboxmanage list -l vms | egrep -i –color=auto ‘(Name: |State:)’ | sed ‘s/Name:[ \t]*\|State:[ \t]*//’ | sed ‘$!N;s/\n/ – /’
    }

  2. Thanks for the script. Works like a charm

  3. Pourquoi pas après promote. over revu Juan Carlos le ldurantedemain dans le but de compagnie les sa femme et sa belle mère à l’aéroport accueillir fants, are generally soeur d’Ingrid et child ex boyfriend or girlfriend mari, air max noir Arrivés environnant les people from france. the surndemain, Ingrid et sa famille française sont gains en france level l’avion présidentiel. Vendredi 18 avril, fin du academic journal présenté level Olivier Galzi. la n

Leave a Reply