个人工具

UbuntuHelp:XenVirtualMachine/XenOnUbuntuEdgy

来自Ubuntu中文

Oneleaf讨论 | 贡献2007年5月24日 (四) 14:12的版本 (新页面: {{From|https://help.ubuntu.com/community/XenVirtualMachine/XenOnUbuntuEdgy}} {{Languages|UbuntuHelp:XenVirtualMachine/XenOnUbuntuEdgy}} == Hypervisor and dom0 == '''The host for virtualiz...)

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航, 搜索

Hypervisor and dom0

The host for virtualized machines and the priviledged first guest

In previous Ubuntu releases, using Xen required building and compiling from source. Starting with Edgy Eft (6.10), this is no longer necessary. You can easily convert an existing running Ubuntu install (Edgy Eft or later) so that the Dom0 is your current setup, and you can follow on to create DomU instances as desired. These instructions are for converting your existing setup in this manner.

To install XEN on a machine running Edgy Eft or later, do the following:

  • Make sure that you are running edgy and that you have universe enabled in your /etc/apt/sources.list
  • Run the following command:
sudo apt-get install xen-hypervisor-3.0-i386 xen-image-xen0-2.6.17-6-generic-xen0 xen-utils-3.0 xen-ioemu-3.0
. If you are running a server kernel, you must change this to
sudo apt-get install xen-hypervisor-3.0-i386-pae xen-image-xen0-2.6.17-6-server-xen0 xen-utils-3.0 xen-ioemu-3.0
so that both the kernel and the hypervisor are PAE-enabled (if there is a mismatch you won't be able to boot).

Note: For amd64, use xen-hypervisor-3.0-amd64 instead of xen-hypervisor-3.0-i386

This will install the XEN hypervisor, the kernel used by the guest host and guest domains, and the userspace utilities used for working with Xen domains.

  • 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.


  • 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.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
  • Now you will have to adjust the network settings that XEN will use. The xend daemon is configured in `/etc/xen/xend-config.sxp`. Add the following line to `xend-config.sxp`:
(network-script network-bridge)
  • If you are going to use the network-bridge, you must have the bridge-utils package installed (else your bridge won't be created by the network-bridge script and you will get an error like 'Error: Device 0 (vif) could not be connected. Hotplug scripts not working.' when attempting to start your DomU). To install it, run the following command:
sudo apt-get install bridge-utils
The later domU examples assume that you use a bridged networking using device xenbr0. If installing bridge-utils doesn't fix this, try moving the file /etc/udev/xen-backend.rules to /etc/udev/rules.d/10-xen-backend.rules


domU

The guest machines running under the xen hypervisor

This chapter describes how to set up the virtual machines. You can do this by hand, but it's also possible to let xen-create-image do the hard work. It automaticaly creates the filesystem, installation and configuration files (both inside and outside the VM). See http://www.xen-tools.org/ or just install it using apt:

sudo apt-get install xen-tools

Xen-tools can set up Ubuntu, Debian, CentOS systems, and also any other system if you give it a proper tarball.

Edgy

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.

use loopback-mounted-file

  • In case of loopback, proceed like:
      • 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 
      • 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.
      • Loopback mount filesystem:
 
sudo mount /usr/local/diskimage-guest.ext3 /mnt -o loop 
      • Install debootstrap:
sudo apt-get install debootstrap 
      • Install edgy base into it:
 
sudo debootstrap edgy /mnt 
      • 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 
      • 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
 
sudo umount /mnt 
      • 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']
  • Give it a try
  • First start xend if it is not already started:
xend start 
  • Now you can create your xen domain
 
sudo xm create edgy-guest.cfg 
  • 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

  • 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:
 
mkfs -t ext3 /dev/hda6 
      • The next step is to create a mountpoint and to mount it:
 
sudo mkdir /media/hda6 && sudo mount /dev/hda6 /media/hda6 
      • All what follows now is almost identical to "use loopback-mounted-file"
      • Install edgy base into it:
 
sudo debootstrap edgy /media/hda6 
      • Give it the kernel modules:
 
sudo cp -a /lib/modules/2.6.17-6-generic-xen0/ /media/hda6/lib/modules 
      • 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
 
sudo umount /media/hda6 
      • 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']
  • Give it a try
  • First start xend if it is not already started:
xend start 
  • Now you can create your xen domain
 
sudo xm create edgy-guest.cfg 
  • 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.

Others using VMX and qemu

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

Installing other distributions as DomU

  • 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

  • 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.
  • You should disable hyperthreading in you BIOS else your Xen Kernel will reboot indefinitively.

Resources

[3] - XenSource

Related Documentation