Abstract
This chapter discusses the concepts and procedures to implement virtual machines on your Mandriva Enterprise Server 5 using Xen, KVM or graphical tool Virt-manager. This will allow you to run multiple OSes within your Mandriva Linux server.
Xen is a virtual machine
monitor for x86 hardware (it runs on i686 and x86-64 CPU
classes). It supports running multiple guest operating systems on a
single machine. Guest OSes (also called “domains”)
require a modified kernel which supports
Xen hypercalls to replace physical
hardware access. At boot, the Xen kernel
is loaded (via GRUB) along with the guest kernel
for the first domain (called
“domain0”). domain0 has privileges
to access the physical hardware (PCI and
ISA devices), to manage other domains, as well as
to provide virtual devices (disks and network) for other
domains.
Here are the main Web references which discuss the configuration of Xen :
We installed Mandriva
Mandriva Enterprise Server 5 on a 12 GB disk. During the installation, we
created a partition of 5 GB. Its file system is mounted on
/ for the domain0
installation. Additionally, we created a swap partition of
256 MB on /dev/sda5.
We now have 7 GB
left. We created two partitions of 3.2 GB, that are not yet
mounted, for two guest domains os
installations, and two swap spaces of 256 MB each.
root domain0 -> sda1
swap domain0 -> sda5
root guest1 -> sda6
swap guest1 -> sda7
root guest2 -> sda8
swap guest2 -> sda9
Mandriva Enterprise Server 5 provides the required patches in the kernel so that the Xen functionality is implemented. You will also need both specific kernels and tools to manage virtualization.
# urpmi kernel-xen xen
Installation of
xen package provides a bootloader configuration
and an initrd creation. What follows is a reminder to configure
domain0. You have to set up the automatic start
of xen services at boot time..
Configuring GRUB
An entry has been
added to the GRUB configuration file
(/boot/grub/menu.lst) so that Xen/Xenolinux can
boot. The entry should look like :
title XEN 3 / Mandriva Enterprise Server 5
kernel (hd0,0)/boot/xen.gz dom0_mem=131072
module (hd0,0)/boot/vmlinuz-2.6.18.8-xen-3.3.0-7mdv root=/dev/sda1 ro
module (hd0,0)/boot/initrd-2.6.18-8-xen-3.3.0-7mdv.img
Tells GRUB where Xen itself is located and parameters to be taken into account by the kernel (in this case, setting domain0 size of allocation memory in kilobytes).
The first line tells you where to find the Xenolinux kernel that Xen should launch with parameters. These are standard Linux parameters, root device identification and initial read-only mount.
The second line contains the path of initrd. It must be the module and not initrd in GRUB configuration, otherwise Xen will not boot.
Creating initrd
We are now going to
create initrd so that
Xen guest domains will be
managed at boot :
# mkinitrd -v -f /boot/initrd-2.6.18.8-xen-3.3.0-7mdv.img 2.6.18.8-xen-3.3.0-7mdv
Starting Xen services
At the end of the installation and configuration process, reboot your system and choose the Xen entry in the GRUB menu.
During your system's start-up, the first part of the output displays information for Xen itself (low level and hardware). The last part of the output displays information for Xenolinux.
To create additional domains, start the xend daemon control. You can also start the xendomains daemon, which launches additional domains at domain0's boot.
# chkconfig --add xend
# chkconfig --add xendomains
# service xend start
# service xendomains start
At this point, you can use the xm tool to monitor or maintain domains running on your system.
The first step in creating an additional domain is to prepare a root filesystem for it to boot. Typically, this might be stored in a normal partition, an LVM partition, a disk file or on an NFS server. A simple solution to do this is to boot from a system installation disk and install the distribution onto a new partition of your hard drive.
In the following sections, we will give an other option to create an additional domain based on a copy of domain0's root partition, installed with urpmi in a physical partition or in a file.
# mkdir -p /mnt/xen
Partition Copy. The main advantage of this method is that the installation disk is not needed. We copy the root partition of domain0 on another partition of the hard drive to obtain a second filesystem that will be used by the guest domain.
# mount /dev/sda6 /mnt/xen # rsync -avDx / /mnt/xen # cp -ar /dev/* /mnt/xen/dev/ # umount /mnt/xen
![]() |
Warning |
|---|---|
The rsync command will synchronize only root filesystems, it doesn't follow a mount link to other filesystems. |
If your /usr and /var are
separate, redo it for each mount point, except for the network
and special entries.
If you have different
partition schemes between domain0 and additional domains,
don't forget to adapt the /etc/fstab file
to the guest domain's filesystem.
Install Mandriva Enterprise Server 5 with urpmi. With urpmi, you can get a clean installation of a new Mandriva Enterprise Server 5.
You have to configure guest
domain /etc/fstab file.
For example, the partition /dev/sda6 becoming
/dev/sda1 :
/dev/sda1 / ext3 relatime,user_xattr,acl 1 1 /dev/sda5 swap swap defaults 0 0 none /proc proc defaults 0 0
First, mount your clean partition :
# mount /dev/sda6 /mnt/xen
# urpmi.addmedia --distrib --urpmi-root /mnt/xen urlYou must configure
url to point
to the directory containing the installation media.
Install the guest domain Mandriva Enterprise Server 5 system base and use urpmi to install new packages.
# urpmi --urpmi-root /mnt/xen basesystem urpmi
At the prompt, you
will be asked many questions. Answer them as you would
proceed for a classical installation (choosekernel-xen).
The following steps configure the new features :
Copy configuration files
for domain0.
# cp /etc/resolv.conf /mnt/xen/etc # cp /etc/fstab /mnt/xen/etc
Copy the networking configuration from domain0.
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 \ /mnt/xen/etc/sysconfig/network-scripts
Install dhcp client if necessary.
# urpmi --urpmi-root /mnt/xen dhcp-client
Enter chroot for final configuration.
# chroot /mnt/xen
Create empty necessary configuration files.
# touch /etc/mtab /etc/urpmi/urpmi.cfg /var/lib/urpmi/MD5SUM
# pwconv
Turn on network
by creating the /etc/sysconfig/network file with the
following content :
NETWORKING=yes
# passwd root
# exit
# umount /mnt/xen
Installing Mandriva Enterprise Server 5 in a File. This way of working has the advantage of not modifying the partition structure of your hard drive. We will explain how to create and mount a disk image. Then you can choose one of two methods below (urpmi or making a copy of the root partition).
First, create an
image file for your Mandriva Enterprise Server 5 guest domain. This command creates a disk image of 1GB,
filled with zeroes, in a file named
mandriva.img located in the current
directory.
# dd if=/dev/zero of=mandriva.img bs=1M count=1 seek=1024
Create a filesystem in the image file. The
-j
option
specifies an ext3 filesystem.
# mke2fs -F -j mandriva.img
Finally, you can mount your image file on a mount point.
# mount -o loop mandriva.img /mnt/xen
You can now use this mount point like a physical partition's mount point and install Mandriva Enterprise Server 5.
In the guest domain's
configuration file, the disk options should be modified so
that phy:sdaX is replaced by
file:path/of/file. Otherwise, other
options are similar.
Before you can launch an additional domain, you should create a configuration file for guest domains. The following section describes these steps. This file is not essential but will help you to get guest domains to boot without any problems.
Create a Guest Domain
Configuration File. The following
configuration file (call it “mandriva”) should be
located in the /etc/xen directory in
domain0 if you want to
launch it manually, or in the
/etc/xen/auto directory if you want to
launch it automatically by xendomains at
boot.
kernel = "/boot/vmlinuz-2.6.18.8-xen-3.3.0-7mdv" ramdisk = "/boot/initrd-xen-2.6.18.8-xen-3.3.0-7mdv.img" memory = 128 name = "Mandriva" dhcp = "dhcp" disk = [ 'phy:sda6,sda1,w', 'phy:sda7,sda5,w' ] root = "/dev/sda1 ro" extra = "xencons=tty" hostname = "mandriva2009" vif = [ '' ]
This file shows the most common options used for a domain definition. Here's a short description of each option :
Set it to the size of the guest domain's memory in megabytes.
Uncomment the dhcp
variable so that the domain will receive its
IP address from a
DHCP server.
List of block
devices exported to the guest domain. In this example, the
sda6 physical partition is named
sda1 in the additional domain and will
be the root partition with the following root option. The
sda7 partition is a swap. If your disk
is an image file, you should replace
phy:sdaX by
file:path/of/file. The
w option explains the read-write rights to
access this partition. You could also use the
r option to set the partition as
read-only.
Specify the root device parameter on the kernel command line. We must take the partition scheme of the disk option.
All the configuration
modifications detailed in the next sections must be made in
the guest domain, not in
domain0 as before. There are two
possibilities :
Modifying
/etc/inittab. If you don't want to
receive annoying messages such as :
INIT: Id "2" respawning too fast: disabled for 5 minutes INIT: Id "3" respawning too fast: disabled for 5 minutes INIT: Id "4" respawning too fast: disabled for 5 minutes INIT: Id "5" respawning too fast: disabled for 5 minutes INIT: Id "6" respawning too fast: disabled for 5 minutes
In your guest
console, you should comment unused terminals in the
/etc/inittab file like this :
1:2345:respawn:/sbin/mingetty tty1 #2:2345:respawn:/sbin/mingetty tty2 #3:2345:respawn:/sbin/mingetty tty3 #4:2345:respawn:/sbin/mingetty tty4 #5:2345:respawn:/sbin/mingetty tty5 #6:2345:respawn:/sbin/mingetty tty6
xend and xendomains Services. If you installed your system with a domain root filesystem copy, then xend and xendomains services are probably configured to start at boot time. It's useless for an additional domain. We will disable it as follows :
# /etc/init.d/xend stop # /etc/init.d/xendomains stop # chkconfig xend off # chkconfig xendomains off
Keytable Service. Here is a little hint to avoid failure messages when keymap is loading at guest domain boot. You should disable the keytable service with :
# chkconfig keytable off # /etc/init.d/keytable stop
But it's not enough because this service is called directly in the
/etc/rc.d/rc.sysinit file. We will comment out the following three
lines (905,906,907) :
#if [ -x /etc/init.d/keytable -a -d /usr/lib/kbd/keymaps ]; then # /etc/init.d/keytable start #fi
Notice that the
keytable and numlock (see following section) services
are not necessary in additional domains because
domain0 has already initialized
numlock and all domains use the same keyboard.
Numlock Service. Finally, in the configuration file of the guest domain, we get this message when the numlock service is started or when we log in :
KDGETLED: Argument invalide Error reading current led setting. Maybe stdin is not a VT?
To avoid this problem, disable the following :
# /etc/init.d/numlock stop # chkconfig numlock off
At this step, we
have a Xen system which
contains the domain0 and one or more
clean additional domains ready for execution.
This section explains Xen network basics and configuration.
The network
scheme is very simple. domain0 has real
Ethernet interface control. Each guest domain has a virtual
network interface. In additional domains, this interface is a
normal Ethernet interface but it's named
vifX.Y with “X” is the number
interface (0 for eth0) and Y is the number of its own instance
domain. All vif and eth
interfaces are connected on the peth0 bridge
for network access.
See XenNetworking for detailed information on networking with Xen.
You will find a documentation and explanations on les interfaces Ethernet interfaces, MAC addresses, bridging, routing, interface names, VLANs, etc.
The xm tool provides many options for managing domains. Here's a quick review :
Start guest domains : Before you start a domain, you should create a config file for it.
To start an additional domain :
# xm create -c /etc/xen/auto/mandriva
The create
command starts a new domain instance. The -c option
configures the console domain so that it should output immediately
and mandriva is the name of the additional
domain you start. You should now see a list of running
domains :
# xm list
You will find more details about syntax commands and options thorough the xm help command.
Using
the Xen console : if you
don't specify the -c option at
start time, you can still use the console.
# xm console Mandriva
Mandriva
is the name of the guest domain target. You can
replace it with the guest ID displayed in the
xm list.
To quit a guest console, just type Ctrl+] (Ctrl+$ dans une console virtuelle locale ou tty).
Guest
domain backup and restore: Administrators of a
Xen system can suspend a
virtual machine in its current state into a disk
file in domain0, allowing it to
resume at a later time.
For example, you can
suspend a domain called mandriva to
disk :
# xm save Mandriva mandriva.chk
This stops the
domain named mandriva and saves its
current state into a file called mandriva.chk.
To resume execution of this domain, use the xm restore command :
# xm restore mandriva.chk
This restores the state of the domain and resumes its execution. The domain will restart in the same state and the console may be reconnected using the xm console Mandriva command.
If you get the following error :
Error: Error creating domain (12, 'Cannot allocate memory')
add the dom0_mem option on the
Xen command line in the
grub.conf entry :
If you get the following error :
Error: Error creating domain: Kernel image does not exist : /boot/vmlinuz-2.6.18.8-xen-3.3.0-7mdv
please install the
kernel-xen package.
KVM (Kernel-based Virtual Machine) is a virtualization solution for x86 architectures based on Intel VT (vmx) and AMD-V (svm) technologies. To determine if such an extension is supported by your hardware, run the following command:
# grep ‘(vmx|svm)’ /proc/cpuinfo
With KVM, you can deploy Linux or Windows® virtual machines.
The KVM website is located here: linux-kvm.org
You will need both qemu-img and kvm packages
# urpmi qemu-img kvm
To use KVM, the kernel module must be loaded. You can verify it thanks to the following command:
# lsmod |grep kvm
The user which will be used to create your virtual machines must belong to the kvm group (here, the user is named 'test').
#usermod -G kvm test
Check with the id command that you user belongs to the kvm group:
$id uid=500(test) gid=500(test) groupes=422(kvm),500(test)
Be aware you'll need enough free space on your hard disk to host your virtual machines. You can create a dedicated partition for that use.
First, you have to create an image of the guest virtual machine. The following command create an image of 3GiB maximum size.
$ qemu-img create mes5dvd 3G Formatting 'mes5dvd', fmt=raw, size=3145728 kB
Different file formats exist. Please read the qemu-img man page to know the different possible file formats.
We are going to install Mandriva Enterprise Server 5 from the installation DVD media into the mes5dvd image we just have created.
kvm -k fr -m 512 -cdrom /dev/cdrom -drive file=mes5dvd
The CD or DVD installation media present into you CDROM/DVDROM device is bootable. Once the command is launched, a window appears and the virtual machine installation process begins. Install Mandriva Enterprise Server 5 completely.
To launch your virtual machine:
kvm -k en-us -m 512 -cdrom /dev/cdrom -drive file=mes5dvd,boot=on
Many options can be passed to KVM (please read man kvm).
With the method described upwards, your virtual machine will have network (same network access than the host machine). KVM deals with the network configuration on its own. If you want to intall several virtual machines, you will have to configure a bridge connection and configure your virtual machines as a NAT. To know how to configure a bridge and how to use it with KVM, you can read the documentation available at linux-kvm.org
Abstract
The "Virtual Machine Manager" application (Virt-manager) is a desktop user interface to configure and manage virtual machines, virtual networks and storage. It is possible to manage Xen, KVM or QEMU guests.
Virt-manager uses libvirtd so it is necessary to start it:
#/etc/init.d/libvirtd start
To add libvirtd on default start:
#chkconfig libvirtd on
If you use Xen, start xend daemon. If you use KVM, then load the kvm module.
So, now that you are ready to start Virt-manager, choose > > > :
#virt-manager
When Virt-manager is connected to your virtualisation system (Xen or KVM or QEMU), you can add a new guest by clicking on .
To configure your virtual networks and storage, click right on >
You can find more informations on official Virt-manager website.