Quote:
Originally Posted by ricardoc
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.