个人工具

“UbuntuHelp:XenVirtualMachine”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第2行: 第2行:
 
{{Languages|UbuntuHelp:XenVirtualMachine}}
 
{{Languages|UbuntuHelp:XenVirtualMachine}}
 
This page is mostly old junk, and the useful parts are being migrated to [http://help.ubuntu.com/community/Xen Xen].  
 
This page is mostly old junk, and the useful parts are being migrated to [http://help.ubuntu.com/community/Xen Xen].  
 
 
 
 
 
=== Using loopback-mounted-file ===
 
=== Using loopback-mounted-file ===
 
+
# Generate loopback file as sparse file (not written entirely to disk but filled on demand) (replace 'edgy.ext3' with whatever name you want for it, ie. 'system1.ext3':  
* Generate loopback file as sparse file (not written entirely to disk but filled on demand) (replace 'edgy.ext3' with whatever name you want for it, ie. 'system1.ext3':  
+
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo dd if=/dev/zero of=/usr/local/edgy.ext3 bs=1024k seek=4096 count=0 </nowiki></pre>
 
sudo dd if=/dev/zero of=/usr/local/edgy.ext3 bs=1024k seek=4096 count=0 </nowiki></pre>
 
+
# Create filesystem within (replace 'edgy.ext3' with what the name you used in step 1):  
* Create filesystem within (replace 'edgy.ext3' with what the name you used in step 1):  
+
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo mkfs.ext3 /usr/local/edgy.ext3 </nowiki></pre>
 
sudo mkfs.ext3 /usr/local/edgy.ext3 </nowiki></pre>
 
 
Mkfs will tell you that this is no block device. Since you already know that (do you?) you can tell it to create the filesystem nevertheless. (so say Yes)
 
Mkfs will tell you that this is no block device. Since you already know that (do you?) you can tell it to create the filesystem nevertheless. (so say Yes)
 
+
# Loopback mount filesystem (replace 'edgy' and 'edgy.ext3' with the name you used in step 1):  
* Loopback mount filesystem (replace 'edgy' and 'edgy.ext3' with the name you used in step 1):  
+
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo mkdir /mnt/edgy
 
sudo mkdir /mnt/edgy
 
sudo mount /usr/local/edgy.ext3 /mnt/edgy -o loop </nowiki></pre>
 
sudo mount /usr/local/edgy.ext3 /mnt/edgy -o loop </nowiki></pre>
 
+
# Install edgy base into it (replace 'edgy' with the release-name (version) of ubuntu you want (dapper, edgy, feisty, etc), replace '/mnt/edgy' with the name you used in step 1):
 
+
 
+
* Install edgy base into it (replace 'edgy' with the release-name (version) of ubuntu you want (dapper, edgy, feisty, etc), replace '/mnt/edgy' with the name you used in step 1):
+
 
32bit Host O/S & 32bit virtual host <code><nowiki> sudo debootstrap edgy /mnt/edgy </nowiki></code>
 
32bit Host O/S & 32bit virtual host <code><nowiki> sudo debootstrap edgy /mnt/edgy </nowiki></code>
 
 
64bit Host O/S & 64bit virtual host <code><nowiki> sudo debootstrap --arch amd64 edgy /mnt/edgy </nowiki></code>
 
64bit Host O/S & 64bit virtual host <code><nowiki> sudo debootstrap --arch amd64 edgy /mnt/edgy </nowiki></code>
 
+
# Give it the kernel modules (the module name depends on whether you use the desktop or server edition) (this implies you are installing the same release of ubuntu as you are currently running on the system as the host O/S, which is edgy throughout this example) (replace '/mnt/edgy' with what you used in step 1):
* Give it the kernel modules (the module name depends on whether you use the desktop or server edition) (this implies you are installing the same release of ubuntu as you are currently running on the system as the host O/S, which is edgy throughout this example) (replace '/mnt/edgy' with what you used in step 1):
+
 
32bit Host OS & 32bit Virtual host: <code><nowiki>  sudo cp -a /lib/modules/2.6.19-4-generic/ /mnt/edgy/lib/modules/ </nowiki></code>
 
32bit Host OS & 32bit Virtual host: <code><nowiki>  sudo cp -a /lib/modules/2.6.19-4-generic/ /mnt/edgy/lib/modules/ </nowiki></code>
 
 
64bit Host OS & 64bit Virtual host: <code><nowiki>  sudo cp -a /lib/modules/2.6.19-4-generic-amd64/ /mnt/edgy/lib/modules/ </nowiki></code>
 
64bit Host OS & 64bit Virtual host: <code><nowiki>  sudo cp -a /lib/modules/2.6.19-4-generic-amd64/ /mnt/edgy/lib/modules/ </nowiki></code>
 
+
# Change whatever you want to be changed before the first boot. Examples:
* Change whatever you want to be changed before the first boot. Examples:
+
 
+
 
The network example below is somewhat confusing.  Basically, whatever your Host O/S's (pre-existing) IP address is, put that in for the gateway, and make sure that the 'netmask' and 'address' put the virtual host into the same broadcast group as the host o/s (simpler example: address: 192.168.1.222 netmask: 255.255.255.0 gateway: 192.168.1.111, the 222 is the virtual host, the 111 is the host o/s's actual IP).
 
The network example below is somewhat confusing.  Basically, whatever your Host O/S's (pre-existing) IP address is, put that in for the gateway, and make sure that the 'netmask' and 'address' put the virtual host into the same broadcast group as the host o/s (simpler example: address: 192.168.1.222 netmask: 255.255.255.0 gateway: 192.168.1.111, the 222 is the virtual host, the 111 is the host o/s's actual IP).
 
 
If you followed the directions above regarding the network configuration you can run the following command:
 
If you followed the directions above regarding the network configuration you can run the following command:
 
 
<code><nowiki> sudo nano /etc/network/interfaces </nowiki></code>
 
<code><nowiki> sudo nano /etc/network/interfaces </nowiki></code>
 
 
and enter the following information
 
and enter the following information
 
 
<pre><nowiki>
 
<pre><nowiki>
 
cat /mnt/edgy/etc/network/interfaces  
 
cat /mnt/edgy/etc/network/interfaces  
 
auto lo
 
auto lo
 
iface lo inet loopback
 
iface lo inet loopback
 
 
auto eth0
 
auto eth0
 
iface eth0 inet dhcp </nowiki></pre>
 
iface eth0 inet dhcp </nowiki></pre>
 
 
otherwise do the following:
 
otherwise do the following:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
cat /mnt/edgy/etc/network/interfaces  
 
cat /mnt/edgy/etc/network/interfaces  
 
auto lo
 
auto lo
 
iface lo inet loopback
 
iface lo inet loopback
 
 
auto eth0
 
auto eth0
 
iface eth0 inet static
 
iface eth0 inet static
第65行: 第41行:
 
netmask 255.255.252.0
 
netmask 255.255.252.0
 
gateway 192.168.47.254 </nowiki></pre>
 
gateway 192.168.47.254 </nowiki></pre>
 
 
Then configure the rest of the files:
 
Then configure the rest of the files:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
cat /mnt/edgy/etc/hosts
 
cat /mnt/edgy/etc/hosts
 
127.0.0.1      localhost
 
127.0.0.1      localhost
 
127.0.1.1      edgyvm </nowiki></pre>
 
127.0.1.1      edgyvm </nowiki></pre>
 
 
<pre><nowiki>
 
<pre><nowiki>
 
cat /mnt/edgy/etc/hostname  
 
cat /mnt/edgy/etc/hostname  
 
edgyvm </nowiki></pre>
 
edgyvm </nowiki></pre>
 
 
<pre><nowiki>
 
<pre><nowiki>
 
cat /mnt/edgy/etc/fstab
 
cat /mnt/edgy/etc/fstab
第82行: 第54行:
 
/dev/hda1      /              ext3    defaults,errors=remount-ro 0      1
 
/dev/hda1      /              ext3    defaults,errors=remount-ro 0      1
 
</nowiki></pre>
 
</nowiki></pre>
 
+
# Umount the loopback partition  
* Umount the loopback partition  
+
 
<pre><nowiki>  
 
<pre><nowiki>  
 
sudo umount /mnt/edgy </nowiki></pre>
 
sudo umount /mnt/edgy </nowiki></pre>
 
+
# Configure the guest, create /etc/xen/edgy-guest.cfg  
* Configure the guest, create /etc/xen/edgy-guest.cfg  
+
 
<pre><nowiki>
 
<pre><nowiki>
 
kernel = "/boot/vmlinuz-2.6.19-4-generic"
 
kernel = "/boot/vmlinuz-2.6.19-4-generic"
第99行: 第69行:
 
root = "/dev/hda1 ro"
 
root = "/dev/hda1 ro"
 
</nowiki></pre>
 
</nowiki></pre>
 
 
''' Note: Change hda1 by sda1 if you are using some SATA or SCSI Controller '''
 
''' Note: Change hda1 by sda1 if you are using some SATA or SCSI Controller '''
 
 
Note that root points to the virtual root partition of the domU and not of dom0. It is recommended to give each domU a swap partition, in such case your cfg-file may look as follows (don't forget to add it to the /etc/fstab of the virtual host, so it mounts it on boot-up):  
 
Note that root points to the virtual root partition of the domU and not of dom0. It is recommended to give each domU a swap partition, in such case your cfg-file may look as follows (don't forget to add it to the /etc/fstab of the virtual host, so it mounts it on boot-up):  
 
<pre><nowiki>
 
<pre><nowiki>
 
disk = [ 'file:/usr/local/edgy.ext3,ioemu:hda1,w','phy:/dev/hda6,ioemu:hda2,w']</nowiki></pre>
 
disk = [ 'file:/usr/local/edgy.ext3,ioemu:hda1,w','phy:/dev/hda6,ioemu:hda2,w']</nowiki></pre>
 
+
# Now you can create your xen domain
* Now you can create your xen domain
+
 
<pre><nowiki>  
 
<pre><nowiki>  
 
sudo xm create edgy-guest.cfg </nowiki></pre>
 
sudo xm create edgy-guest.cfg </nowiki></pre>
 
+
# You can connect to the guest using the command below or any network based access that you install later on (openssh-server, vncserver, remote-X11, ...)
* You can connect to the guest using the command below or any network based access that you install later on (openssh-server, vncserver, remote-X11, ...)
+
 
<pre><nowiki>  
 
<pre><nowiki>  
 
sudo xm console edgy-guest </nowiki></pre>  
 
sudo xm console edgy-guest </nowiki></pre>  
 
 
Use '''crtl + ]''' to get out of console.
 
Use '''crtl + ]''' to get out of console.
 
 
If you logged in via '''putty''' use '''ctrl + 5''' to leave the domu-console.
 
If you logged in via '''putty''' use '''ctrl + 5''' to leave the domu-console.
 
 
 
== Hypervisor and dom0 ==
 
== Hypervisor and dom0 ==
 
'''The host for virtualized machines and the priviledged first guest'''
 
'''The host for virtualized machines and the priviledged first guest'''
 
+
# The Xen kernel packages currently do not create an initrd image when they are installed. (This will probably be changed in the future). To create an initrd image run the following command:
* The Xen kernel packages currently do not create an initrd image when they are installed. (This will probably be changed in the future). To create an initrd image run the following command:
+
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo mkinitramfs -o /boot/xen0-linux-2.6.17-6-generic-xen0.initrd.img 2.6.17-6-generic-xen0
 
sudo mkinitramfs -o /boot/xen0-linux-2.6.17-6-generic-xen0.initrd.img 2.6.17-6-generic-xen0
第129行: 第90行:
 
sudo mkinitramfs -o /boot/xen0-linux-2.6.17-6-server-xen0.initrd.img 2.6.17-6-server-xen0
 
sudo mkinitramfs -o /boot/xen0-linux-2.6.17-6-server-xen0.initrd.img 2.6.17-6-server-xen0
 
</nowiki></pre>if you are using the Ubuntu server distribution.
 
</nowiki></pre>if you are using the Ubuntu server distribution.
 
+
# Now that the kernel and initrd is installed, you have to setup grub. Add the following to your /boot/grub/menu.lst:
 
+
* Now that the kernel and initrd is installed, you have to setup grub. Add the following to your /boot/grub/menu.lst:
+
 
<pre><nowiki>
 
<pre><nowiki>
 
title XEN/2.6.17
 
title XEN/2.6.17
第141行: 第100行:
 
where xxx is the partition where your root is located. Edgy can use a new way of identifying you partitions by UUID. In this case, just use that syntax for root e.g. <code><nowiki>root=UUID=f5cf5b9a-ed1a-4d6a-a707-a606574e2b6f</nowiki></code>.  You can obtain the UUIDs of your partitions using the command <code><nowiki>blkid</nowiki></code> (found in <code><nowiki>/sbin</nowiki></code>). If you are using the server edition, please make sure you select the right terms in the module lines (xen0-linux-2.6.17-6-server-xen0...).
 
where xxx is the partition where your root is located. Edgy can use a new way of identifying you partitions by UUID. In this case, just use that syntax for root e.g. <code><nowiki>root=UUID=f5cf5b9a-ed1a-4d6a-a707-a606574e2b6f</nowiki></code>.  You can obtain the UUIDs of your partitions using the command <code><nowiki>blkid</nowiki></code> (found in <code><nowiki>/sbin</nowiki></code>). If you are using the server edition, please make sure you select the right terms in the module lines (xen0-linux-2.6.17-6-server-xen0...).
 
Note: On amd64, use xen-3.0-amd64.gz instead of xen-3.0-i386.gz
 
Note: On amd64, use xen-3.0-amd64.gz instead of xen-3.0-i386.gz
 
 
Note: kernel and modules may need to have the /boot removed from them to get this to work. ie  
 
Note: kernel and modules may need to have the /boot removed from them to get this to work. ie  
 
<pre><nowiki>
 
<pre><nowiki>
 
kernel /xen-3.0-i386.gz
 
kernel /xen-3.0-i386.gz
 
</nowiki></pre>
 
</nowiki></pre>
 
 
 
== domU ==
 
== domU ==
 
''' The guest machines running under the xen hypervisor'''
 
''' The guest machines running under the xen hypervisor'''
 
 
Xen-tools can set up Ubuntu, Debian, CentOS systems, and also any other system if you give it a proper tarball.
 
Xen-tools can set up Ubuntu, Debian, CentOS systems, and also any other system if you give it a proper tarball.
 
 
A domU guest system can be built using the same kernel image that was used for dom0.
 
A domU guest system can be built using the same kernel image that was used for dom0.
* Decide whether to use a '''loopback-mounted''' file or a '''raw partition''' for a clients filesystem.
+
# Decide whether to use a '''loopback-mounted''' file or a '''raw partition''' for a clients filesystem.
 
+
 
=== use loopback-mounted-file ===
 
=== use loopback-mounted-file ===
* In case of loopback, proceed like:
+
# In case of loopback, proceed like:
*** Generate loopback file as sparse file (not written entirely to disk but filled on demand:  
+
## Generate loopback file as sparse file (not written entirely to disk but filled on demand:  
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo dd if=/dev/zero of=/usr/local/diskimage-guest.ext3 bs=1024k seek=4096 count=0 </nowiki></pre>
 
sudo dd if=/dev/zero of=/usr/local/diskimage-guest.ext3 bs=1024k seek=4096 count=0 </nowiki></pre>
*** Create filesystem within:  
+
# Create filesystem within:  
 
<pre><nowiki>  
 
<pre><nowiki>  
 
sudo mkfs.ext3 /usr/local/diskimage-guest.ext3 </nowiki></pre> Mkfs will tell you that this is no block device. Since you already know that (do you?) you can tell it to create the filesystem nevertheless.
 
sudo mkfs.ext3 /usr/local/diskimage-guest.ext3 </nowiki></pre> Mkfs will tell you that this is no block device. Since you already know that (do you?) you can tell it to create the filesystem nevertheless.
*** Loopback mount filesystem:  
+
# Loopback mount filesystem:  
 
<pre><nowiki>  
 
<pre><nowiki>  
 
sudo mount /usr/local/diskimage-guest.ext3 /mnt -o loop </nowiki></pre>
 
sudo mount /usr/local/diskimage-guest.ext3 /mnt -o loop </nowiki></pre>
*** Install debootstrap:  
+
# Install debootstrap:  
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo apt-get install debootstrap </nowiki></pre>
 
sudo apt-get install debootstrap </nowiki></pre>
*** Install edgy base into it:  
+
# Install edgy base into it:  
 
<pre><nowiki>  
 
<pre><nowiki>  
 
sudo debootstrap edgy /mnt </nowiki></pre>
 
sudo debootstrap edgy /mnt </nowiki></pre>
*** Give it the kernel modules (the module name depends on whether you use the desktop or server edition)  
+
# Give it the kernel modules (the module name depends on whether you use the desktop or server edition)  
 
<pre><nowiki>  
 
<pre><nowiki>  
 
sudo cp -a /lib/modules/2.6.17-6-generic-xen0/ /mnt/lib/modules </nowiki></pre>
 
sudo cp -a /lib/modules/2.6.17-6-generic-xen0/ /mnt/lib/modules </nowiki></pre>
*** Change whatever you want to be changed before the first boot (/mnt/etc/apt/sources.list, /mnt/etc/network/interfaces, /mnt/etc/hostname, /mnt/etc/hosts)
+
# Change whatever you want to be changed before the first boot (/mnt/etc/apt/sources.list, /mnt/etc/network/interfaces, /mnt/etc/hostname, /mnt/etc/hosts)
*** Unmount  
+
# Unmount  
 
<pre><nowiki>  
 
<pre><nowiki>  
 
sudo umount /mnt </nowiki></pre>
 
sudo umount /mnt </nowiki></pre>
*** Configure the guest, create /etc/xen/edgy-guest.cfg  
+
# Configure the guest, create /etc/xen/edgy-guest.cfg  
 
<pre><nowiki>
 
<pre><nowiki>
 
kernel = "/boot/xen0-linux-2.6.17-6-generic-xen0"
 
kernel = "/boot/xen0-linux-2.6.17-6-generic-xen0"
第194行: 第147行:
 
<pre><nowiki>
 
<pre><nowiki>
 
disk = [ 'file:/usr/local/diskimage-guest.ext3,ioemu:hda1,w','phy:/dev/hda6,ioemu:hda2,w']</nowiki></pre>
 
disk = [ 'file:/usr/local/diskimage-guest.ext3,ioemu:hda1,w','phy:/dev/hda6,ioemu:hda2,w']</nowiki></pre>
* Give it a try
+
# Give it a try
* First start xend if it is not already started:
+
# First start xend if it is not already started:
 
<pre><nowiki>
 
<pre><nowiki>
 
xend start </nowiki></pre>
 
xend start </nowiki></pre>
 
+
# Now you can create your xen domain
* Now you can create your xen domain
+
 
<pre><nowiki>  
 
<pre><nowiki>  
 
sudo xm create edgy-guest.cfg </nowiki></pre>
 
sudo xm create edgy-guest.cfg </nowiki></pre>
* You can connect to the guest using  
+
# You can connect to the guest using  
 
<pre><nowiki>  
 
<pre><nowiki>  
 
sudo xm console edgy-guest </nowiki></pre> or any network based access that you install later on (ssh or vnc or remote-X11)
 
sudo xm console edgy-guest </nowiki></pre> or any network based access that you install later on (ssh or vnc or remote-X11)
 
 
 
=== use raw partition ===
 
=== use raw partition ===
 
+
# In case of a raw partition you want to use we need to create a file-system on it first.
* In case of a raw partition you want to use we need to create a file-system on it first.
+
## If e.g /dev/hda6 is our raw unformated partiton create a ext3-filesystem:
*** If e.g /dev/hda6 is our raw unformated partiton create a ext3-filesystem:
+
 
<pre><nowiki>  
 
<pre><nowiki>  
 
mkfs -t ext3 /dev/hda6 </nowiki></pre>
 
mkfs -t ext3 /dev/hda6 </nowiki></pre>
*** The next step is to create a mountpoint and to mount it:
+
# The next step is to create a mountpoint and to mount it:
 
<pre><nowiki>  
 
<pre><nowiki>  
 
sudo mkdir /media/hda6 && sudo mount /dev/hda6 /media/hda6 </nowiki></pre>
 
sudo mkdir /media/hda6 && sudo mount /dev/hda6 /media/hda6 </nowiki></pre>
*** All what follows now is ''almost'' identical to "use loopback-mounted-file"
+
# All what follows now is ''almost'' identical to "use loopback-mounted-file"
*** Install edgy base into it:  
+
# Install edgy base into it:  
 
<pre><nowiki>  
 
<pre><nowiki>  
 
sudo debootstrap edgy /media/hda6 </nowiki></pre>
 
sudo debootstrap edgy /media/hda6 </nowiki></pre>
*** Give it the kernel modules:  
+
# Give it the kernel modules:  
 
<pre><nowiki>  
 
<pre><nowiki>  
 
sudo cp -a /lib/modules/2.6.17-6-generic-xen0/ /media/hda6/lib/modules </nowiki></pre>
 
sudo cp -a /lib/modules/2.6.17-6-generic-xen0/ /media/hda6/lib/modules </nowiki></pre>
*** Change whatever you want to be changed before the first boot (/media/hda6/etc/apt/sources.list, /media/hda6/etc/network/interfaces, /media/hda6/etc/hostname, /media/hda6/etc/hosts)
+
# Change whatever you want to be changed before the first boot (/media/hda6/etc/apt/sources.list, /media/hda6/etc/network/interfaces, /media/hda6/etc/hostname, /media/hda6/etc/hosts)
*** Unmount  
+
# Unmount  
 
<pre><nowiki>  
 
<pre><nowiki>  
 
sudo umount /media/hda6 </nowiki></pre>
 
sudo umount /media/hda6 </nowiki></pre>
*** Configure the guest, create /etc/xen/edgy-guest.cfg  
+
# Configure the guest, create /etc/xen/edgy-guest.cfg  
 
<pre><nowiki>
 
<pre><nowiki>
 
kernel = "/boot/xen0-linux-2.6.17-6-generic-xen0"
 
kernel = "/boot/xen0-linux-2.6.17-6-generic-xen0"
第241行: 第190行:
 
<pre><nowiki>
 
<pre><nowiki>
 
disk = [ 'phy:/dev/hdXX,hda1,w','phy:/dev/hdXY,hda2,w']</nowiki></pre>
 
disk = [ 'phy:/dev/hdXX,hda1,w','phy:/dev/hdXY,hda2,w']</nowiki></pre>
* Give it a try  
+
# Give it a try  
* First start xend if it is not already started:
+
# First start xend if it is not already started:
 
<pre><nowiki>
 
<pre><nowiki>
 
xend start </nowiki></pre>
 
xend start </nowiki></pre>
 
+
# Now you can create your xen domain
* Now you can create your xen domain
+
 
<pre><nowiki>  
 
<pre><nowiki>  
 
sudo xm create edgy-guest.cfg </nowiki></pre>
 
sudo xm create edgy-guest.cfg </nowiki></pre>
* You can connect to the guest using  
+
# You can connect to the guest using  
 
<pre><nowiki>  
 
<pre><nowiki>  
 
sudo xm console edgy-guest </nowiki></pre> or any network based access that you install later on (ssh or vnc or remote-X11)
 
sudo xm console edgy-guest </nowiki></pre> or any network based access that you install later on (ssh or vnc or remote-X11)
 
 
Especially if you want to set up a larger number of virtual machines, it's strongly recommended to set up LVM and use logical volumes for your virtual machines.
 
Especially if you want to set up a larger number of virtual machines, it's strongly recommended to set up LVM and use logical volumes for your virtual machines.
 
 
 
 
 
 
 
== Installing DomU w/ debootstrap ==
 
== Installing DomU w/ debootstrap ==
 
 
First, setup and configure lvm, create an ext3 and swap partition in lvm, and mount your lvm partition to /xen.
 
First, setup and configure lvm, create an ext3 and swap partition in lvm, and mount your lvm partition to /xen.
 
 
<code><nowiki>apt-get install debootstrap</nowiki></code>
 
<code><nowiki>apt-get install debootstrap</nowiki></code>
 
 
I prefer to install from CD, as it's faster. Mount your CD-Rom to /media/cdrom, and mount your future domU root partition to /xen
 
I prefer to install from CD, as it's faster. Mount your CD-Rom to /media/cdrom, and mount your future domU root partition to /xen
 
 
<pre><nowiki>
 
<pre><nowiki>
 
debootstrap dapper /xen file:/media/cdrom</nowiki></pre>
 
debootstrap dapper /xen file:/media/cdrom</nowiki></pre>
 
 
You should see lots of I: messages, and finally the prompt. Change directories to the root directory of your new filesystem.
 
You should see lots of I: messages, and finally the prompt. Change directories to the root directory of your new filesystem.
 
 
=== Xen configuration options ===
 
=== Xen configuration options ===
 
 
Using your favorite editor (back in Dom0), create /etc/xen/dom1.cfg with the following text
 
Using your favorite editor (back in Dom0), create /etc/xen/dom1.cfg with the following text
 
 
<pre><nowiki>kernel = "/boot/vmlinuz-2.6-xen"
 
<pre><nowiki>kernel = "/boot/vmlinuz-2.6-xen"
 
memory = 128
 
memory = 128
第286行: 第219行:
 
extra = "4"
 
extra = "4"
 
</nowiki></pre>
 
</nowiki></pre>
 
 
=== Create a DomU ===
 
=== Create a DomU ===
 
 
<code><nowiki>xm create dom1.cfg -c</nowiki></code>
 
<code><nowiki>xm create dom1.cfg -c</nowiki></code>
 
 
Login with root, no password (you want to change that!)
 
Login with root, no password (you want to change that!)
 
 
=== Changes Necessary on the DomU's Filesystem ===
 
=== Changes Necessary on the DomU's Filesystem ===
 
<code><nowiki>mv ./lib/tls ./lib/tls.disabled</nowiki></code>
 
<code><nowiki>mv ./lib/tls ./lib/tls.disabled</nowiki></code>
 
 
in ./etc/network/interfaces (change the relevant numbers)
 
in ./etc/network/interfaces (change the relevant numbers)
 
<pre><nowiki>auto lo
 
<pre><nowiki>auto lo
 
iface lo inet loopback
 
iface lo inet loopback
 
 
auto eth0
 
auto eth0
 
iface eth0 inet static
 
iface eth0 inet static
第309行: 第236行:
 
# dns-* options are implemented by the resolvconf package, if installed
 
# dns-* options are implemented by the resolvconf package, if installed
 
dns-nameservers 1.2.3.4 1.2.3.5</nowiki></pre>
 
dns-nameservers 1.2.3.4 1.2.3.5</nowiki></pre>
 
 
 
Copy the Dom0's sources list: <code><nowiki>cp /etc/apt/sources.list ./etc/apt/sources.list</nowiki></code> and edit them if you wish.
 
Copy the Dom0's sources list: <code><nowiki>cp /etc/apt/sources.list ./etc/apt/sources.list</nowiki></code> and edit them if you wish.
 
 
 
In ./etc/fstab
 
In ./etc/fstab
 
 
<pre><nowiki># /fstab: static file system information.
 
<pre><nowiki># /fstab: static file system information.
 
#
 
#
第322行: 第244行:
 
/dev/hda1      /              ext3    defaults,errors=remount-ro 0      1
 
/dev/hda1      /              ext3    defaults,errors=remount-ro 0      1
 
/dev/hdb1      none            swap    sw              0      0</nowiki></pre>
 
/dev/hdb1      none            swap    sw              0      0</nowiki></pre>
 
 
<code><nowiki>umount /dev/xen_lvm/dom1</nowiki></code> (we don't want two operating systems writing to the same partition!)
 
<code><nowiki>umount /dev/xen_lvm/dom1</nowiki></code> (we don't want two operating systems writing to the same partition!)
 
 
Locale setup:
 
Locale setup:
 
 
The locale isn't set up properly by default. Resolve this by:  
 
The locale isn't set up properly by default. Resolve this by:  
 
<pre><nowiki>
 
<pre><nowiki>
 
Install base packages for your language:
 
Install base packages for your language:
 
apt-get install language-pack-en-base
 
apt-get install language-pack-en-base
 
 
Install/Reconfigure localeconf via either:
 
Install/Reconfigure localeconf via either:
 
apt-get install localeconf
 
apt-get install localeconf
 
dpkg-reconfigure localeconf
 
dpkg-reconfigure localeconf
 
+
* Manage locale configuration files with debconf? -> yes
*** Manage locale configuration files with debconf? -> yes
+
* Please select the default system locale. -> Your locale. Mine is en_US ISO-8859-1 for example.
*** Please select the default system locale. -> Your locale. Mine is en_US ISO-8859-1 for example.
+
* Select the environment settings that should override the default locale.  -> Select All
*** Select the environment settings that should override the default locale.  -> Select All
+
* In the following dialogs always select what you set for your locale above.
*** In the following dialogs always select what you set for your locale above.
+
 
+
 
Install/reconfigure locales:
 
Install/reconfigure locales:
 
apt-get install locales
 
apt-get install locales
 
dpkg-reconfigure locales
 
dpkg-reconfigure locales
 
+
* Here, use the same locale you used in the localeconf setup.
*** Here, use the same locale you used in the localeconf setup.
+
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Setting up your hostname
 
Setting up your hostname
 
 
<pre><nowiki>
 
<pre><nowiki>
 
Manually edit /etc/hostname with your domU hostname.
 
Manually edit /etc/hostname with your domU hostname.
第355行: 第268行:
 
(set the 127.0.0.1 host in /etc/hosts to sync with the host in /etc/hostname)
 
(set the 127.0.0.1 host in /etc/hosts to sync with the host in /etc/hostname)
 
</nowiki></pre>
 
</nowiki></pre>
 
 
At this point you want to set up sshd, so you can log into your new virtual machine remotely!
 
At this point you want to set up sshd, so you can log into your new virtual machine remotely!
 
You are ready!
 
You are ready!
 
 
=== lib tls error ===
 
=== lib tls error ===
 
 
This should only be on older versions of Ubuntu, or on domU guests maybe?
 
This should only be on older versions of Ubuntu, or on domU guests maybe?
 
 
If you receive a large warning message during boot-up about /lib/tls, you may do one of the following:
 
If you receive a large warning message during boot-up about /lib/tls, you may do one of the following:
* <code><nowiki>mv /lib/tls /lib/tls.disabled</nowiki></code> (easy, but the issue may crop up again after an upgrade)
+
# <code><nowiki>mv /lib/tls /lib/tls.disabled</nowiki></code> (easy, but the issue may crop up again after an upgrade)
* [http://wiki.xensource.com/xenwiki/DebianTlsLibcDiversion Divert Xen using a Script] (This makes sure upgrades don't put /lib/tls back again.
+
# [http://wiki.xensource.com/xenwiki/DebianTlsLibcDiversion Divert Xen using a Script] (This makes sure upgrades don't put /lib/tls back again.
* [http://wiki.xensource.com/xenwiki/UbuntuDapperHowTo Build your own glibc] (Instructions from XenSource's Wiki)
+
# [http://wiki.xensource.com/xenwiki/UbuntuDapperHowTo Build your own glibc] (Instructions from XenSource's Wiki)
 
+
 
Note: Disabling /lib/tls gives significantly poor performance for glibc. [http://www.mail-archive.com/[email protected]/msg04668.html Find a way to install a Xen-friendly glibc]. Removing /lib/tls is disabling the thread-local storage (tls) handling features of glibc by hiding them.
 
Note: Disabling /lib/tls gives significantly poor performance for glibc. [http://www.mail-archive.com/[email protected]/msg04668.html Find a way to install a Xen-friendly glibc]. Removing /lib/tls is disabling the thread-local storage (tls) handling features of glibc by hiding them.
 
 
=== libcrypto error ===
 
=== libcrypto error ===
 
 
Probably only on older versions of Ubuntu.
 
Probably only on older versions of Ubuntu.
 
 
If when starting xend, you get the error: blktapctrl: error while loading shared libraries: libcrypto.so.0.9.7: cannot open shared object file: No such file or directory
 
If when starting xend, you get the error: blktapctrl: error while loading shared libraries: libcrypto.so.0.9.7: cannot open shared object file: No such file or directory
 
Figure out the version of libcrypto you have:
 
Figure out the version of libcrypto you have:
 
 
<code><nowiki>ls /usr/lib/libcrypto.so.*</nowiki></code>
 
<code><nowiki>ls /usr/lib/libcrypto.so.*</nowiki></code>
 
 
for example :
 
for example :
 
 
/usr/lib/libcrypto.so.0.9.8
 
/usr/lib/libcrypto.so.0.9.8
 
 
Make a symbolic link to it:
 
Make a symbolic link to it:
 
 
<code><nowiki>ln -s /usr/lib/libcrypto.so.0.9.8 /usr/lib/libcrypto.so.0.9.7</nowiki></code>
 
<code><nowiki>ln -s /usr/lib/libcrypto.so.0.9.8 /usr/lib/libcrypto.so.0.9.7</nowiki></code>
 
 
=== ethx missing ===
 
=== ethx missing ===
 
When porting a physical system to a xen image file, eth0 was missing.  Xen assigned eth2 as the first network interface.  To correct this issue comment out  eth0  in /etc/iftab. In fact this also happens if you move an installation to another hardware, because the numbers of the ethernet interfaces are bound to a specific MAC address (in the /etc/iftab table) by the ubuntu installer.
 
When porting a physical system to a xen image file, eth0 was missing.  Xen assigned eth2 as the first network interface.  To correct this issue comment out  eth0  in /etc/iftab. In fact this also happens if you move an installation to another hardware, because the numbers of the ethernet interfaces are bound to a specific MAC address (in the /etc/iftab table) by the ubuntu installer.
 
 
 
 
 
=== Windows DomU guest ===
 
=== Windows DomU guest ===
 
 
In recent processors, Intel and AMD use an extension that gives xen the ability to run guest machines that are not aware of xen at all. The processor flag is called 'VMX' and is present in alle Core2 and some D9xx processors (called 'Vanderpool' or 'VT') as well as in AM2 processors ('called 'Pacifica').
 
In recent processors, Intel and AMD use an extension that gives xen the ability to run guest machines that are not aware of xen at all. The processor flag is called 'VMX' and is present in alle Core2 and some D9xx processors (called 'Vanderpool' or 'VT') as well as in AM2 processors ('called 'Pacifica').
 
 
With the help of qemu (a processor emulation project), xen is able to provide a complete boot process from bios. The necessary package is installed by <code><nowiki> apt-get install xen-ioemu-3.0 </nowiki></code> from universe repository.
 
With the help of qemu (a processor emulation project), xen is able to provide a complete boot process from bios. The necessary package is installed by <code><nowiki> apt-get install xen-ioemu-3.0 </nowiki></code> from universe repository.
 
 
Here is an example configuration (vmx-guest.cfg) using a bootable cdrom as iso-image under /usr/local/bootimage.iso and a loopback (see above) file /usr/local/diskimage-windows for the later harddisk image:
 
Here is an example configuration (vmx-guest.cfg) using a bootable cdrom as iso-image under /usr/local/bootimage.iso and a loopback (see above) file /usr/local/diskimage-windows for the later harddisk image:
 
<pre><nowiki>
 
<pre><nowiki>
第416行: 第308行:
 
</nowiki></pre>
 
</nowiki></pre>
 
Note the new syntax for cdrom in xen 3.0.3!
 
Note the new syntax for cdrom in xen 3.0.3!
 
 
<code><nowiki>boot='d'</nowiki></code> lets the guest boot from the cd image, after finishing installation, the next boot should be launched from disk using <code><nowiki>boot='c'</nowiki></code>
 
<code><nowiki>boot='d'</nowiki></code> lets the guest boot from the cd image, after finishing installation, the next boot should be launched from disk using <code><nowiki>boot='c'</nowiki></code>
 
 
<code><nowiki>vnc=1</nowiki></code> allows us to connect to the guest after a launch using the vncviewer software:
 
<code><nowiki>vnc=1</nowiki></code> allows us to connect to the guest after a launch using the vncviewer software:
 
<pre><nowiki>
 
<pre><nowiki>
第424行: 第314行:
 
vncviewer localhost
 
vncviewer localhost
 
</nowiki></pre>
 
</nowiki></pre>
 
 
 
* You may face problems running other distributions than Edgy as domU, in such cases download the original XENsource archive and use the kernel version out of this packages:
 
* You may face problems running other distributions than Edgy as domU, in such cases download the original XENsource archive and use the kernel version out of this packages:
 
<pre><nowiki>
 
<pre><nowiki>
第437行: 第325行:
 
cd /boot
 
cd /boot
 
sudo mkinitramfs -o /boot/initrd.img-2.6.16.33-xen 2.6.16.33-xen</nowiki></pre>
 
sudo mkinitramfs -o /boot/initrd.img-2.6.16.33-xen 2.6.16.33-xen</nowiki></pre>
 
 
* You can find ready-to-go distributions at: [http://jailtime.org/]
 
* You can find ready-to-go distributions at: [http://jailtime.org/]
 
* See also [http://help.ubuntu.com/community/XenOnUbuntuBinaryInstall] for a detailed HowTo.
 
* See also [http://help.ubuntu.com/community/XenOnUbuntuBinaryInstall] for a detailed HowTo.
 
 
== Known Bugs ==
 
== Known Bugs ==
 
 
* The edgy xen kernel is reported to crash if two DomUs are started, see: https://launchpad.net/distros/ubuntu/+source/xen-source-2.6.17/+bug/71348 (believed to be fixed with the feisty xen kernels)
 
* The edgy xen kernel is reported to crash if two DomUs are started, see: https://launchpad.net/distros/ubuntu/+source/xen-source-2.6.17/+bug/71348 (believed to be fixed with the feisty xen kernels)
 
 
 
* You should disable hyperthreading in you BIOS else your Xen Kernel will reboot indefinitively.
 
* You should disable hyperthreading in you BIOS else your Xen Kernel will reboot indefinitively.
 
 
 
 
 
==== Steps ====
 
==== Steps ====
 
 
* apt-get install ssh bridge-utils gcc make patch binutils zlib1g-dev python-dev libncurses-dev x-dev libssl-dev
 
* apt-get install ssh bridge-utils gcc make patch binutils zlib1g-dev python-dev libncurses-dev x-dev libssl-dev
 
The packages x-dev and libssl-dev seem to be necessary for building the xen-tools.
 
The packages x-dev and libssl-dev seem to be necessary for building the xen-tools.
 
 
* apt-get install bin86 bcc libc6-dev-i386
 
* apt-get install bin86 bcc libc6-dev-i386
 
so you can build the hvmloader as well.
 
so you can build the hvmloader as well.
 
 
Download source distribution, unpack, cd to xen-3.0.4_1-src and do
 
Download source distribution, unpack, cd to xen-3.0.4_1-src and do
 
 
<pre><nowiki>
 
<pre><nowiki>
 
# make prep-kernels
 
# make prep-kernels
第468行: 第343行:
 
</nowiki></pre>
 
</nowiki></pre>
 
Add cciss support to kernel in order for Xen to boot successfully on this HP box:
 
Add cciss support to kernel in order for Xen to boot successfully on this HP box:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
# make linux-2.6-xen-config CONFIGMODE=menuconfig
 
# make linux-2.6-xen-config CONFIGMODE=menuconfig
第479行: 第353行:
 
</nowiki></pre>
 
</nowiki></pre>
 
Add this to /boot/grub/menu.lst
 
Add this to /boot/grub/menu.lst
 
 
<pre><nowiki>
 
<pre><nowiki>
 
title Xen 3.0.4 / XenLinux 2.6
 
title Xen 3.0.4 / XenLinux 2.6
第488行: 第361行:
 
</nowiki></pre>
 
</nowiki></pre>
 
and reboot.
 
and reboot.
 
 
 
Now, if you try to export an LVM partition as "sda1" it will fail with a boot log containing "xen_blk: can't get major 8 with name sd" followed by a guest kernel panic. This is a known problem described in the XenFaq and the solution is to  build a domU kernel w/o SCSI support. These are the steps to be done in directory xen-3.0.4_1-src/:
 
Now, if you try to export an LVM partition as "sda1" it will fail with a boot log containing "xen_blk: can't get major 8 with name sd" followed by a guest kernel panic. This is a known problem described in the XenFaq and the solution is to  build a domU kernel w/o SCSI support. These are the steps to be done in directory xen-3.0.4_1-src/:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
# make linux-2.6-xenU-config CONFIGMODE=menuconfig
 
# make linux-2.6-xenU-config CONFIGMODE=menuconfig
第499行: 第369行:
 
# cp linux-2.6.16.33-xenU/vmlinuz /boot/vmlinuz-2.6-xenU
 
# cp linux-2.6.16.33-xenU/vmlinuz /boot/vmlinuz-2.6-xenU
 
</nowiki></pre>
 
</nowiki></pre>
 
 
 
 
This config file then works for a Linux PV guest:
 
This config file then works for a Linux PV guest:
 
 
<pre><nowiki>
 
<pre><nowiki>
 
#  -*- mode: python; -*-
 
#  -*- mode: python; -*-
 
 
# Kernel image file.
 
# Kernel image file.
 
kernel = "/boot/vmlinuz-2.6-xenU"
 
kernel = "/boot/vmlinuz-2.6-xenU"
第516行: 第381行:
 
extra = "4"
 
extra = "4"
 
</nowiki></pre>
 
</nowiki></pre>
 
 
and  
 
and  
 
 
 
 
 
[[category:CategoryDocumentation]] [[category:CategoryCleanup]]
 
[[category:CategoryDocumentation]] [[category:CategoryCleanup]]
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2007年11月30日 (五) 22:34的版本

This page is mostly old junk, and the useful parts are being migrated to Xen.

Using loopback-mounted-file

  1. Generate loopback file as sparse file (not written entirely to disk but filled on demand) (replace 'edgy.ext3' with whatever name you want for it, ie. 'system1.ext3':
sudo dd if=/dev/zero of=/usr/local/edgy.ext3 bs=1024k seek=4096 count=0 
  1. Create filesystem within (replace 'edgy.ext3' with what the name you used in step 1):
sudo mkfs.ext3 /usr/local/edgy.ext3 

Mkfs will tell you that this is no block device. Since you already know that (do you?) you can tell it to create the filesystem nevertheless. (so say Yes)

  1. Loopback mount filesystem (replace 'edgy' and 'edgy.ext3' with the name you used in step 1):
sudo mkdir /mnt/edgy
sudo mount /usr/local/edgy.ext3 /mnt/edgy -o loop 
  1. Install edgy base into it (replace 'edgy' with the release-name (version) of ubuntu you want (dapper, edgy, feisty, etc), replace '/mnt/edgy' with the name you used in step 1):

32bit Host O/S & 32bit virtual host sudo debootstrap edgy /mnt/edgy 64bit Host O/S & 64bit virtual host sudo debootstrap --arch amd64 edgy /mnt/edgy

  1. Give it the kernel modules (the module name depends on whether you use the desktop or server edition) (this implies you are installing the same release of ubuntu as you are currently running on the system as the host O/S, which is edgy throughout this example) (replace '/mnt/edgy' with what you used in step 1):

32bit Host OS & 32bit Virtual host: sudo cp -a /lib/modules/2.6.19-4-generic/ /mnt/edgy/lib/modules/ 64bit Host OS & 64bit Virtual host: sudo cp -a /lib/modules/2.6.19-4-generic-amd64/ /mnt/edgy/lib/modules/

  1. Change whatever you want to be changed before the first boot. Examples:

The network example below is somewhat confusing. Basically, whatever your Host O/S's (pre-existing) IP address is, put that in for the gateway, and make sure that the 'netmask' and 'address' put the virtual host into the same broadcast group as the host o/s (simpler example: address: 192.168.1.222 netmask: 255.255.255.0 gateway: 192.168.1.111, the 222 is the virtual host, the 111 is the host o/s's actual IP). If you followed the directions above regarding the network configuration you can run the following command: sudo nano /etc/network/interfaces and enter the following information

cat /mnt/edgy/etc/network/interfaces 
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp 

otherwise do the following:

cat /mnt/edgy/etc/network/interfaces 
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.44.247
netmask 255.255.252.0
gateway 192.168.47.254 

Then configure the rest of the files:

cat /mnt/edgy/etc/hosts
127.0.0.1       localhost
127.0.1.1       edgyvm 
cat /mnt/edgy/etc/hostname 
edgyvm 
cat /mnt/edgy/etc/fstab
proc            /proc           proc    defaults        0       0
/dev/hda1       /               ext3    defaults,errors=remount-ro 0       1
  1. Umount the loopback partition
 
sudo umount /mnt/edgy 
  1. Configure the guest, create /etc/xen/edgy-guest.cfg
kernel = "/boot/vmlinuz-2.6.19-4-generic"
ramdisk = "/boot/initrd.img-2.6.19-4-generic"
builder='linux'
memory = 128
name = "edgy-guest"
vcpus = 1
vif = [ 'bridge=xenbr0' ]
disk = [ 'file:/usr/local/edgy.ext3,ioemu:hda1,w' ]
root = "/dev/hda1 ro"

Note: Change hda1 by sda1 if you are using some SATA or SCSI Controller Note that root points to the virtual root partition of the domU and not of dom0. It is recommended to give each domU a swap partition, in such case your cfg-file may look as follows (don't forget to add it to the /etc/fstab of the virtual host, so it mounts it on boot-up):

disk = [ 'file:/usr/local/edgy.ext3,ioemu:hda1,w','phy:/dev/hda6,ioemu:hda2,w']
  1. Now you can create your xen domain
 
sudo xm create edgy-guest.cfg 
  1. You can connect to the guest using the command below or any network based access that you install later on (openssh-server, vncserver, remote-X11, ...)
 
sudo xm console edgy-guest 

Use crtl + ] to get out of console. If you logged in via putty use ctrl + 5 to leave the domu-console.

Hypervisor and dom0

The host for virtualized machines and the priviledged first guest

  1. The Xen kernel packages currently do not create an initrd image when they are installed. (This will probably be changed in the future). To create an initrd image run the following command:
sudo mkinitramfs -o /boot/xen0-linux-2.6.17-6-generic-xen0.initrd.img 2.6.17-6-generic-xen0
Respectively:
sudo mkinitramfs -o /boot/xen0-linux-2.6.17-6-server-xen0.initrd.img 2.6.17-6-server-xen0
if you are using the Ubuntu server distribution.
  1. Now that the kernel and initrd is installed, you have to setup grub. Add the following to your /boot/grub/menu.lst:
title XEN/2.6.17
root (hd0,0)
kernel /boot/xen-3.0-i386-pae.gz
module /boot/xen0-linux-2.6.17-6-generic-xen0 root=/dev/xxx ro
module /boot/xen0-linux-2.6.17-6-generic-xen0.initrd.img

where xxx is the partition where your root is located. Edgy can use a new way of identifying you partitions by UUID. In this case, just use that syntax for root e.g. root=UUID=f5cf5b9a-ed1a-4d6a-a707-a606574e2b6f. You can obtain the UUIDs of your partitions using the command blkid (found in /sbin). If you are using the server edition, please make sure you select the right terms in the module lines (xen0-linux-2.6.17-6-server-xen0...). Note: On amd64, use xen-3.0-amd64.gz instead of xen-3.0-i386.gz Note: kernel and modules may need to have the /boot removed from them to get this to work. ie

kernel /xen-3.0-i386.gz

domU

The guest machines running under the xen hypervisor Xen-tools can set up Ubuntu, Debian, CentOS systems, and also any other system if you give it a proper tarball. A domU guest system can be built using the same kernel image that was used for dom0.

  1. Decide whether to use a loopback-mounted file or a raw partition for a clients filesystem.

use loopback-mounted-file

  1. In case of loopback, proceed like:
    1. Generate loopback file as sparse file (not written entirely to disk but filled on demand:
sudo dd if=/dev/zero of=/usr/local/diskimage-guest.ext3 bs=1024k seek=4096 count=0 
  1. Create filesystem within:
 
sudo mkfs.ext3 /usr/local/diskimage-guest.ext3 
Mkfs will tell you that this is no block device. Since you already know that (do you?) you can tell it to create the filesystem nevertheless.
  1. Loopback mount filesystem:
 
sudo mount /usr/local/diskimage-guest.ext3 /mnt -o loop 
  1. Install debootstrap:
sudo apt-get install debootstrap 
  1. Install edgy base into it:
 
sudo debootstrap edgy /mnt 
  1. Give it the kernel modules (the module name depends on whether you use the desktop or server edition)
 
sudo cp -a /lib/modules/2.6.17-6-generic-xen0/ /mnt/lib/modules 
  1. Change whatever you want to be changed before the first boot (/mnt/etc/apt/sources.list, /mnt/etc/network/interfaces, /mnt/etc/hostname, /mnt/etc/hosts)
  2. Unmount
 
sudo umount /mnt 
  1. Configure the guest, create /etc/xen/edgy-guest.cfg
kernel = "/boot/xen0-linux-2.6.17-6-generic-xen0"
ramdisk = "/boot/xen0-linux-2.6.17-6-generic-xen0.initrd.img"
builder='linux'
memory = 128
name = "edgy-guest"
vcpus = 1
vif = [ 'bridge=xenbr0' ]
disk = [ 'file:/usr/local/diskimage-guest.ext3,ioemu:hda1,w' ]
root = "/dev/hda1 ro"
Note that root points to the virtual root partition of the domU and not of dom0. It is recommended to give each domU a swap partition, in such case your cfg-file may look as follows:
disk = [ 'file:/usr/local/diskimage-guest.ext3,ioemu:hda1,w','phy:/dev/hda6,ioemu:hda2,w']
  1. Give it a try
  2. First start xend if it is not already started:
xend start 
  1. Now you can create your xen domain
 
sudo xm create edgy-guest.cfg 
  1. You can connect to the guest using
 
sudo xm console edgy-guest 
or any network based access that you install later on (ssh or vnc or remote-X11)

use raw partition

  1. In case of a raw partition you want to use we need to create a file-system on it first.
    1. If e.g /dev/hda6 is our raw unformated partiton create a ext3-filesystem:
 
mkfs -t ext3 /dev/hda6 
  1. The next step is to create a mountpoint and to mount it:
 
sudo mkdir /media/hda6 && sudo mount /dev/hda6 /media/hda6 
  1. All what follows now is almost identical to "use loopback-mounted-file"
  2. Install edgy base into it:
 
sudo debootstrap edgy /media/hda6 
  1. Give it the kernel modules:
 
sudo cp -a /lib/modules/2.6.17-6-generic-xen0/ /media/hda6/lib/modules 
  1. Change whatever you want to be changed before the first boot (/media/hda6/etc/apt/sources.list, /media/hda6/etc/network/interfaces, /media/hda6/etc/hostname, /media/hda6/etc/hosts)
  2. Unmount
 
sudo umount /media/hda6 
  1. Configure the guest, create /etc/xen/edgy-guest.cfg
kernel = "/boot/xen0-linux-2.6.17-6-generic-xen0"
ramdisk = "/boot/xen0-linux-2.6.17-6-generic-xen0.initrd.img"
builder='linux'
memory = 128
name = "edgy-guest"
vcpus = 1
vif = [ 'bridge=xenbr0' ]
disk = [ 'phy:/dev/hdX,hda1,w' ]
root = "/dev/hda1 ro"
Note that root points to the virtual root partition of the domU and not of dom0. It is recommended to give each domU a swap partition, in such case your cfg-file may look as follows:
disk = [ 'phy:/dev/hdXX,hda1,w','phy:/dev/hdXY,hda2,w']
  1. Give it a try
  2. First start xend if it is not already started:
xend start 
  1. Now you can create your xen domain
 
sudo xm create edgy-guest.cfg 
  1. You can connect to the guest using
 
sudo xm console edgy-guest 
or any network based access that you install later on (ssh or vnc or remote-X11)

Especially if you want to set up a larger number of virtual machines, it's strongly recommended to set up LVM and use logical volumes for your virtual machines.

Installing DomU w/ debootstrap

First, setup and configure lvm, create an ext3 and swap partition in lvm, and mount your lvm partition to /xen. apt-get install debootstrap I prefer to install from CD, as it's faster. Mount your CD-Rom to /media/cdrom, and mount your future domU root partition to /xen

debootstrap dapper /xen file:/media/cdrom

You should see lots of I: messages, and finally the prompt. Change directories to the root directory of your new filesystem.

Xen configuration options

Using your favorite editor (back in Dom0), create /etc/xen/dom1.cfg with the following text

kernel = "/boot/vmlinuz-2.6-xen"
memory = 128
name = "dom1"
vif = [ '' ]
dhcp = "dhcp"
disk = ['phy:/dev/xen_lvm/dom1,hda1,w','phy:/dev/xen_lvm/dom1_swap,hdb1,w']
root = "/dev/hda1 ro"
extra = "4"

Create a DomU

xm create dom1.cfg -c Login with root, no password (you want to change that!)

Changes Necessary on the DomU's Filesystem

mv ./lib/tls ./lib/tls.disabled in ./etc/network/interfaces (change the relevant numbers)

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.3.101
netmask 255.255.255.0
network 192.168.3.0
broadcast 192.168.3.255
gateway 192.168.3.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 1.2.3.4 1.2.3.5

Copy the Dom0's sources list: cp /etc/apt/sources.list ./etc/apt/sources.list and edit them if you wish. In ./etc/fstab

# /fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
/dev/hda1       /               ext3    defaults,errors=remount-ro 0       1
/dev/hdb1       none            swap    sw              0       0

umount /dev/xen_lvm/dom1 (we don't want two operating systems writing to the same partition!) Locale setup: The locale isn't set up properly by default. Resolve this by:

Install base packages for your language:
apt-get install language-pack-en-base
Install/Reconfigure localeconf via either:
apt-get install localeconf
dpkg-reconfigure localeconf
* Manage locale configuration files with debconf? -> yes
* Please select the default system locale. -> Your locale. Mine is en_US ISO-8859-1 for example.
* Select the environment settings that should override the default locale.  -> Select All
* In the following dialogs always select what you set for your locale above.
Install/reconfigure locales:
apt-get install locales
dpkg-reconfigure locales
* Here, use the same locale you used in the localeconf setup.

Setting up your hostname

Manually edit /etc/hostname with your domU hostname.
Manually edit /etc/hosts (If you used debootstrap, you need to set this file up from scratch.)
(set the 127.0.0.1 host in /etc/hosts to sync with the host in /etc/hostname)

At this point you want to set up sshd, so you can log into your new virtual machine remotely! You are ready!

lib tls error

This should only be on older versions of Ubuntu, or on domU guests maybe? If you receive a large warning message during boot-up about /lib/tls, you may do one of the following:

  1. mv /lib/tls /lib/tls.disabled (easy, but the issue may crop up again after an upgrade)
  2. Divert Xen using a Script (This makes sure upgrades don't put /lib/tls back again.
  3. Build your own glibc (Instructions from XenSource's Wiki)

Note: Disabling /lib/tls gives significantly poor performance for glibc. Find a way to install a Xen-friendly glibc. Removing /lib/tls is disabling the thread-local storage (tls) handling features of glibc by hiding them.

libcrypto error

Probably only on older versions of Ubuntu. If when starting xend, you get the error: blktapctrl: error while loading shared libraries: libcrypto.so.0.9.7: cannot open shared object file: No such file or directory Figure out the version of libcrypto you have: ls /usr/lib/libcrypto.so.* for example : /usr/lib/libcrypto.so.0.9.8 Make a symbolic link to it: ln -s /usr/lib/libcrypto.so.0.9.8 /usr/lib/libcrypto.so.0.9.7

ethx missing

When porting a physical system to a xen image file, eth0 was missing. Xen assigned eth2 as the first network interface. To correct this issue comment out eth0 in /etc/iftab. In fact this also happens if you move an installation to another hardware, because the numbers of the ethernet interfaces are bound to a specific MAC address (in the /etc/iftab table) by the ubuntu installer.

Windows DomU guest

In recent processors, Intel and AMD use an extension that gives xen the ability to run guest machines that are not aware of xen at all. The processor flag is called 'VMX' and is present in alle Core2 and some D9xx processors (called 'Vanderpool' or 'VT') as well as in AM2 processors ('called 'Pacifica'). With the help of qemu (a processor emulation project), xen is able to provide a complete boot process from bios. The necessary package is installed by apt-get install xen-ioemu-3.0 from universe repository. Here is an example configuration (vmx-guest.cfg) using a bootable cdrom as iso-image under /usr/local/bootimage.iso and a loopback (see above) file /usr/local/diskimage-windows for the later harddisk image:

kernel = "/usr/lib/xen-ioemu-3.0/boot/hvmloader"
builder='hvm'
memory = 384
name = "vmx-guest"
vcpus=1
vif = [ 'bridge=xenbr0' ]
disk = ['file:/usr/local/diskimage-windows,ioemu:hda,w','file:/usr/local/bootimage.iso,hdc:cdrom,r']
device_model ='/usr/lib/xen-ioemu-3.0/bin/qemu-dm'
boot='d'
vnc=1
vncviewer=1
serial='pty'
ne2000=0

Note the new syntax for cdrom in xen 3.0.3! boot='d' lets the guest boot from the cd image, after finishing installation, the next boot should be launched from disk using boot='c' vnc=1 allows us to connect to the guest after a launch using the vncviewer software:

xm create vmx-guest.cfg
vncviewer localhost
  • You may face problems running other distributions than Edgy as domU, in such cases download the original XENsource archive and use the kernel version out of this packages:
wget http://bits.xensource.com/oss-xen/release/3.0.4-1/bin.tgz/xen-3.0.4_1-install-x86_32p.tgz
tar zvfx xen-3.0.4_1-install-x86_32p.tgz
cd dist
sudo ./install.sh
  • If you need a ramdisk, remember to create one with mkinitramfs before:
sudo depmod -v 2.6.16.33-xen
cd /boot
sudo mkinitramfs -o /boot/initrd.img-2.6.16.33-xen 2.6.16.33-xen
  • You can find ready-to-go distributions at: [1]
  • See also [2] for a detailed HowTo.

Known Bugs

Steps

  • apt-get install ssh bridge-utils gcc make patch binutils zlib1g-dev python-dev libncurses-dev x-dev libssl-dev

The packages x-dev and libssl-dev seem to be necessary for building the xen-tools.

  • apt-get install bin86 bcc libc6-dev-i386

so you can build the hvmloader as well. Download source distribution, unpack, cd to xen-3.0.4_1-src and do

# make prep-kernels
# pico linux-2.6.16.33-xen/Makefile
Add -fno-stack-protector to CFLAGS in the makefile above (I added it to line 343) - thanks to Peter Fokkinga for the tip.
# make dist

Add cciss support to kernel in order for Xen to boot successfully on this HP box:

# make linux-2.6-xen-config CONFIGMODE=menuconfig
check "Device Drivers -> SCSI device support -> SCSI device support" - link statically.
check "Device Drivers -> SCSI device support -> SCSI disk support" - link statically.
check "Device Drivers -> SCSI device support -> SCSI generic support" - link statically.
check "Device Drivers -> Block devices - >Compaq Smart Array 5xxx support" - link statically.
# make linux-2.6-xen-build
# make install

Add this to /boot/grub/menu.lst

title Xen 3.0.4 / XenLinux 2.6
kernel /boot/xen-3.0.gz console=vga
module /boot/vmlinuz-2.6-xen root=/dev/cciss/c0d0p1 ro console=tty0
savedefault
boot

and reboot. Now, if you try to export an LVM partition as "sda1" it will fail with a boot log containing "xen_blk: can't get major 8 with name sd" followed by a guest kernel panic. This is a known problem described in the XenFaq and the solution is to build a domU kernel w/o SCSI support. These are the steps to be done in directory xen-3.0.4_1-src/:

# make linux-2.6-xenU-config CONFIGMODE=menuconfig
UNcheck "Device Drivers -> SCSI device support -> SCSI device support" completely
remember to edit ...xenU/Makefile to get a no-stack-protection compile.
# make linux-2.6-xenU-build
# cp linux-2.6.16.33-xenU/vmlinuz /boot/vmlinuz-2.6-xenU

This config file then works for a Linux PV guest:

#  -*- mode: python; -*-
# Kernel image file.
kernel = "/boot/vmlinuz-2.6-xenU"
memory = 64
name = "debian1"
vif = [ '' ]
disk = [ 'phy:vm-disks/debian1,sda1,w', 'phy:vm-disks/debian1-swap,sda2,w' ]
root = "/dev/sda1 ro"
extra = "4"

and