Академический Документы
Профессиональный Документы
Культура Документы
I'm using a Debian Lenny system (x86_64) with the hostname server1.example.com and the IP address
192.168.0.100 as the host system (dom0). (The setup might differ slightly if you are on an i386
system.) I will use Debian Lenny for the virtual machines (domU) as well.
This guide will explain how to set up image-based virtual machines and also LVM-based virtual
machines.
2 Installing Xen
To install Xen, we simply run
apt-get install xen-hypervisor-3.2-1-amd64 xen-linux-system-2.6.26-1-xen-amd64
xen-utils-3.2-1 xenstore-utils xenwatch xen-shell xen-tools
Afterwards we open /etc/modules and make sure that we have the line loop max_loop=64 in it (this
step is needed only if you want to create image-based virtual machines - you can skip it if you want to
create LVM-based virtual machines):
vi /etc/modules
[...]
loop max_loop=64
The dir line specifies where the virtual machine images will be stored. dist specifies the distribution to
be installed in the virtual machines (Debian Lenny) (there's a comment in the file that explains what
distributions are currently supported).
The passwd = 1 line makes that you can specify a root password when you create a new guest domain.
In the mirror line specify a Debian mirror close to you.
Make sure you specify a gateway, netmask, and broadcast address. If you don't, and you don't specify a
gateway and netmask on the command line when using xen-create-image, your guest domains won't
have networking even if you specified an IP address!
It is very important that you add the line serial_device = hvc0 because otherwise your virtual machines
might not boot properly!
Note :
Mount the Guest iso under the path /var/www/html/pub -
# mount -o loop isopath /var/www/html/pub
view the mounted file in firefox - http://localhosthtml/pub ,
Use the above path in the file /etc/xen-tools/xen-tools.conf as a mirror for installation
of Guest OS.
Before we go on, we must create the directory where the virtual machine images should be stored:
mkdir /home/xen
Now let's create our first guest domain, xen1.example.com, with the IP address 192.168.0.101:
xen-create-image --hostname=xen1.example.com --size=4Gb --swap=256Mb --ip=192.168.0.101
--memory=128Mb --arch=amd64 --role=udev
Options that you specify on the command line override the settings in /etc/xen-tools/xen-tools.conf.
Options that are not specified on the command line are taken from /etc/xen-tools/xen-tools.conf. Please
make sure that you add --role=udev, or your virtual machine might not boot properly!
(To learn more about the available options, take a look at the xen-create-image man page:
man xen-create-image
)
The xen-create-image command will now create the xen1.example.com virtual machine for us. This
can take a few minutes. The output should be similar to this one:
server1:~# xen-create-image --hostname=xen1.example.com --size=4Gb --swap=256Mb --
ip=192.168.0.101 --memory=128Mb --arch=amd64 --role=udev
General Information
--------------------
Hostname : xen1.example.com
Distribution : lenny
Partitions : swap 256Mb (swap)
/ 4Gb (ext3)
Image type : sparse
Memory size : 128Mb
Kernel path : /boot/vmlinuz-2.6.26-1-xen-amd64
Initrd path : /boot/initrd.img-2.6.26-1-xen-amd64
Networking Information
----------------------
IP Address 1 : 192.168.0.101 [MAC: 00:16:3E:D0:91:EE]
Netmask : 255.255.255.0
Broadcast : 192.168.0.255
Gateway : 192.168.0.1
Creating partition image: /home/xen/domains/xen1.example.com/swap.img
Done
Creating swap on /home/xen/domains/xen1.example.com/swap.img
Done
Creating partition image: /home/xen/domains/xen1.example.com/disk.img
Done
Creating ext3 filesystem on /home/xen/domains/xen1.example.com/disk.img
Done
Installation method: debootstrap
Done
Running hooks
Done
Role: udev
File: /etc/xen-tools/role.d/udev
Role script completed.
Creating Xen configuration file
Done
Setting up root password
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
All done
Logfile produced at:
/var/log/xen-tools/xen1.example.com.log
server1:~#
There should now be a xen1.example.com configuration file - /etc/xen/xen1.example.com.cfg. Take a
look at it to become familiar with virtual machines configuration files:
vi /etc/xen/xen1.example.com.cfg
#
# Configuration file for the Xen instance xen1.example.com, created
# by xen-tools 3.9 on Tue Feb 3 17:56:25 2009.
#
#
# Kernel + memory size
#
kernel = '/boot/vmlinuz-2.6.26-1-xen-amd64'
ramdisk = '/boot/initrd.img-2.6.26-1-xen-amd64'
memory = '128'
#
# Disk device(s).
#
root = '/dev/xvda2 ro'
disk =[
'file:/home/xen/domains/xen1.example.com/swap.img,xvda1,w',
'file:/home/xen/domains/xen1.example.com/disk.img,xvda2,w',
]
#
# Hostname
#
name = 'xen1.example.com'
#
# Networking
#
vif = [ 'ip=192.168.0.101,mac=00:16:3E:D0:91:EE' ]
#
# Behaviour
#
on_poweroff = 'destroy'
on_reboot = 'restart'
on_crash = 'restart'
(Please note: if you have a dual-core or quad-core CPU and want the virtual machine to use all CPU
cores, please add the line vcpus = '2' or vcpus = '4' to the configuration file.)
To start the virtual machine, run
xm create /etc/xen/xen1.example.com.cfg
Run
xm console xen1.example.com
to log in on that virtual machine (type CTRL+] if you are at the console, or CTRL+5 if you're using
PuTTY to go back to dom0), or use an SSH client to connect to it (192.168.0.101).
To get a list of running virtual machines, type
xm list
The output should look like this:
server1:~# xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 3488 2 r----- 398.2
xen1.example.com 6 128 1 -b---- 2.8
server1:~#
To shut down xen1.example.com, do this:
xm shutdown xen1.example.com
If you want xen1.example.com to start automatically at the next boot of the system, then do this:
ln -s /etc/xen/xen1.example.com.cfg /etc/xen/auto
Here are the most important Xen commands:
xm create -c /path/to/config - Start a virtual machine.
xm shutdown <name> - Stop a virtual machine.
xm destroy <name> - Stop a virtual machine immediately without shutting it down. It's as if you
switch off the power button.
xm list - List all running systems.
xm console <name> - Log in on a virtual machine.
xm help - List of all commands.
A list of all virtual machines that were created with the xen-create-image command is available under
xen-list-images
server1:~# xen-list-images
Name: xen1.example.com
Memory: 128
IP: 192.168.0.101