This page describe how create a VM to run on stratuslab.
To use your image on StratusLab with all options available, you must tweak your image with
All this stuff is done by a RPM stratuslab-one-context or on YUM repository. You can install it on RPM based distribution with the command
user@vm$ rpm -i http://yum.stratuslab.eu/snapshots/fedora14/stratuslab-one-context-0.0.1-0.20110804.135844.noarch.rpm
or if you have configure StratusLab yum repository
user@vm$ yum install stratuslab-one-context
StratusLab allow users to submit some parameters when they start a VM. This parameters (–context or –context-file) can be use do specific post-boot action on the VM. The typical example is to put a public ssh key of the user on /root/.ssh/authorized_keys but you can add your own script.
Contextualization script need to have a specific directory /mnt/stratuslab
user@vm$ mkdir -p /mnt/stratuslab
If you don't want to use RPM, you can create a contextualization script (/usr/bin/stratuslab-one-context) like the following one and put it on /etc/init.d/rc.local
#!/bin/sh -e
############################
# Some variable definition #
############################
configuration_file=/etc/stratuslab/stratuslab-one-context.cfg
configuration_dir=/etc/stratuslab/conf.d
external_context_run=/tmp/external_context_run
echo "#!/bin/sh" > $external_context_run
#################################################
# Check if configuration file exist AND load it #
#################################################
if [ -f $configuration_file ]
then
source $configuration_file
fi
###################################################
# Check if contextualization device is accessible #
###################################################
if [ -n $context_device ]
then
if [ -e /dev/$context_device ]
then
DEVICE=$context_device
else
echo "Device $context_device does not exist"
exit -1
fi
else
echo "No device defined for contextualization"
exit -2
fi
###############################################################################
# Load all *.context file on configuration directory (/etc/stratuslab/conf.d) #
###############################################################################
if [ -d $configuration_dir ]
then
context_files=`ls $configuration_dir/*.context`
for context_file in $context_files
do
source $context_file
if [ "x$enable" == "xyes" ]
then
if [ "x$run_exec" != "x" ]
then
echo ". "$run_exec >> $external_context_run
fi
fi
run_exec=""
enable=""
done
fi
############################################################
# Mount contextualization device and do the standard stuff #
# from opennebula (mainly put the ssh keys on /root/.ssh) #
############################################################
mount -t iso9660 /dev/$DEVICE /mnt/stratuslab
if [ -f /mnt/stratuslab/context.sh ]; then
. /mnt/stratuslab/init.sh
fi
################################################################
# Run all contextualization script from /etc/stratuslab/conf.d #
################################################################
echo "Start all external context"
chmod +x $external_context_run
. $external_context_run
rm -f $external_context_run
umount /mnt/stratuslab
exit 0
The are 2 files type for contextualization, both are available on /etc/stratuslab
The *.context format is very simple.
enable=yes # If enable is not defined or defined as no, the script is not launch FOO=bar # I can define some usefull variable for my script run_exec=/path/to/script # The executable i want run
Every time i will start my VM, the /path/to/script will be run. If no special contextualization variable is defined by the user when he start the machine, 'foo' variable will have 'bar' value. But if a user run the instance a command like:
user@box$ stratus-run-instance --context="FOO=shi" http://url/mydisk.img.gz
The variable FOO will have value 'shi'
Like we use ssh key to log into Virtual Image, you can restrict the ssh authentification to ssh key authentification. This can be done on OpenSSH with the following option on /etc/ssh/sshd_config
PasswordAuthentication no
As your Virtual Image will be used by a lot of user and the image is available online, it s a good thing to randomize the root password @boot time. This can be done by the following script (/usr/bin/stratus-random-password)
#!/bin/sh newpswd=`cat /dev/urandom | tr -dc "a-zA-Z0-9-_\$\?" | head -c 8` passwd root <<EOF $newpswd $newpswd EOF
By default, a filesystem check is done every 180 days. This is useless with a Virtual Image and this delay the boot time when your Virtual Images are 180 days old.
To disable it, you must run the following command for every fs on your VM.
user@vm$ tune2fs -c 0 -i 0 /dev/hda1 ...
If you used VirtualBox to create a VM, you can convert it to a raw images to run on StratusLab. The easiest way to make your VM compatible with StratusLab is to convert your vdi disk into raw disk. This can be done with standard VirtualBox tools with the following command
user@box$VBoxManage internalcommands converttoraw mydisk.vdi mydisk.img user@box$gzip mydisk.img
Now, you ve got a img.gz, you can put it on a appliance repository and use it with command
user@box$stratus-run-instance http://url/mydisk.img.gz
or use a marketplace
user@box$ stratus-run-instance marketplace-id