<?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; virtualization</title>
	<atom:link href="http://www.brandonturner.net/blog/tag/virtualization/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>Convert an existing Windows installation to a Xen guest</title>
		<link>http://www.brandonturner.net/blog/2010/01/convert-windows-to-xen-guest/</link>
		<comments>http://www.brandonturner.net/blog/2010/01/convert-windows-to-xen-guest/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 02:53:44 +0000</pubDate>
		<dc:creator>Brandon</dc:creator>
				<category><![CDATA[Server Admin]]></category>
		<category><![CDATA[virtualization]]></category>
		<category><![CDATA[xen]]></category>

		<guid isPermaLink="false">http://www.brandonturner.net/blog/?p=524</guid>
		<description><![CDATA[I&#8217;ve been dual booting Linux and Windows for as long as I&#8217;ve run Linux on the desktop. Recently I installed Xen on Ubuntu and subsequently decided to port my old Windows bare-metal install to a Xen domU. Running Windows as a Xen domU has several advantages, the most obvious being the ability to access Windows [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been dual booting Linux and Windows for as long as I&#8217;ve run Linux on the desktop.  Recently I installed <a href="http://www.brandonturner.net/blog/2010/01/install-xen-ubuntu/">Xen on Ubuntu</a> and subsequently decided to port my old Windows bare-metal install to a Xen domU.</p>
<p>Running Windows as a Xen domU has several advantages, the most obvious being the ability to access Windows while running Linux.  Additionally, you can take advantage of features such as domain migration, save/restore and LVM snapshots.</p>
<p>In this article, I&#8217;ll walk through how I converted my existing Windows XP Professional bare-metal (normal) install to a Xen guest (domU).  In my setup, the Xen dom0 is running on an LVM volume on a separate physical disk from the original Windows installation.  I will show you how to move the original Windows installation to a LVM logical volume.  You will need a retail or volume Windows license.  Xen emulates different hardware that will cause you to have to reactivate Windows.  An OEM license is not allowed to move hardware.  While I&#8217;d argue the physical hardware is still the same, I&#8217;m sure there is some definition that says otherwise <img src='http://www.brandonturner.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .  Finally, I converted a Windows XP installation, but the same procedure should work with any NTFS-based Windows installation (Vista, 7, Server 2003, Server 2008).</p>
<p>One thing before we get started:  If you plan on following these directions please back up first!  You&#8217;ll be partitioning volumes, copying partitions, etc.  One slip of the finger and you can wipe your entire system.  So be careful and back up!</p>
<p><a name="windows-disk-layout"></a></p>
<h4>Windows Disk Layout</h4>
<p>Before we begin, let&#8217;s discuss the layout of a typical Windows hard drive.  The table below shows a hard drive with a single NTFS partition.</p>
<table>
<tr>
<th>Start Sector</th>
<th>End Sector</th>
<th>Start Cylinder</th>
<th>End Cylinder</th>
<th>Description</th>
</tr>
<tr>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td><a href="http://en.wikipedia.org/wiki/Master_boot_record">Master Boot Record</a></tr>
<tr>
<td>63</td>
<td>x</td>
<td>1</td>
<td>Total cylinders &#8211; 1</td>
<td>NTFS Volume</td>
</tr>
</table>
<p>In order to boot Windows, three conditions concerning the NTFS partition must be met:</p>
<ol>
<li>The starting sector must be encoded in the partition&#8217;s volume boot sector at address 0x1c</li>
<li>The partition should not occupy the last disk cylinder.  This is not always true, but in some cases occupying the last cylinder can cause a BSOD.</li>
<li>The partition must be marked bootable
</ol>
<p>Keep this in mind for now.  We will see how it affects us later.</p>
<p><a name="xen-vbd"></a></p>
<h4>Set up Xen Virtual Block Device (VBD)</h4>
<p>In a paravirtualized Linux guest, Xen acts as a bootloader by assigning virtual block devices and starting the kernel.  In an HVM domain such as Windows we need a bootloader to start the domain.  I chose to use the use the default bootloader that comes Windows XP.</p>
<p>Bootloaders such as Grub and the Windows bootloader are stored in the Master Boot Record of a physical disk.  In order to emulate this in our Xen guest we will create a VBD that represents a physical disk.</p>
<p>Xen has several options for VBDs.  I&#8217;m using an LVM-backed VBD as it is slightly faster than a file-based VBD and allows me to take LVM snapshots.  Creating a logical volume is easy, but first we must determine what size to make it.</p>
<p>To meet the criteria in the <a href="#windows-disk-layout">previous section</a> for booting Windows, we need to have two disk cylinders more than are required for our NTFS partition.  To simplify this, just create a logical volume 25MB larger than your Windows&#8217; NTFS partition.</p>
<div class="prompt">
<span class="comment"># Create logical volume for our 50GB NTFS partition:</span><br />
<span class="comment"># &nbsp;&nbsp;50 * 1024 + 25 = 51225 MB</span><br />
$ <span class="cmd">sudo lvcreate -nwin_hda -L51225M vg</span>
</div>
<p><a name="partition-logical-volume"></a></p>
<h4>Partition Logical Volume</h4>
<p>Now we need to partition the logical volume we just created.  Why do we need to partition a partition?  Remember that the logical volume in dom0 represents a physical disk in domU.  We need to partition this virtual disk, add a MBR and clone our NTFS volume.  Luckily, everything in Linux behaves like a file so we will have no problems partitioning our logical volume.</p>
<div class="prompt">
<p>$ <span class="cmd">sudo fdisk /dev/vg/win_hda</span></p>
<p>Command (m for help): <span class="cmd">n</span><br />
Command action<br />
&nbsp;&nbsp;e  extended<br />
&nbsp;&nbsp;p  primary partition (1-4)<br />
<span class="cmd">p</span><br />
Partition number (1-4): <span class="cmd">1</span><br />
First cylinder (1-6530, default 1): <span class="cmd">1</span><br />
<span style="color: red;">Last cylinder should be one less than total cylinders:</span><br />
Last cylinder, +cylinders or +size{K,M,G} (1-6530, default 6530): <span class="cmd">6529</span></p>
<p>Command (m for help): <span class="cmd">a</span><br />
Partition number (1-4): <span class="cmd">1</span></p>
<p>Command (m for help): <span class="cmd">t</span><br />
Selected partition 1<br />
Hex code (type L to list codes): <span class="cmd">7</span><br />
Changed system type of partition 1 to 7 (HPFS/NTFS)</p>
<p>Command (m for help): <span class="cmd">w</span>
</div>
<p><a name="clone-ntfs-partition"></a></p>
<h4>Clone NTFS Partition</h4>
<p>Now it is time to copy our NTFS partition.  The simplest way to do this is by using <code>dd</code>.  </p>
<div class="prompt">
<span class="comment"># We offset the destination so that our NTFS partition starts at the beginning of the first cylinder</span><br />
$ <span class="cmd">sudo dd bs=512 if=/dev/sdc1 of=/dev/vg/win_hda seek=63</span>
</div>
<p>This could take a while.  Don&#8217;t worry if you don&#8217;t see anything, <code>dd</code> doesn&#8217;t display progress as it works.  If you are like me and would rather know how the clone is progressing, install <a href="http://dcfldd.sourceforge.net/">dcfldd</a> and use that instead.</p>
<p><a name="modify-ntfs-boot-sector"></a></p>
<h4>Modify NTFS Boot Sector</h4>
<p>If your original NTFS partition was the first partition on the disk, you may be able to skip this step, but it won&#8217;t hurt to check.</p>
<p>To satisfy the first condition in the <a href="#windows-disk-layout">Windows Disk Layout</a> section above, we need to make sure the starting disk sector is encoded in the NTFS boot sector of our NTFS partition.  If you have followed the previous steps, your starting sector is 63.  To verify this:</p>
<div class="prompt">
$ <span class="cmd">sudo fdisk -l -u /dev/vg/win_vma</span><br />
Disk /dev/vg/win_hda: 53.7 GB, 53716451328 bytes<br />
255 heads, 63 sectors/track, 6530 cylinders, total 104914944 sectors<br />
Units = sectors of 1 * 512 = 512 bytes<br />
Disk identifier: 0xe3f4562c</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Device Boot &nbsp;Start &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Blocks &nbsp;&nbsp;Id &nbsp;System<br />
/dev/vg1/win_hda1 &nbsp;&nbsp;* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>63</b> &nbsp;&nbsp;104888384 &nbsp;&nbsp;&nbsp;52444161 &nbsp;&nbsp;&nbsp;7 &nbsp;HPFS/NTFS
</div>
<p>You will need to convert the starting address to hexadecimal and rearrange it:</p>
<ol>
<li>Convert 63 to hex: 0x3F</li>
<li>Left pad with 0s so you have 8 hexadecimal digits: 0x0000003F</li>
<li>Rearrange pairs so AB CD EF GH becomes GH EF CD AB: 0x3F000000</li>
</ol>
<p>Now using <code><a href="http://rigaux.org/hexedit.html">hexedit</a></code>, or the binary file editor of your choice, ensure the starting sector address is inserted into the NTFS partition&#8217;s boot sector at address 0x1C (remember the NTFS partition starts at sector 63, or byte address 0x7E00).</p>
<div class="prompt">
$ <span class="cmd">sudo hexedit /dev/vg/win_hda</span>
</div>
<p>Move to position 0x7E1C (0x7E00 + 0x001C).  In hexedit this is done by pressing <code>Enter</code>, typing <code>7E1C</code>, and pressing <code>Enter</code> again.  Now make sure the 4 bytes at 0x7E1C equal the rearranged pairs above.  If not, type the pairs.  To save and exit: <code>Ctrl+X</code>.  To exit without saving: <code>Ctrl+C</code>.</p>
<p><a name="fix-mbr"></a></p>
<h4>Fix Master Boot Record</h4>
<p>At this point you have a virtual disk (<code>/dev/vg/win_hda</code>) with a single NTFS partition containing your Windows installation.  Unfortunately it is not quite ready because there is no bootloader in in the MBR.  We can use the <a href="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/bootcons_fixmbr.mspx?mfr=true"><code>fixmbr</code></a> command on the Windows XP CD to install a bootloader into our virtual disk&#8217;s MBR.</p>
<p>First, we need to create a configuration file for our Windows Xen guest.  Here is mine, YMMV:</p>
<pre class="brush: plain;">
kernel = &quot;/usr/lib/xen/boot/hvmloader&quot;
builder = 'hvm'

memory = 1024

name = &quot;winxp&quot;
vif = []

disk = [
    'phy:/dev/vg/win_hda,hda,w',
    'phy:/dev/cdrom,hdc:cdrom,r'
]

device_model = '/usr/lib/xen/bin/qemu-dm'
boot=&quot;dc&quot;
vnc=1
</pre>
<p>Place your Windows XP CD in your CD drive.  You will boot your Xen guest using this CD to access the <code>fixmbr</code> command.</p>
<div class="prompt">
$ <span class="cmd">sudo xm create /etc/xen/winxp.cfg</span>
</div>
<p>Boot from CD:<br />
<div id="attachment_568" class="wp-caption aligncenter" style="width: 590px"><a href="http://www.brandonturner.net/blog/wp-content/uploads/2010/01/boot-from-cd.png"><img src="http://www.brandonturner.net/blog/wp-content/uploads/2010/01/boot-from-cd.png" alt="Press any key to boot from CD" title="Boot from CD" width="580" height="322" class="size-full wp-image-568" /></a><p class="wp-caption-text">Press any key to boot from CD</p></div></p>
<p>At the Welcome to Setup screen, press <b>R</b> to enter the recovery console:<br />
<div id="attachment_571" class="wp-caption aligncenter" style="width: 590px"><a href="http://www.brandonturner.net/blog/wp-content/uploads/2010/01/enter-recovery-console.png"><img src="http://www.brandonturner.net/blog/wp-content/uploads/2010/01/enter-recovery-console.png" alt="Press R to enter the recovery console" title="Enter Recovery Console" width="580" height="319" class="size-full wp-image-571" /></a><p class="wp-caption-text">Press R to enter the recovery console</p></div></p>
<p>Log on to your Windows partition:<br />
<div id="attachment_572" class="wp-caption aligncenter" style="width: 590px"><a href="http://www.brandonturner.net/blog/wp-content/uploads/2010/01/login-windows-partition.png"><img src="http://www.brandonturner.net/blog/wp-content/uploads/2010/01/login-windows-partition.png" alt="Select your Windows partition" title="Log in to Windows Partition" width="580" height="319" class="size-full wp-image-572" /></a><p class="wp-caption-text">Log in to your Windows partition</p></div></p>
<p>Use the <code>fixmbr</code> command to add the Windows bootloader to the MBR.  Confirm the ominous warning message as you know what you are doing.<br />
<div id="attachment_580" class="wp-caption aligncenter" style="width: 590px"><a href="http://www.brandonturner.net/blog/wp-content/uploads/2010/01/fixmbr.png"><img src="http://www.brandonturner.net/blog/wp-content/uploads/2010/01/fixmbr.png" alt="Running fixmbr on the Xen virtual disk" title="fixmbr" width="580" height="238" class="size-full wp-image-580" /></a><p class="wp-caption-text">Running fixmbr on the Xen virtual disk</p></div></p>
<p><a name="boot-windows"></a></p>
<h4>Boot Windows</h4>
<p>At this point your Windows Xen guest domainU is ready to boot.  Simply reboot the domain:</p>
<div class="prompt">
$ <span class="cmd">sudo xm reboot winxp</span>
</div>
<p>Once your Windows guest boots it should recognize new hardware and want to reboot.  You will probably have to reactivate Windows at some point as well.  You should probably install the <a href="http://wiki.xensource.com/xenwiki/XenWindowsGplPv">Xen GPLPV</a> drivers as soon as possible.  It is probably also a good idea to remove drivers from your old hardware as they are no longer needed.</p>
<p>I recommend accessing your Xen guest over the Remote Desktop Protocol using <code><a href="http://www.rdesktop.org/">rdesktop</a></code> instead of over VNC.  You&#8217;ll find your Windows is much more responsive over RDP.</p>
<p>Congratulations, you&#8217;ve ported your previous Windows installation to a Xen guest.  Though it wasn&#8217;t a point-and-click migration, it&#8217;s still faster then reinstalling Windows and all of your apps from scratch.  </p>
<p>Let me know if you found any errors or found this useful.  Enjoy your new Xen setup.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brandonturner.net/blog/2010/01/convert-windows-to-xen-guest/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<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>
