Rails, Firefox, Anime, Mac
I had to spend some time setting up Xen on one of the new Dell servers we bought and while there was some documentation around, I had to constantly refer to the different sources since there wasn’t a complete page which had everything I needed for my particular situation – I have a host machine with Ubuntu Feisty Fawn installed and wanted to install a couple of Xen guest domains on it. One other thing I found lacking in the documentation is the explanation of commands or answers to the question “so why the hell am I doing this?”. I’m not considering LVM at the moment and am happy with loopback disk file images too.
So I think it’s a good idea to write this down somewhere for the next time I have to do the same bloody thing over again on any new servers.
Some caveats before we start:
Some terms that deserve explaining (most guides out there just use “DomU” and “Dom0″ without any ceremony, and assume you know what they mean):
OK let’s go!
First off, we need to install the Xen server on the host machine (or Dom0). Thankfully, there is a Xen server package in Feisty Fawn’s apt-get repository.
/etc/apt/sources.list and run: apt-get install ubuntu-xen-serversudo xm list should show you Domain-0 (which is the host machine that’s running Xen).(network-script network-bridge)
(network-script network-dummy)
sudo xend restart
Now let’s create a base Xen image. We’ll use this as a template for any future images (domUs).
dd if=/dev/zero of=/xen-images/feisty_base.img bs=1024k count=4000
dd if=/dev/zero of=/xen-images/feisty_base_swap.img bs=1024k count=1000
These commands create image files of 4GB and 1GB for your virtual OS and its swap respectively. ‘count’ is the number of blocks (block size = 1024k).
mkfs.ext3 /xen-images/feisty_base.img
Answer ‘yes’ to proceed anyway when it complains about the file not being a block device.
mkswap /xen-images/feisty_base_swap.img
chmod 640 /xen-images/feisty_base*
mkdir /xen-images/mnt
mount -o loop /xen-images/feisty_base.img /xen-images/mnt
Now we have full access to the base image’s filesystem. What we need to do now is to put a base install of Feisty Fawn on it.
Next, we have to put Ubuntu onto the image and configure it to our liking.
apt-get install debootstrap
debootstrap feisty /xen-images/mnt
After this is done you should see the basic Ubuntu file hierarchy:
ls /xen-images/mnt
cp /etc/apt/sources.list /xen-images/mnt/etc/apt/
cp -a /lib/modules/2.6.19-4-server/ /xen-images/mnt/lib/modules/
libc6-xen package, which is a Xen-compatible glibc that allows applications to use Thread-Local Storage (TLS).
apt-get install libc6-xen
Taken from the Xen FAQ:
Some modern distributions ship with a ‘TLS’ version of glibc that is not fully compatible with Xen. To use Xen reliably and with maximum performance you must disable the incompatible glibc.
/xen-images/mnt/etc/network/interfaces:
auto lo
iface lo inet loopback
# Uncomment this and fill up with your networks settings.
#auto eth0
#iface eth0 inet static
# address 192.168.0.201
# netmask 255.255.255.0
# broadcast 192.168.255.255
# gateway 192.168.0.1
# dns-nameservers 192.168.0.1
Notice how the network settings are commented out – this is because we are leaving the base image as a template from which other images would be made from.
/xen-images/mnt/etc/hosts):
127.0.0.1 localhost localhost.localdomain
127.0.0.1 guest
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
/xen-images/mnt/etc/hostname. In this case I’m just naming it ‘guest’ – actual virtual machines would have sensible hostnames./xen-images/mnt/etc/fstab).
proc /proc proc defaults 0 0
/dev/hda1 / ext3 defaults,errors=remount-ro 0 1
/dev/hda2 none swap sw 0 0
Don’t worry, the /dev/hda* would be configured to point to the images you created, not to your actual physical harddisks.
umount /xen-images/mnt
/etc/xen/vm_feisty_base.config.example.sxp (you can name it whatever you like of course):
name = "feisty_base"
kernel = "/boot/vmlinuz-2.6.19-4-server"
ramdisk = "/boot/initrd.img-2.6.19-4-server"
root = "/dev/hda1 ro"
memory = 512
disk = ['file:/xen-images/feisty_base.img,hda1,w','file:/xen-images/feisty_base_swap.img,hda2,w']
# Network.
hostname = "feisty_base"
vif = ['bridge=xenbr0']
dhcp = "off"
ip = "192.168.0.201"
netmask = "255.255.255.0"
gateway = "192.168.0.1"
An explanation of the configuration options:
xm create /etc/xen/vm_feisty_base.config.example.sxp -c
You should see a console (the ‘-c’ option connects you to the console immediately after booting up the virtual machine. Login as root (empty password) – you’ll want to change the password (with ‘passwd’).
shadowconfig on
/etc/network/interfaces and edit /etc/network/interfaces to put in correct values so you can access the Internet from the virtual machine:
cp /etc/network/interfaces /etc/network/interfaces.bak
vim /etc/network/interfaces
ifup -a
apt-get update
apt-get install ubuntu-standard
apt-get upgrade
apt-get install ssh
ifdown -a
mv /etc/network/interfaces.bak /etc/network/interfaces
Ctrl-]. This will bring you back to dom0′s shell.-w means “wait for the domU to shutdown completely”):
xm shutdown feisty_base -w
You’re done setting up the base image! Now you have a nicely configured base image.
The fruits of thy labor are almost at hand – with the base image, we can now make a copy of it for our first Xen virtual machine.
cp /xen-images/feisty_base.img /xen-images/yuki.img
cp /xen-images/feisty_base_swap.img /xen-images/yuki_swap.img
You may want to resize the base image depending on your disk space needs. (And, of course, you can create your own swap image like we did earlier instead of copying the base image’s swap file.)
cp /etc/xen/vm_feisty_base.config.example.sxp /etc/xen/vm_yuki.config.sxp
/etc/xen/vm_yuki.config.sxp file, changing the values to suit your virtual server (you probably want to change at least the ‘name’, ‘disk’, ‘ip, and ‘hostname’ values).
name = "yuki"
disk = ['file:/xen-images/yuki.img,hda1,w','file:/xen-images/yuki_swap.img,hda2,w']
hostname = "yuki"
ip = "192.168.0.202"
xm create -c /etc/xen/vm_yuki.config.sxp
passwd
ifup -a
ping google.com
Ctrl-]
ln -s /etc/xen/vm_yuki.config.sxp /etc/xen/auto/
Any Xen domain configuration placed in /etc/xen/auto/ will be started up automatically on boot (and shutdown when the host machine is shutdown too).
That’s it! You have a functional Xen guest domain that starts up on boot and that can connect to the Internet. Oh before I forget, some useful commands when dealing with the Xen images:
xm create /path/to/config_file – Starts up the guest domain with the given Xen domU configuration file. (xm create -c to login to the console immediately after booting the image.)xm console yuki – Open the console for the ‘yuki’ Xen domain.xm shutdown yuki – Shutdown the ‘yuki’ domU.xm list – Lists all the Xen domains you have running.Let’s say you wanna add 1GB of disk space to your virtual machine (named ‘yuki’).
Note that LVM is usually recommended for Xen setups, so you may wanna take a look at that instead.
dd if=/dev/zero of=/tmp/temp_expand bs=1024k count=1000
xm shutdown yuki
cat /tmp/temp_expand >> /xen-images/yuki.img
resize2fs -f /xen-images/yuki.img
xm create -c /etc/xen/vm_yuki.config.sxp
df -h)Copyright (c) 2003-2012 redemption in a blog
Heavily modified Compositio Theme created by: Design Disease brought to you by PremiumThemes.com
21 Responses to Installing Xen on Ubuntu Feisty Fawn – the complete newbie’s guide
Free as in Time » Blog Archive » Mmmm... Xen
June 28th, 2007 at 10pm
[...] I have yet to give this a try, but it looks very helpful: Installing Xen on Ubuntu Feisty Fawn – the complete newbie’s guide. [...]
Geekularity » links for 2007-06-29
June 30th, 2007 at 7am
[...] Installing Xen on Ubuntu Feisty Fawn – the complete newbie’s guide – redemption in a blog (tags: ubuntu xen) [...]
links for 2007-06-30 « My Weblog
June 30th, 2007 at 12pm
[...] Installing Xen on Ubuntu Feisty Fawn – the complete newbie’s guide – redemption in a blog (tags: tutorial linux virtualization) [...]
Alternageek » Show Notes for AlternaGeek Episode 7
July 24th, 2007 at 9pm
[...] XenExpress on Feisty: Complete Newbies Guide to Installing Xen on Ubuntu Feisty Ubuntu Forums – Installing [...]
vainov
July 27th, 2007 at 8pm
I am following this path exactly as shown above. When I get to
xm create /etc/xen/vm_feisty_base.config.example.sxp -cI get the following error:
Error: (22, 'Invalid argument')I’m running on a Dell Dimension 8400 w a P4/3.0GHz computer w HT enabled.
Any ideas?
BTW:
There is a typo in the code sample
debootstrap feisty /xen-image/mnt
Should be:
debootstrap feisty /xen-images/mntvainov
July 27th, 2007 at 9pm
Comment to my previous posting:
Kernel images v
2.6.20-15don’t seem to work. If I use images v2.6.19-4then everything works fine.Additional typo appears in listing for
/etc/xen/vm_feisty_base.config.example.sxpThe swap file is named
feisty_base_swap.imgin the initial procedure, but in the sample the ‘disk =’ paramter requests a swap file namedbase_swap.img.Chu Yeow
July 28th, 2007 at 1pm
vainov: Thanks for pointing out the typos! I’ve fixed them. And I also faced a similar problem getting the 2.6.20-15 kernel images to work so sorry can’t help you there.
Neil
August 21st, 2007 at 8am
My CPU will not support Xen, on an IBM T42 laptop, you need a PAE enabled CPU,
cat /proc/cpuinfo | grep paewill tell you if you can run Xen.http://kbase.redhat.com/faq/FAQ_108_10486.shtm
zucaritas
August 24th, 2007 at 10pm
I can’t get the network running, and when i do
zucaritas
August 24th, 2007 at 10pm
sorry, it was when i do
apt-get install libc6-xenTwo wins! « Awed Manor
September 9th, 2007 at 8am
[...] be able to import VMWare virtual machine images – but then I saw the “quick and easy” instructions. No, thanks. I know that some of it is involved in setting up the template so everything else [...]
pradeep
September 9th, 2007 at 8pm
After the following steps, my network stops :
# Edit /etc/xen/xend-config.sxp and uncomment this line:
(network-script network-bridge)
# Comment out this line:
(network-script network-dummy)
# Restart xend:
sudo xend restart
I have a static IP assigned to eth0. Do I need any additional steps?
Thanks !!
– noob
Mmmm… Xen
November 9th, 2007 at 2am
[...] I have yet to give this a try, but it looks very helpful: Installing Xen on Ubuntu Feisty Fawn – the complete newbie’s guide. [...]
Trung
November 29th, 2007 at 10am
The created VPS will sometime produce this error
To fix this:
(from https://help.ubuntu.com/community/Xen)
Kalmi
December 1st, 2007 at 1am
multiverse needs to be enabled too…
I needed it for the xen-linux package…
A Fresh Cup » Blog Archive » Double Shot #66
December 29th, 2007 at 9pm
[...] Installing Xen on Ubuntu Feisty Fawn – the complete newbie’s guide – I hope not to have to tackle this any time soon, but if I do, this looks like a good unified guide. [...]
???0000?????? » Blog Archive » ??xen?????????
March 10th, 2008 at 4pm
[...] Installing Xen on Ubuntu Feisty Fawn – the complete newbie’s guide [...]
Sailface » Blog Archive » links for 2008-07-18
July 18th, 2008 at 8pm
[...] Installing Xen on Ubuntu Feisty Fawn – the complete newbie’s guide | redemption in a blog (tags: xen ubuntu virtualization) [...]
Assertions and Deviations :: Virtualization :: Blank or black screen when booting Ubuntu on Xen
May 29th, 2009 at 12pm
[...] with a generic Intel 960 series motherboard and a lack-tastic X3100 video card). There are various tutorials and howtos on doing this, so it went [...]
Setting up virtualization on Ubuntu with KVM - redemption in a blog
February 1st, 2010 at 10pm
[...] being a happy Xen user for several years now, I’ve recently had to switch to an alternative virtualization solution. [...]
Some useful Links and References - Xen Tutorial
October 4th, 2010 at 9pm
[...] * http://blog.codefront.net/2007/06/26/installing-xen-on-ubuntu-feisty-fawn-the-complete-newbies-guide... [...]