红联Linux门户
Linux帮助

Installing Xen on ubuntu

发布时间:2007-11-20 00:34:01来源:红联作者:dhwoecv
Abstract

This guide will show you how to install Xen under Ubuntu Linux. It will also walk you through the installation and setup of several different guest operating systems.

Table of Contents(目录)

Feedback
Copyright and License
Disclaimer
Introduction
Installing and setting up Xen

Installing Ubuntu Linux
Installing the Prerequisite packages (安装需要的包)
Installing Xen onto Ubuntu Linux
Configuring the Bootloader
Creating Domain Configurations
Starting the Daemon
Installing ttyLinux

Installing other Linux Distributions(其他linux发行版)

Installing Debian Linux

Other Resources

Feedback

Comments on this Guide may be directed to Michael McCabe (<mccabemt@clarkson.edu>).
Copyright and License

This document, Installing Xen, is copyright (c) 2005 by the Clarkson Open Source Institute. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is available at http://www.gnu.org /copyleft/fdl.html.
Disclaimer

No liability for the contents of this document can be accepted. Use the concepts, examples and information at your own risk. There may be errors and inaccuracies, that could be damaging to your system. Proceed with caution, and although this is highly unlikely, the author(s) do not take any responsibility.

All copyrights are held by their by their respective owners, unless specifically noted otherwise. Use of a term in this document should not be regarded as affecting the validity of any trademark or service mark. Naming of particular products or brands should not be seen as endorsements.

Introduction(前言)

Xen is a high performance virtualization layer for X86 machines. Currently Xen is available for Linux and is currently being ported to Net BSD and Plan 9. There are Linux packages available for Fedora, and Debian Linux. Also there are plans to port Xen to the X86_64 architecture.

Installing and setting up Xen

This section will walk you through installing a Linux distribution and installing and configuring that Linux distribution. For the purposes of this document we will be using Ubuntu Linux.

Installing Ubuntu Linux(安装ubuntu基本系统)

When you install Ubuntu Linux you should do a custom-expert installation. You will not need most of the packages that are installed. Some of the packages (X Windows Packages) may even cause memory corruption and other more severe problems. To start a custom-expert installation all you'll need to do is pass custom-expert when the installation CD is booting.

Installing the Prerequisite packages(安装所需要的包)

After installing the base Ubuntu system you will need to install several other packages. Here is the list of packages that are required for Xen.(Some of these packages have already been installed)

* grub
* bridge-utils
* iproute
* python
* python-twisted
* gcc
* libcurl2
* libcurl2-dev
* zlib1g
* zlib1g-dev

To install the necessary packages you can use the Ubuntu packaging system apt
用ubuntu的包管理系统apt安装必须的包

Example 1.

#apt-get update
#apt-get install


Installing Xen onto Ubuntu Linux

First, download the xen install package with the following command.

Example 2.

#wget http://www.cl.cam.ac.uk/Research/SRG/netos/xen/downloads/xen-2.0.5-install.tgz


Now untar the file.

#tar zxvf xen-2.0.5-install.tgz


And run the script

#sh ./install.sh


All of the necessary Xen packages should now be installed in the proper places. The only thing left to do is configure the bootloader.

Configuring the Bootloader

The options that are passed to the Xen kernel by Grub are slighlty different than those that are passed to the Linux kernel. Here is the entry that had to be added to the Grub configuration in order to boot Xen. The file that you will need to edit is /boot/grub/menu.lst

Example 3.

title Xen 2.0 / XenLinux 2.6.10
kernel /boot/xen.gz dom0_mem=131072
module /boot/vmlinuz-2.6.10-xen0 root=/dev/hdb1 ro console=tty0


If your machine needs an initrd to boot you will need to add that to the configuration. Most people won't need this and more information can be found on the Xen FAQ . You will definitely need this if your root filesystem is on an lvm partition.

Creating Domain Configurations

Two example configuration files are contained in /etc/xen, xmexample1 and xmexample2. The only difference between these two configuration files is that the second one has comments and contains an extra unnecessary function, which you will see later. Open xmexample2 with a text editor.

The first bit of code encountered allows for a domain-naming scheme based off of a variable.

Example 4.

def vmid_check(var,val):
val = int(val)
if val <= 0:
raise ValueError
return val

xm_vars.var('vmid',
use="Virtual machine id. Integer greater than 0.",
check=vmid_check)

xm_vars.check()


The next variable encountered is kernel. Here a xen enabled kernel must be specified. This is the kernel the new domain will run on. Also note that the new kernel must be a "xenU" kernel. The U stands for user.

Example 5.

kernel = "/boot/vmlinuz-2.6.10-xenU"


memory specifies how much RAM the new domain will use. Make sure not to use more than the machine has.

Moving right along, the name variable indicates what the new domain will be called. In this case the name depends on the value of vmid given.

Example 6.

name = "VM%d" % vmid


cpu is used for machines with multiple processors. Just comment this out if your machine does not have multiple processors.

The vif variable declares the mac address of the new domain. If no mac address is specified a random mac address is given by xen. In order for the new domain to access the internet on campus the mac address must be registered.

Next, disk indicates where the root directory of the new domain can be found, which partition xen resides on, and specifies permissions the new domain will have. The first argument is the root partition of new domain. This could also be a file as you will see later. The second argument is the partition xenLinux resides on. And finally, the last argument is the permissions the domain will have on its root partition files. So it should look something like:

