Archive for the ‘virtualbox’ Category

Running virtualbox Linux guests in headless mode

April 21, 2011 2 comments

Sometimes it’s more convenient to start virtualbox Linux guests in headless mode and access them through ssh. This guide assumes the vm to be running in headless mode
1) has ssh server installed
2) uses static ip address or dhcp but ip address is known and doesn’t change

To run vb guest in headless mode, simply run the following command

VBoxHeadless -startvm vm_name&

To ensure vm to be accessible, its network setting under VirtualBox Manager needs to be set to Bridge mode and use static ip address (or dhcp if the ip doesn’t change upon reboots) for the vm. This needs to be done before the above command is run.

Wait for some moments after the headless command is issued, start pinging the vm to check if the vm is up by its ip (or use telnet vm_ip 22 if PING is blocked on the vm). SSH to it should be a piece of cake now.

If you are like me who doesn’t even want to type the command ssh (Yup I wrote a one-letter bash function just to wrap the ssh call to some machines that I use on a daily basis) , you might want to turn the VBoxHeadless command into a function in bash:
1) vim ~/.bash_profile
2) append the following
function headless {
VBoxHeadless -startvm $1&

headless() {
        [ $# -lt 1 ] && echo "Usage: $FUNCNAME vm_name" && return
        VBoxHeadless -startvm $1&

3) . ~/.bash_profile
4) headless vm_name
Notes: Step 3 just needs to be run once right after the function is added to your bash profile. Before step 4 is run please make sure the vm is not already running.

Categories: linux, Tip, virtualbox