Friday, December 4, 2009

Experimental Xen and Ubuntu. Part 2: hypervisor

This is second part of a two-part HOWTO. See Experimental Xen and Ubuntu. Part 1: kernel.

In this part we're going to compile the hypervisor and tools. You can install Ubuntu-provided binaries if you're happy with an older version. In that case, jump to Grub2 configuration. I'll again assume your compilation directory is ~/src.

Warning: You're about to install an experimental software. It might not work. The instructions might be outdated. In fact, I wrote this Howto over the course of 3 days and I had to update them. Use at your own risk.


0. Prerequisites

You'll need:
  • An hour or two
  • Some more development tools and libraries in addition to what you've already installed in part 1


    aptitude install mercurial xorg-dev python-dev zlib1g-dev python-openssl python-pam libssl-dev uuid-dev bcc bison flex checkinstall
    



1. Get ACPICA

You'll need one more tool: Intel's ACPI Component Architecture compiler. It's not in the distribution. Download it from http://acpica.org/downloads/ to ~/src, then:
cd ~/src
tar -xvzf acpica-unix*.tar.gz
cd acpica*/compiler
make
sudo chown root.root iasl
sudo mv iasl /usr/local/bin
There's no "make install", so you need to use last two lines to put the binary in place.


2. Get the sources

Download latest Xen from repository into your compilation directory.
hg clone http://xenbits.xensource.com/xen-unstable.hg
To update the sources later, use:
cd ~/src/xen-unstable.hg
hg pull
hg update



3. Compile hypervisor and tools

cd xen-unstable.hg
make xen
make tools
Do not use "make all" or you'll also get another kernel and docs (which require TeX and take ages to compile).

4. Create packages