Example 7.

disk = ['phy:hdb2,hdb1,w']


or

disk = ['file:/path/to/the/root/file,hdb1,w']


In the example file uses the vmid variable to indicate which partition the new domain's root directory is located. This can be useful, but not for the purposes of this howto.

Leave dhcp commented out. Xen will automatically give new domains a random ip address.

root points to the root device. This should be the location of the xen root partition. Also specified is read-only permissions so the new domain can't affect the xen host it's running on top of.

Another useful variable you may wish to declare is reboot. Declaring this to "always" and the only way to kill the domain is using xen commands, which will be discussed in another section.

And there you have, a xen domain configuration file. Your only a short command away from having a brand new domain up!!
Starting the Daemon

The xen daemon is called xend but all xen commands are under xm. To start,stop,reset the daemon:

Example 8.

#xend start
#xend stop
#xend restart


If the xen daemon does not start properly make sure that the localhost is up.

Example 9.

#ifconfig lo
#dhclient


Once the daemon is running, it's time to make some domains. Use the following command to make a domain out of the configuration file customDomain.

Example 10.

#xm create -c customDomain vmid=2


The -c flag means that you want the new domain's console to be the current console. The vmid variable is used in the name of the domain. This domain will be VM2. To stop a domain from running either shut the domain down from its console or use xm to destroy the domain.

Example 11.

#xm destroy VM2


You can list all current running domains with

Example 12.

#xm list


Installing ttyLinux

ttyLinux is a stripped down linux system. Creating a domain from this file is very simple and shows one method of creating many domains without the burden of many partitions.
First, download the zipped ttyLinux file.

Example 13.

#wget http://easynews.dl.sourceforge.net/sourceforge/xen/ttylinux-xen.bz2


Next, unzip the file.

#bzip2 -d ttylinux-xen.bz2


Now that we have the system we must right a Xen configuration file for it. To keep things organized it is recommended that you put this file into /etc/xen.

Example 14.

kernel = "/boot/vmlinuz-2.6-xenU"
memory = 64
name = "ttylinux"
nics = 1
ip = "1.2.3.4"
disk = ['file:/etc/xen/ttylinux-xen,sda1,w']
root = "/dev/sda1 ro"


Now create the domain using the new configuration file.

Example 15.

#xm create -c ttyLinux


And voila!! Was that easy or what?

Installing other Linux Distributions(安装其他linux发行版)

Larger Linux distributions are sometimes more difficult to install on a virtual machine. This is because the installation program does not usually support Xen because it is such a new technology.

Installing Debian Linux

Debian is suprisingly simple to install as a Xen guest. In this example we will be using files to back the Xen guest. To begin you must initialize the files using dd. This example assumes that your image files are /opt/xen-images/debian-root and /opt/xen-images/debian-root.

Example 16.

#dd if=/dev/zero of=/opt/xen-images/debian-root bs=1024k count=1000
#dd if=/dev/zero of=/opt/xen-images/debian-swap bs=1024k count=500


Now we will initialize the filesystems inside of each of these files. We will be using ext3 as our root filesystem.

Example 17.

#mkfs.ext3 /opt/xen-images/debian-root
#mkswap /opt/xen-images/debian-swap


Now we will need to mount the root filesystem before we run debootstrap.

Example 18.

#mkdir /mnt/debian
#mount -o loop /opt/xen-images /mnt/debian


Now we will install debootstrap and bootstrap a base Debian installation. This is a barebones installation that is less than 200 megs.

Example 19.

#apt-get install debootstrap
#debootstrap --arch i386 sarge /mnt/debian http://ftp.us.debian.org/debian


At this point your system is an unconfigured base system. You will need to edit the following files in order to have your system in a valid configuration.

* /etc/fstab
* /etc/hostname
* /etc/hosts
* /etc/network/interfaces
* /etc/apt/sources.list

FSTAB configuration

Example 20.

/dev/sda1 / ext3 defaults 0 1
/dev/sda2 swap swap defaults 0 0
proc /proc proc defaults 0 0


Hostname

Example 21.

debian-xen-guest


You will need to make sure that /etc/hosts contains the following line.

Example 22.

127.0.0.1 localhost


At this point you will need to setup your network interface configuration. This is done my editing the file /etc/network/interfaces. This guest will have a loopback network device and one ethernet card that will be configured with dhcp. More information on configuring network devices under Debian can be found in the Debian Reference.

Example 23.

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp


You'll also need to add a mirror to /etc/apt/sources.list Then you can unmount the filesystem image.

Now you can write the domain configuration file. This file will be can be stored anywhere on the filesystem but we have chosen to store all of our configurations in /etc/xen. Here is a sample domain configuration file for a debian based Xen guest.

Example 24.

name="Debian"
memory=128
kernel="/boot/vmlinuz-2.6.10-xenU"
nics=1
disk=['file:/opt/xen-images/debian-root,sda1,w','file:/opt/xen-images/debian-swap,sda2,w']
root="/dev/sda1 ro"


Now we are ready to boot our Debian guest.

Example 25.

#xm create /etc/xen/debian.conf -c


Other Resources
文章评论

共有 0 条评论