There are many ways you can actually accomplish the installation of VM’s (DomU’s) on Xen and XenServer – from the extreme and complex howto’s to simply using pre-built images and templates.
This Howto is a mixture of both and has been written for the following reasons:
- I found a great site called Stacklet that builds bootable images for virtualization software such as Xen.
- I like using XenCenter for XenServer management (yes it is Windows only but OpenXenCenter is available for Linux although not 100% complete at the time of writing).
- I used to use Gentoo a lot in the past when I ran my own small beowulf cluster and really wanted a Gentoo VM to play around with.
- A completed Gentoo VM can be created from start to finish using XenCenter from a Windows computer on your network (anyone who knows me also knows I am not a Windows fan – but to keep things fairly simple, this is how I did it).
Notes:
- This Howto may or may not be right for you and I will take no responsibility for anything you do on your own servers. I would also like to state that this method could be done from within the XenServer using the CLI tools or programmatically using the XML-RPC based API (SDK’s available for C, C#, Java, PowerShell, and Python on the Citrix Community site).
- In this Howto we are creating a Paravirtualized Gentoo VM for XenServer using the image provided by Stacklet, there is no reason why this method will not work with any other Xen3 distro available from Stacklet.
Prerequisites
- Centos XenServer installed with Linux Templates (available from the optional 2nd install CD for Linux Guest Support)
- XenCenter on Windows somewhere on your network
- A Linux VM running on the XenServer (I used Centos 5.3 which can be installed using the Linux Templates)
- A XenServer Generic PV VM Template void of Virtual Disks which I provide – but you can create your own if you wish.
Create the Gentoo Virtual Machine
Select your running Linux VM and click the Storage tab. We want to create a new disk of a suitable size for our Gentoo to live so click ‘Add’ and create a disk the size you require (I created an 8 GB disk of which 1GB will be swap). Give it a name and description so you always know what it is (I named mine ‘Gentoo 2010.0 i386′ and added the description ‘Gentoo root and swap’). Once you click ‘Add’, make a note of its device path (I already have several virtual disks so my path was /dev/xvdf).
The disk will now be instantly available within your Linux Virtual Machine and now you can enter the console by clicking the ‘Console’ (log in to your VM as root). To make sure the Virtual Disk has been detected, you can type cat /proc/partitions(notice that I have also mounted thexs-tools.isowithin the Virtual DVD drive as we will need that shortly). We can now use our Linux VM and prepare our Virtual Disk for the Gentoo installation.# Type the following (or copy and paste) into your console # and replace [*] with your drive letter # Make sure we are in our home directory cd ~ # Create partitions using fdisk # I created 7GB for / and 1GB for swap # use 'm' for help while in fdisk # to quit, use 'q' or to write changes and quit, use 'w' fdisk /dev/xvd[*] # create an ext3 filesystem for the Gentoo root mke2fs -j /dev/xvd[*]1 # create a swap partition mkswap /dev/xvd[*]2 # Make a directory and mount the ext3 partition mkdir /mnt/root mount /dev/xvd[*]1 /mnt/root
Notes:
- The above steps could be done using the Graphical Console if available within your XenCenter from your Linux VM, just install a GUI parition editor (gparted for gnome etc).
- You do not need to partition in the way I have, as long as the 1st partition contains grub (for pygrub to work) then you can use whatever layout you like.
- The CLI application ‘cfdisk’ did not like the Virtual disks – I am not sure if that was just the version I had installed or if it will be the same for every distro.
- The above steps could be done using the Graphical Console if available within your XenCenter from your Linux VM, just install a GUI parition editor (gparted for gnome etc).
- Now we download the prebuilt Xen 3 Gentoo 2010.0 from Stacklet (I am using the 32bit version – but this should work with any of the Xen3 ready distros available on the site) and then we just copy it onto our newly created Virtual Disk.
# Type the following (or copy and paste) into your console # Get and mount the Stacklet Gentoo image mkdir gentoo cd gentoo wget http://stacklet.com/sites/default/files/gentoo/gentoo.2010-0.x86.20091128.img.tar.bz2 tar -xvjpf gentoo.2010-0.x86.20091128.img.tar.bz2 mkdir /mnt/loop mount -o loop gentoo.2010-0.x86.img /mnt/loop/ # Copy everything to the new disk rsync -avP /mnt/loop/* /mnt/root
- Our Gentoo root is now almost ready to be used, we just need to install the XenServer xe-guest-utilities and optionally change the default root password to something other than ‘password’. This step is optional at this time and can be done once the Virtual Machine has been booted (feel free to skip to the next step if you want to do this part later – especially if you are creating a template to distribute). If you are following this Howto to install a different Stacklet Distro, then skip to the next step.
# Type the following (or copy and paste) into your console # create a place to mount the Virtual DVD drive mkdir /mnt/cdrom mount /dev/xvdd /mnt/cdrom # copy resolv.conf into our chroot cp /etc/resolv.conf /mnt/root/etc/ # copy the RPM into our gentoo root # NOTE: there are 32bit and 64bit versions cp /mnt/cdrom/Linux/xe-guest-utilities-5.5.0-464.i386.rpm /mnt/root/ # We can now chroot into our Gentoo root and install it chroot /mnt/root # a watched emerge never compiles # only joking - Gentoo humour - compile! emerge rpm2targz # convert the RPM into a tar.gz rpm2targz /xe-guest-utilities-5.5.0-464.i386.rpm # untar into Gentoo # NOTE: This will not run on boot but demonstrates it works # (although it does not correctly recognise the distro) # The init.d script needs editing (I have had no time to get that far) # for now, just manually run it when you start your Gentoo VM # (/etc/init.d/xe-linux-distribution start) tar -xvzf /xe-guest-utilities-5.5.0-464.i386.tar.gz # Set your new root password passwd # type in your new password (twice) and we are done exit
Also during this stage, you could set your timezone, your hostname and domain name as done within the Gentoo Linux Quick Install Guide (code listing 2.17 and 2.18). It would also be a good idea to edit
/etc/fstaband put in our swap partition.
We can now finish up in our console and unmount the Gentoo image ‘umount /mnt/loop‘ and Gentoo Virtual Disk ‘umount /mnt/root‘. The next step is to use our newly created Virtual Disk, but first we have to Deactivate and Detach it from our Linux VM by simply clicking ‘Deactivate’ and then ‘Detach’ from within our Linux Virtual Machines ‘Storage’ tab in XenCenter. Our Virtual Disk is now ready.
For this step we need to use a template and Attach our newly created Virtual Disk. I used the XenServer ‘Debian Etch 4.0′ template and then let it install without booting up, I then deleted its Virtual Disks and added the new Gentoo one.
To save you doing this step, I have created a XenServer Generic PV VM Template (3.4KB) that contains no Virtual Disks (DO NOT use the XenServer ‘Other Install Media’ template as it will not work for paravirtualized setups), simply unzip then install from within XenCenter – select ‘Templates’ from the top menu and ‘Import Template’ (Import Type is an Exported Template).
Once you have Imported the template, you can create a new VM from it.
Change the Name, Description, VCPU’s, Initial Memory and anything else you wish to alter – You do not need to add any Virtual Disks as you have one to use.
On the last option, untick the ‘Start VM automatically‘ box as we do not want to start it yet – Then click ‘Finish’.
We can now select the VM and use its Storage tab to attach our Virtual Disk. Just boot up and use!
Do not forget to edit your /etc/fstab and add the swap partition and any other adjustments you want to make that I have not mentioned in Part 4 of this howto.
Once you have made your changes, you can make a template from your running Virtual Machine. Simply create a Snapshot by right clicking the Virtual Machine then select the VM’s ‘Snapshot’ tab. Right Clicking the snapshot will give you several options where you can create a VM from the snapshot, create a template from the snapshot and even export a template from the snapshot.
Conclusion
There we have it, a Paravirtualized Gentoo on XenServer using images from Stacklet. I would ultimately like to use my Gentoo VM to automatically create more images programatically, but that would depend on how much time I can spare towards the project. I would also like to create an ebuild of the xe-guest-utilities, but again – if I have the time I will.
This howto may look lengthy and complex… but the whole process is really simple… I hope this Howto helps someone.
3 responses so far ↓
M.S. Babaei // Jan 10th 2010 at 1:04 pm
tnx for this Great and useful How-to…
B. Merouze // Jan 22nd 2010 at 3:54 pm
Thanks a lot !
As found on another howto (which did not work for me), here is a patch for the xe-linux-distribution to recognise gentoo:
“”"
Edit xe-linux-distribution. Add the following function below the identify_lsb() function (don’t put it IN the function, put it BELOW the function).
identify_gentoo()
{
gentoo_release=”$1″
if [ ! -e "${gentoo_release}" ] ; then
return 1
fi
distro=”gentoo”
eval $(cat ${gentoo_release} | awk ‘{ print “release=” $5 }’ )
if [ -z "${release}" ] ; then
return 1
fi
eval $(echo $release | awk -F. — ‘{ print “major=” $1 ; print “minor=” $2 }’ )
if [ -z "${major}" -o -z "$minor" ] ; then
return 1
fi
write_to_output “${distro}” “${major}” “${minor}” “${distro}”
}
Next, you should add the following line
identify_gentoo “/etc/gentoo-release” && exit 0
put it just below the following line:
identify_debian /etc/debian_version && exit 0
“”"
(http://christopher.wojno.com/articles/2009/08/11/gentoo-domu-in-xenserver)
B. Merouze // Jan 25th 2010 at 6:30 pm
I made a Gentoo compliant init script to replace the xe-linux-distribution installed by the RPM.
It is available on the following post on Citrix Forums: http://forums.citrix.com/thread.jspa?threadID=247092
I’ll work on an ebuild if I have enough time this week. Hopefully Citrix will support Gentoo as a guest host one day!
Leave a Comment