Now you're supposed to to type "make install". That would put the compiled files into right places, but without any traces in your package system and without easy way to uninstall. There's a "make uninstall" target, but not guaranteed to work. So I decided to make a primitive .deb with checkinstall. It won't have all the features of a real deb package: proper dependency information, pre/post install scripts etc. But it works.
sudo checkinstall make install-xen
sudo checkinstall make install-tools
Checkinstall will ask you a few questions. Set version number to 3.5 (anything numeric will do, but autodetected unstable.hg won't). Set the package name and "provides" to "xen-hypervisor" for the first package, "xen-utils" (not xen-tools!) for the second.


5. Install packages

cd ~/src/xen-unstable.hg
sudo dpkg -i xen-* system_1-2_all.deb 

6. Update your Grub2 configuration

You'll need to boot Xen instead of Linux. Our primitive package won't modify Grub2 configuration. Create file /etc/grub.d/08_xen, make it executable and insert the following contents:
#!/bin/sh 

cat << EOF 
menuentry "Xen 3.5 / Ubuntu, 2.6.31.6-xen1" { 
    insmod ext2 
    set root=(hd0,1) 
    multiboot /boot/xen-3.5.gz 
    module /boot/vmlinuz-2.6.31.6-xen1 dummy=dummy dom0_mem=1024M root=/dev/sda1 ro 
    module /boot/initrd.img-2.6.31.6-xen1 
} 

EOF

Substitute root=(hd0,1) and root=/dev/sda1 with the right information (get one from /boot/grub/grub.cfg). Provide the right path for the Xen kernel you compiled with the previous Howto. Note the argument "dummy=dummy" for the Linux kernel - it's needed because some versions of Grub2 swallow the first argument. Command "insmod ext2" is also correct for ext3 and ext4.
You should also change /etc/default/grub and comment the lines starting with GRUB_HIDDEN_TIMEOUT. It'll make Grub2 display menu and wait for a few seconds. This way, it'll be easier to select another entry if the default won't boot. When you're ready, run:
update-grub

7. Run Xen daemon at boot

update-rc.d xend defaults
update-rc.d xendomains defaults

Troubleshooting

Unfortunately, chances of getting an unbootable system are high. My advice is to narrow down the problem. Try installing the Ubuntu-provided hypervisor or another kernel. Try updating and compiling again the kernel or Xen, new changes are commited every day. Search Xen mailing lists.

Wednesday, December 2, 2009

Extra Apt repositories in Ubuntu


Ubuntu contains thousands of packages in standard repositories, but some useful software is not included, usually for licensing reason. It's convenient to install other apps the same way you use for Ubuntu - with Synaptic, aptitude or whatever your favourite package manager is. That's when extra repositories are useful.


Using extra repository requires two things:

- adding a repository URL to apt's configuration - by convention, each repository gets it's own file in /etc/apt/sources.list.d

- adding a package signing key, so APT won't complain about untrusted source.

You can use GUI or command line for that, I prefer the latter. See https://help.ubuntu.com/community/Repositories/Ubuntu for instructions on using GUI.


Be warned that unofficial repositories are not supported by Ubuntu and may contain lower quality software. Although the ones below usually don't. Here are the repos I add on my machines.



MediBuntu



The single most useful repo. It contains multimedia codecs that didn't make it to official system due to licensing. Other software includes Skype and Google Earth.

echo "deb http://packages.medibuntu.org/ karmic free non-free" | sudo tee -a /etc/apt/sources.list.d/medibuntu.list
sudo apt-get update && sudo apt-get install medibuntu-keyring

The last line will warn you unverified package.


GetDeb



Large collection of various packages. Highlights: Flock browser, Cinepaint movie editor, Ubuntu Tweak.

wget -q -O- http://archive.getdeb.net/getdeb-archive.key | sudo apt-key add -
echo "deb http://archive.getdeb.net/ubuntu karmic-getdeb apps" | sudo tee -a /etc/apt/sources.list.d/getdeb.list


Tip: if you installed Flock, you might want to use Firefox plugins (not extensions - plugins are Flash Player, Java, Adobe Reader etc.) in it. Just use this two lines:

cd /usr/share/flock/plugins
sudo ln -s /usr/lib/firefox-addons/plugins/* .





VirtualBox




My choice for desktop virtual machine.

wget -q -O- http://download.virtualbox.org/virtualbox/debian/sun_vbox.asc | sudo apt-key add -
echo "deb http://download.virtualbox.org/virtualbox/debian karmic non-free" | sudo tee -a /etc/apt/sources.list.d/virtualbox.list




What's next?




After adding repositories, update your package list:

sudo apt-get update

Then you can view the new packages in Synaptic or aptitude. I always start with:

sudo aptitude install ubuntu-restricted-extras

It gives you codecs, Java plugin, Flash player and MS fonts, all with one command.

Tuesday, December 1, 2009

Experimental Xen and Ubuntu. Part 1: kernel


Xen status in Ubuntu is strange. There are packages for hypervisor and utils, there are even some addon tools. Ubuntu runs as a Xen guest flawlessly. However, there's no kernel supporting dom0 (privileged domain, you can think of it as a host operating system) in Ubuntu, which makes hypervisor useless.


Many users resolved the problem by borrowing a Xen kernel from Debian. It's also easy to download binary Xen distribution with the kernel included. But official Xen kernel is still 2.6.18. It's as old as Windows Vista! I wouldn't want to use something that ancient. Luckily, Xen maintainers provide a patch for every new kernel release - see Xen Wiki on PVOPS kernel for details. Installation is relatively easy and you can even make a deb package.


While you're at it, you can also compile the newest, shiniest Xen hypervisor and get all the exciting features. It's not as straightforward as kernel installation, but it's not a rocket science either.


This two part HOWTO guides you through the installation of the latest Xen on Ubuntu. Part 1 deals with the kernel. Part 2 is about the hypervisor and tools. You can install Ubuntu-provided binaries if you're happy with an older version and skip to Grub2 configuration.


0. Prerequisites


You'll need:
  • an hour or two
  • some experience with kernel compilation
  • a way to restore your system if it won't boot
  • compiler, development libraries, git client:


    sudo aptitude install kernel-package git-core libncurses5-dev



1. Create source directory



Prepare a directory for compilation, e.g. $HOME/src. DO NOT use /usr/src/linux, use non-system directory and don't compile as root. Note it has nothing to do with Xen, it's just the right way to compile kernel, although many people get it wrong. See Greg Kroah-Hartman's great book "Linux Kernel in a Nutshell" for details.


I'll assume you use ~/src. Substitute whatever you wish. You'll need about 1.5 GB of disk space.



2. Get the sources



cd ~/src
git clone git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git linux-2.6-xen


3. Configure the kernel - the important stuff



For convenience, I copied the standard Ubuntu kernel config to use as a base, it's in /boot/config-2.6.31-15-general. Put it in ~/src/linux-2.6-xen and rename to .config.


Go to your new kernel source directory and use "make menuconfig" or your preferred method of kernel configuration. You only really need one change:
Processor type and features ---> Paravirtualized guest support ---> Enable Xen privileged domain support


Another modification you might want is "Local version" from "General setup". Add something like "-xen1". This way if you need another try, you'll get a package with a different name.



4. Configure the kernel - the unimportant tweaks


While you're at it, you can also tweak some features for better performance. Some quick modifications:
  • Set the processor type to exact type you have instead of a generic one.
  • Disable all setting with debugging, profiling or probe in their name (especially from "Processor type and features" and "Kernel hacking").
  • Disable unusual hardware from "Processor type and features". That goes directly into the kernel, so reducing clutter here might help.
  • I don't bother with the drivers. They go into modules anyway and have no impact on your runtime performance, they onlymake your kernel compilation last longer. I'd rather have my computer spend extra 30 minutes compiling then have myself spend 30 minutes turning off drivers. You can however quickly disable whole groups, like Packet Radio or Video4Linux if you're sure you don't need them.
  • From "Security options", disable SELinux and Tomoyo if you don't use it.
  • Disable all KVM options. You can't use two hypervisors at the same time anyway.


5. Compile your kernel the Debian/Ubuntu way



make-kpkg --rootcmd fakeroot --initrd kernel_image

This might be a good time to go for lunch.



6) Install your package



dpkg -i [name of your kernel package]


Try rebooting. The kernel supports Xen dom0 and domU, but it runs on real hardware as well.


Blogged with the Flock Browser