<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Brandon&#039;s Blog &#187; ubuntu</title>
	<atom:link href="http://www.brandonturner.net/blog/tag/ubuntu/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brandonturner.net/blog</link>
	<description>Random thoughts on web applications, software development and Linux</description>
	<lastBuildDate>Thu, 08 Apr 2010 01:47:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Installing Xen on Ubuntu 9.10</title>
		<link>http://www.brandonturner.net/blog/2010/01/install-xen-ubuntu/</link>
		<comments>http://www.brandonturner.net/blog/2010/01/install-xen-ubuntu/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 22:01:58 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[Server Admin]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[virtualization]]></category>
		<category><![CDATA[xen]]></category>

		<guid isPermaLink="false">http://www.brandonturner.net/blog/?p=493</guid>
		<description><![CDATA[Install Xen 3.4.2 on Ubuntu 9.10 Karmic Koala, converting an existing install to the Xen dom0. Karmic doesn't have Xen binaries but you can install from source.]]></description>
			<content:encoded><![CDATA[<p>Recently I switched to Ubuntu as the primary operating system on my desktop machine.  As part of the switch, I wanted to install Xen to virtualize some additional operating systems.  Xen provides very good performance when virtualizing Linux distributions due to <a href="http://en.wikipedia.org/wiki/Paravirtualization">paravirtualization</a>.  The latest versions can also virtualize certain unmodified guest operating systems on processors that support virtualization.</p>
<p>In a Xen setup, the Xen hypervisor runs directly on the hardware (bare-metal).  The first guest operating system (dom0) runs &#8220;on top&#8221; of Xen and has full access to the underlying hardware.  Additional guests (domU) also run on top of the Xen hypervisor, but with limited access to the underlying hardware.</p>
<p>Converting an existing Ubuntu install to a Xen dom0 install requires installing the Xen hypervisor.  In previous versions of Ubuntu this could easily be done <a href="https://help.ubuntu.com/community/Xen">using apt</a>.  Unfortunately no packages exist for Ubuntu 9.10 (Karmic Koala).  In this post I&#8217;ll describe the steps I took to install Xen from source on Karmic.  If you&#8217;d rather install via binary packages you&#8217;ll need to find a third-party repository.</p>
<h4>Install Xen hypervisor and tools</h4>
<div class="prompt">
<p><span class="comment"># In order to compile Xen, you must first install some build dependencies:</span><br />
<span class="cmd">$ sudo apt-get install bin86 bcc iasl uuid-dev libsdl-dev</span></p>
<p>$ <span class="cmd">cd /usr/src</span></p>
<p><span class="comment"># See <a href="http://www.xen.org/products/xen_source.html">http://www.xen.org/products/xen_source.html</a> for latest downloads</span><br />
$ <span class="cmd">wget <a href="http://bits.xensource.com/oss-xen/release/3.4.2/xen-3.4.2.tar.gz">http://bits.xensource.com/oss-xen/release/3.4.2/xen-3.4.2.tar.gz</a></span><br />
$ <span class="cmd">tar -xzf xen-3.4.2.tar.gz</span></p>
<p><span class="comment"># I created this small patch to adapt Xen to Ubuntu&#8217;s layout</span><br />
$ <span class="cmd">wget <a href="http://www.bltweb.net/patches/xen-3.4.2-ubuntu.patch">http://www.bltweb.net/patches/xen-3.4.2-ubuntu.patch</a></span><br />
<span class="comment"># or if you are using Xen 4.0:</span><br />
$ <span class="cmd">wget <a href="http://www.bltweb.net/patches/xen-4.0.0-ubuntu.patch">http://www.bltweb.net/patches/xen-4.0.0-ubuntu.patch</a></span></p>
<p>$ <span class="cmd">cd xen-3.4.2</span><br />
$ <span class="cmd">patch -p1 < ../xen-3.4.2-ubuntu.patch</span><br />
$ <span class="cmd">make dist-xen dist-tools dist-stubdom</span><br />
$ <span class="cmd">sudo make install-xen install-tools install-stubdom</span></p>
</div>
<h4>Install Xen Kernel Sources</h4>
<p>The stock Karmic kernel will not work when running as dom0 in Xen.  You must install a new kernel.  I chose to compile my own kernel.  Compiling a kernel is not for the faint of heart, but isn&#8217;t as hard as you might think.</p>
<p>You have two main choices when it comes to a dom0 kernel.  The Xen kernel or a dom0 <a href="http://wiki.xensource.com/xenwiki/XenParavirtOps">pv-ops kernel</a>.  Normally I would recommend using a pv-ops kernel.  The same pv-ops kernel can run on bare-metal or under the Xen hypervisor.  The pv-ops kernel is going to be the default in future versions of Xen and will most likely be included in the mainline Linux kernel soon.</p>
<p>Unfortunately, the pv-ops kernel will not work with binary graphics drivers provided by Nvidia.  Since I have an Nvidia graphics card (and want to use the binary drivers) I need to use the standard Xen kernel.  The standard Xen kernel is still version 2.6.18, however luckily Andrew Lyon maintains <a href="http://code.google.com/p/gentoo-xen-kernel/downloads/list">forward ported patches</a> for Gentoo that we can use on our Ubuntu install.</p>
<p>First things first, let&#8217;s get the kernel sources downloaded and patched:</p>
<div class="prompt">
<p>$ <span class="cmd">cd /usr/src</span></p>
<p><span class="comment"># Download the vanilla kernel sources from <a href="http://www.kernel.org/">http://www.kernel.org/</a></span><br />
$ <span class="cmd">wget <a href="http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.8.tar.bz2">http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.8.tar.bz2</a></span><br />
$ <span class="cmd">tar -xjf linux-2.6.31.8.tar.bz2</span><br />
$ <span class="cmd">mv linux-2.6.31.8 linux-2.6.31.8-xen0-amd64</span></p>
<p><span class="comment"># Download the forward ported xen patches from <a href="http://code.google.com/p/gentoo-xen-kernel/downloads/list">http://code.google.com/p/gentoo-xen-kernel/downloads/list</a></span><br />
$ <span class="cmd">wget <a href="http://gentoo-xen-kernel.googlecode.com/files/xen-patches-2.6.31-10.tar.bz2">http://gentoo-xen-kernel.googlecode.com/files/xen-patches-2.6.31-10.tar.bz2</a></span><br />
$ <span class="cmd">mkdir xenpatches-v10_2.6.31.8</span><br />
$ <span class="cmd">cd xenpatches-v10_2.6.31.8</span><br />
$ <span class="cmd">tar -xjf ../xen-patches-2.6.31-10.tar.bz2</span><br />
$ <span class="cmd">cd ../</span></p>
<p><span class="comment"># Apply the xen patches</span><br />
$ <span class="cmd">cd linux-2.6.31.8-xen0-amd64</span><br />
$ <span class="cmd">for i in `ls ../xenpatches-v10_2.6.31.8/`; do patch -p1 < ../xenpatches-v10_2.6.31.8/"$i"; done</span></p>
</div>
<p>At this point I like to modify the kernel&#8217;s &#8220;extra version&#8221; to clearly identify that this is a dom0 kernel.  To do this, modify the Makefile using your favorite text editor and change the EXTRAVERSION line to look like:</p>
<pre class="brush: bash; highlight: [4];">
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 31
EXTRAVERSION = .8-xen0-amd64
NAME = Man-Eating Seals of Antiquity
...
</pre>
<h4>Compile Xen Kernel</h4>
<p>Configuring your kernel is <i>left as an exercise for the reader</i>.  There is a ton of existing documentation on how to do this.  The easiest way to get started is to copy the configuration from the stock Ubuntu kernel and run make menuconfig.</p>
<div class="prompt">
$ <span class="cmd">cp /boot/config-2.6-31-17-generic .config</span><br />
$ <span class="cmd">make menuconfig</span>
</div>
<p>There are some options that you want to be sure you enable:</p>
<pre class="prompt">
Processor type and features --->
  [*] Enable Xen compatible kernel
Networking support --->
  Networking options --->
    &lt;*> 802.1d Ethernet Bridging
Device Drivers --->
  XEN --->
    [*] Privileged Guest (domain 0)
    &lt;M> Backend driver support
    &lt;M>   Block-device backend driver
    &lt;M>   Block-device tap backend driver
    &lt;M>   Block-device tap backend driver 2
    &lt;M>   Network-device backend driver
    &lt;M>   PCI-device backend driver
    &lt;M>   SCSI backend driver
    &lt;M>   USB backend driver
    &lt;*> Block-device frontend driver
    &lt;*> Network-device frontend driver
    &lt;M> SCSI frontend driver
    &lt;M> USB frontend driver
    &lt;*> Framebuffer-device frontend driver
    &lt;*>   Keyboard-device frontend driver
    [*] Disable serial port drivers
    &lt;*> Export Xen attributes in sysfs
        Xen version compatibility (3.3.0 and later) --->
           3.3.0 and later
</pre>
<p>Now compile and install your kernel:</p>
<div class="prompt">
<span class="comment"># To speed up the compile, set CONCURRENCY_LEVEL to one higher than the number of processor cores in your machine</span><br />
$ <span class="cmd">export CONCURRENCY_LEVEL=5</span><br />
$ <span class="cmd">make</span><br />
$ <span class="cmd">sudo make install</span><br />
$ <span class="cmd">sudo make modules_install</span></p>
<p><span class="comment"># Make an initramfs</span><br />
$ <span class="cmd">sudo mkinitramfs -o /boot/initrd.img-2.6.31.8-xen0-amd64 2.6.31.8-xen0-amd64</span>
</div>
<p>If you compiled the Xen net, block and usb backend drivers as modules, you will probably want to load them by default by adding them to your <code>/etc/modules</code> file:</p>
<pre class="brush: plain;">
# /etc/modules
...
# These modules are required for Xen DomUs to work
netbk
blkbk
usbbk
</pre>
<h4>Update Grub</h4>
<p>Most existing Xen documentation on the web refers to the first version of Grub.  Ubuntu 9.10 ships with Grub 2.  Grub 2 works great with Xen, unless you use fakeraid.  If you use fakeraid, I would suggest downgrading to Grub 1.</p>
<p>Ubuntu&#8217;s <code>update-grub</code> command won&#8217;t recognize your new Xen kernel, but you can easily modify the <code>/etc/grub.d/40_custom</code> script to manually insert it into your Grub configuration.  Here&#8217;s what my <code>40_custom</code> file looks like:</p>
<pre class="brush: bash;">
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.

menuentry &quot;Ubuntu, Xen 3.4.2 dom0 2.6.31.8-xen0-amd64&quot; {
   set quiet=1
   insmod raid
   insmod mdraid
   insmod ext2
   set root=(md1)
   search --no-floppy --fs-uuid --set 31d4873b-fed1-49d9-b37d-89d9f7a46566
   multiboot (md1)/xen-3.4.2.gz vga=gfx-1440x900x32 quiet
   module (md1)/vmlinuz-2.6.31.8-xen0-amd64 root=/dev/mapper/vg0-root root=/dev/mapper/vg0-root ro quiet splash
   module (md1)/initrd.img-2.6.31.8-xen0-amd64
}
</pre>
<p>You will need to adjust this for your system.  You can use the <code>blkid</code> command to get the UUID for your disk partitions.  You might notice that I passed the <code>root=</code> parameter twice on the <code>module</code> line.  This may be a bug somewhere in Xen or Grub but I could not get anything to work when only including this parameter once.</p>
<p>You also need to update your default operating system.  You may want to wait until after you&#8217;ve verified everything works, but eventually you should edit <code>/etc/default/grub</code>.  Mine looks like:</p>
<pre class="brush: bash; highlight: [4];">
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.

GRUB_DEFAULT=&quot;Ubuntu, Xen 3.4.2 dom0 2.6.31.8-xen0-amd64&quot;
#GRUB_DEFAULT=&quot;0&quot;
#GRUB_HIDDEN_TIMEOUT=1
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=&quot;3&quot;
GRUB_DISTRIBUTOR=`lsb_release -i -s 2&gt; /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=&quot;quiet splash&quot;
GRUB_CMDLINE_LINUX=&quot;&quot;

# The resolution used on graphical terminal
GRUB_GFXMODE=1440x900x32

# Uncomment if you don't want GRUB to pass &quot;root=UUID=xxx&quot; parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entrys
#GRUB_DISABLE_LINUX_RECOVERY=&quot;true&quot;

GRUB_DISABLE_OS_PROBER=true
</pre>
<p>Now run <code>update-grub</code>:</p>
<div class="prompt">
$ <span class="cmd">sudo update-grub</span>
</div>
<h4>Reboot</h4>
<p>Cross your fingers, it&#8217;s time to reboot into the Xen hypervisor and your new Xen kernel.  If you are lucky everything will work and you&#8217;ll soon be back to your desktop.  You may run into driver issues, in which case you&#8217;ll need to boot your original kernel and try your hand at reconfiguring and recompiling your kernel. </p>
<p>If you use Nvidia or ATI binary drivers they won&#8217;t work with the Xen kernel (yet).  Enabling these is a subject for another day, but it can be done.  For now, let&#8217;s stay focused on getting Xen fully installed and running.</p>
<p>After rebooting, you can check a couple of things:</p>
<div class="prompt">
$ <span class="cmd">uname -r</span><br />
<b>2.6.31.8-xen0-amd64</b><br />
$ <span class="cmd">sudo cat /proc/xen/capabilities</span><br />
<b>control_d</b>
</div>
<h4>Start Xen tools</h4>
<p>Once you are running the Xen hypervisor and a Xen compatible dom0 kernel, you need to start the Xen daemon.  This is done with:</p>
<div class="prompt">
$ <span class="cmd">sudo /etc/init.d/xend start</span>
</div>
<p>You can start this automatically by establishing sysvinit links with:</p>
<div class="prompt">
$ <span class="cmd">sudo update-rc.d xend start 20 2 3 4 5 . stop 80 0 1 6 .
</div>
<p>If you want Xen domUs in <code>/etc/xen/auto</code> to start automatically on boot, set the <code>xendomains</code> init script to run on boot:</p>
<div class="prompt">
$ <span class="cmd">sudo update-rc.d xendomains start 21 2 3 4 5 . stop 79 0 1 6 .
</div>
<h4>Compile a domU kernel</h4>
<p>This step is optional.  You may want to compile a kernel for use by your Linux domUs.  Many distributions can run as a domU with their stock kernel however if that doesn&#8217;t work you can configure them to use a Xen domU kernel.</p>
<p>Configuring a Xen domU kernel is similar to configuring a Xen dom0 kernel:</p>
<div class="prompt">
<p>$ <span class="cmd">cd /usr/src</span></p>
<p>$ <span class="cmd">tar -xjf linux-2.6.31.8.tar.bz2</span><br />
$ <span class="cmd">mv linux-2.6.31.8 linux-2.6.31.8-xenU-amd64</span></p>
<p><span class="comment"># Modify Makefile so EXTRAVERSION = .8-xenU-amd64</span></p>
<p>$ <span class="cmd">cp /boot/config-2.6-31-17-generic .config</span><br />
$ <span class="cmd">make menuconfig</span><br />
$ <span class="cmd">sudo make install</span><br />
$ <span class="cmd">sudo make modules_install</span>
</div>
<p>When configuring the domU kernel, you&#8217;ll want to make sure you enable:</p>
<pre class="prompt">
Processor type and features --->
  [*] Paravirtualized guest support --->
    [*] Xen guest support
Device drivers --->
  [*] Xen /dev/xen/evtchn device
  &lt;*> Xen filesystem
  [*] Create xen entries under /sys/hypervisor
</pre>
<h4>Ready for domUs</h4>
<p>Congratulations, your Ubuntu 9.10 Karmic Koala installation is now running as a domain 0 on top of the latest Xen hypervisor.  You are ready to start installing domUs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brandonturner.net/blog/2010/01/install-xen-ubuntu/feed/</wfw:commentRss>
		<slash:comments>90</slash:comments>
		</item>
	</channel>
</rss>
