Home > linux, Tip, virtualbox > Running virtualbox Linux guests in headless mode

Running virtualbox Linux guests in headless mode

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.

Advertisements
Categories: linux, Tip, virtualbox
  1. September 6, 2011 at 5:25 pm

    Hi there — One other approach that I thought of was to have the VBoxHeadless command syntax as a line that would be inserted into the host system’s /etc/rc.d/rc.local file. What are your thoughts?

    • ricoch3n
      September 6, 2011 at 9:56 pm

      That would be perfectly fine, and you can also remove the ampersand at the end of the command. Actually that’s similar to what I did while working for an ISP. One thing to pay attention to is stuff in /etc/rc.local will run AFTER all run level scripts are executed, which in the VB case would be totally fine unless there are some services on the VB host that rely on those from the VB guests.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: