Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > HOWTO-Related Questions

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 21st April 2010, 18:55
ricardoc ricardoc is offline
Junior Member
 
Join Date: Apr 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default VBoxHeadless-Just one machine at a time?

Hi Falco,

I've been following all your articles dedicated to running VMs with VirtualBox using VBoxHeadless. They are an interesting proposal. I have noticed though that invariably you talk about one connection at a time. Since the RDP protocol is used with the host IP and not the guest, how can we set up simultaneous connections to more than one guest running on a headless Linux box with VirtualBox?

Also, how can VirtualBox itself be managed remotely on a headless server? Is there a tool for that?

Thanks,

Ricardo.
Reply With Quote
Sponsored Links
  #2  
Old 21st April 2010, 20:16
dfed dfed is offline
Junior Member
 
Join Date: Apr 2010
Posts: 16
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by ricardoc View Post
Hi Falco,

I've been following all your articles dedicated to running VMs with VirtualBox using VBoxHeadless. They are an interesting proposal. I have noticed though that invariably you talk about one connection at a time. Since the RDP protocol is used with the host IP and not the guest, how can we set up simultaneous connections to more than one guest running on a headless Linux box with VirtualBox?

Also, how can VirtualBox itself be managed remotely on a headless server? Is there a tool for that?

Thanks,

Ricardo.
I have some things I've noted running this at home you may be interested in, but let's start with the vrdp servers.

You can set the creation of each machine to have a vrdp server enabled on guest, rather than on the host itself.

I manage my server via ssh and some (admittedly poorly written) hacks. I can detail them here soon (I am just about to head into work, so I can post more when I get there.)

running an ssh service on the host allows you to su - to the user that runs virtualbox (or ssh in as that user, if you allow it) and run VBoxManage and VBoxHeadless commands. If you are looking for a graphical hypervisor, ssh -X to the user that runs VirtualBox and execute the command VirtualBox and you'll get the familiar graphical VirtualBox interface.

In the meantime, I'll post the command-line scripts I use to control the guests in a short while.
Reply With Quote
  #3  
Old 21st April 2010, 22:40
ricardoc ricardoc is offline
Junior Member
 
Join Date: Apr 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi dfed,

Thank you for replying so fast. I would like to get a reference on how to set the vrdp server enabled guests. I would also like to take a look at your scripts (even if they are "poorly" written hacks); you have to start somewhere, don't you?

Regarding the graphical hypervisor, don't you need the X windows installed in the host to reach it through ssh? Will that mean that you have to add X to the headless server? Sorry for the silly questions but I'm not what you will call a Linux average user; I'm pretty new to this world.

Regards,
Reply With Quote
  #4  
Old 22nd April 2010, 00:16
dfed dfed is offline
Junior Member
 
Join Date: Apr 2010
Posts: 16
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by ricardoc View Post
Hi dfed,

Thank you for replying so fast. I would like to get a reference on how to set the vrdp server enabled guests. I would also like to take a look at your scripts (even if they are "poorly" written hacks); you have to start somewhere, don't you?

Regarding the graphical hypervisor, don't you need the X windows installed in the host to reach it through ssh? Will that mean that you have to add X to the headless server? Sorry for the silly questions but I'm not what you will call a Linux average user; I'm pretty new to this world.

Regards,
Sure. As for scripts, I'll post them in a bit. First, if you want to enable vrdp per guest you can get familiar with the command VBoxManage. Read up here:

http://www.virtualbox.org/manual/ch08.html

ETA or, more specifically, this:

http://linux-tips.org/article/74/ena...ualbox-machine

But for enabling vrdp servers on each guest, you'd do something like:

Code:
VBoxManage modifyvm MachineName -vrdpport <port>
To answer your question about X being installed on the host, if you have installed VirtualBox via the how-to here, most likely apt already grabbed the Qt and X libraries as a dependency. This means you shouldn't have to install anything to ssh -X (user@host) then run the VirtualBox command.

Some tips for automating some scripts from an ssh session to more easily control your VM's based on what I have done:

1) set up two directories in the home directory of the user you are running VirtualBox from. One is ~/bin and one is ~/config.

From there, you want to be able to use those directories for executable scripts (in ~/bin) that source configurations you can either automatically or manually gather (located in ~/config).

For example, in the crontab for the user running VirtualBox, I have this job:

Code:
# Regenerate list of installed Virtual Guests:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * ls ~/.VirtualBox/Machines | sort -u > ~/config/hosts
That generates a list of the hosts in a configuration file for me. Mine does it every five minutes, your choice of interval may vary. I build and destroy VM's rather often, as I use this box as a development and testing environment.

Also, depending on your network configurations (ie: home network on cable modem or broadband, etc.) you may want to consider this tutorial for your host:

http://www.howtoforge.com/installing...on-ubuntu-9.10

What this can do is give you a DNS resolution for the network for each of your guests (again, I am assuming this is a home network, not a corporate sandbox that may or may not already have DNS.)

With those two in place, you can then add a couple of other scripts. One would manage the startup and shutdown of your VM's either by individual name or all at a time. I wrote one for this, as seen below:

Code:
#!/bin/bash
#Written by me with no guarantee this pile of crap will work.
#init.d script to start/stop/restart all VM's installed on system via VirtualBox
#
# If we've not had 2 variables passed in the command line, failboat has sailed.
if [[ "${#}" -lt 2 ]]; then
    echo "Usage: ${0} <start|stop|restart> <(vm name)|all>" >&2
    exit 1;
elif [[ "${#}" -gt 2 ]]; then
    echo "Usage: ${0} <start|stop|restart> <(vm name)|all>" >&2
    exit 1;
fi
# First, declare some arrays to use later:
declare -a list
	list=($(ls ~/.VirtualBox/Machines/ | sort -u))
declare -a running
	running=($(ps -ef | grep VBoxHeadless | grep -v grep | awk '{print $10}' | sort -u))
# Sanity check on ${1}:
if [[ "${1}" == "stop" ]]; then
	com=${1}
elif [[ "${1}" == "start" ]]; then
	com=${1}
elif [[ "${1}" == "restart" ]]; then
	com=${1}
else echo "Usage: ${0} <start|stop|restart> <(vm name)|all>" >&2; exit 1;
fi
# Sanity check on ${2}:
checkvm=($(for z in ${list[@]}; do echo ${z} | grep ${2}; done))
if [[ "${2}" == ${checkvm} ]]; then
	vm=${2}
elif [[ "${2}" == "all" ]]; then 
	vm=${list[@]}
else echo "Virtual Machine ${2} not found.  Exiting." >&2; exit 1;
fi
echo "Working to ${com} ${vm[@]}"
# Let's do some work.
if [[ "${com}" == "start" ]]; then 
	for x in ${vm[@]}; do nohup VBoxHeadless --startvm ${x} 2> /dev/null > /dev/null &
		echo "Started VM ${x}"
	done
elif [[ "${com}" == "stop" ]]; then
	for x in ${vm[@]}; do VBoxManage controlvm ${x} poweroff 2>&1 > /dev/null
		echo "Stopped VM ${x}"
	done
elif [[ "${com}" == "restart" ]]; then
	for x in ${vm[@]}; do VBoxManage controlvm ${x} poweroff 2>&1 > /dev/null && nohup VBoxHeadless --startvm ${x} 2> /dev/null > /dev/null &
		echo "Restarted VM ${x}"
	done
fi
exit 0
Now this is a work in progress, as I have an extra array in there I don't use (yet) that checks which VM's are running (this will be for a future enhancement that checks for VM's that have died and restarts them.) I should note that I do this the hard way, as I could tell that line to use the VBoxManage command to give me running virtiuals. At it's basic this script will get you the ability to start/stop a single VM by name or all at once. It may duplicate some functions of the VirtualBox commands, but it's easier for me to remember to type. This can also be adapted to be used as an init.d script at start up to automatically boot your VM's.

One more I use is the following:

Code:
#!/bin/bash
source ~/.bashrc
command=$1
for x in `cat ~/config/hosts`
do
	ssh $x "uname -n; ${command}"
done
This is so I can send commands via ssh to each VM at once. This would be handy, if for example, I wanted to check disk usage on each machine. I could then just do a vcmd "df -h" (include the double quotes) and it would give me a readout of the response from each server.

Now this assumes you run SSH on each guest. Also, it assumes that each guest may have similar linux/unix operating systems. If you wanted to parse between BSD or Linux guests, you could set up something like the following:

Code:
#!/bin/bash
for x in `cat ~/config/hosts`; do ssh ${x} 'uname -nvo'; done > ~/config/host-os
This would give you a configuration file with the list of host names and their OS flavors. You could then adapt command scripts based on just those like so:

Code:
#!/bin/bash
source ~/.bashrc
command=$1
for x in `cat ~/config/host-os | grep "Ubuntu" | awk '{print $1}'`
do
	ssh $x "uname -n; ${command}"
done
This gives me the ability to run aptitude on all the ubuntu guests.

You get the idea. If you have bash scripting questions I can post some links to help learn more about that.

Last edited by dfed; 22nd April 2010 at 01:52.
Reply With Quote
  #5  
Old 22nd April 2010, 00:21
dfed dfed is offline
Junior Member
 
Join Date: Apr 2010
Posts: 16
Thanks: 0
Thanked 1 Time in 1 Post
Default

Also, forgot to add:

The basic funcitonality of my scripts are mostly covered in VBoxManage/VBoxHeadless commands. The extras I added are simple convenience and may not be written very effectively. I do like being able to execute a command to all (insert linux/UNIX flavor here) guests for keeping housekeeping duties easy.

The big one, though, is the script to start/stop all or one VM by name. This specifically can be used to start VM's automatically at boot and is helpful in case of unexpected outage on the host.
Reply With Quote
  #6  
Old 22nd April 2010, 01:10
dfed dfed is offline
Junior Member
 
Join Date: Apr 2010
Posts: 16
Thanks: 0
Thanked 1 Time in 1 Post
Default

Apologies for the many posts, but I often nitpick my own ideas and something just struck me.

My script to determine the OS of each guests and give a config file to use in other scripts is inelegant. It also fails when a windows guest is introduced, because that wouldn't have an ssh service.

Something much more elegant would be like the following:

Code:
#!/bin/bash
for x in `ls ~/.VirtualBox/Machines/ | sort -u`; do VBoxManage showvminfo ${x} | sed -n 5,6p; done
Of course this is off the top of my head. You could use various awk/sed magicks to get the needed info. Once gotten, you could tailor scripts to the various OS platforms your guests run (automating yum vs. automating aptitude, etc.)

Helpful commands to use in scripts I've just sussed out:

Show VM operating systems:

for x in `ls ~/.VirtualBox/Machines/ | sort -u`; do VBoxManage showvminfo ${x} | sed -n 5,6p; done

list running vms:

VBoxManage list runningvms | sed '5d' | awk '{print $1}' | grep -v "All" | grep -v "(C)" | sed 's/"//' | sed 's/"//' | sort -u

List all vms:

VBoxManage list vms | sed '5d' | awk '{print $1}' | grep -v "All" | grep -v "(C)" | sed 's/"//' | sed 's/"//' | sort -u


(ETA: Yeah these need to be combed over by me more thoroughly, but you get the idea.)

Last edited by dfed; 22nd April 2010 at 02:06. Reason: cleaned up script line
Reply With Quote
Reply

Bookmarks

Tags
vboxheadless, virtual machine, virtualbox

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
freebsd 7, samba 3, domain controller alexdimarco Suggest HOWTO 6 5th November 2010 16:54
Virtualizing a Physical Machine atjensen11 Server Operation 1 1st March 2009 05:31
Install/use a virtual machine on Ubuntu 8.10 DarkArchon HOWTO-Related Questions 1 7th December 2008 22:17
ntp time zone ftp weirdness jsigned Installation/Configuration 2 26th November 2008 02:09
Time logging xp users Aaron Morris Server Operation 4 3rd September 2006 23:45


All times are GMT +2. The time now is 06:10.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.