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 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
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
installation. Additionally, we created a swap partition of
256 MB on
root domain0 -> sda1 swap domain0 -> sda5 root guest1 -> sda6 swap guest1 -> sda7 root guest2 -> sda8 swap guest2 -> sda9
# urpmi kernel-xen xen
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..
title XEN 3 / Mandriva Enterprise Server 5 kernel (hd0,0)/boot/xen.gz dom0_mem=131072 module (hd0,0)/boot/vmlinuz-22.214.171.124-xen-3.3.0-7mdv root=/dev/sda1 ro module (hd0,0)/boot/initrd-2.6.18-8-xen-3.3.0-7mdv.img
# mkinitrd -v -f /boot/initrd-126.96.36.199-xen-3.3.0-7mdv.img 188.8.131.52-xen-3.3.0-7mdv
Starting Xen services
# chkconfig --add xend # chkconfig --add xendomains # service xend start # service xendomains start
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.
# 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
Install Mandriva Enterprise Server 5 with urpmi. With urpmi, you can get a clean installation of a new Mandriva Enterprise Server 5.
/dev/sda1 / ext3 relatime,user_xattr,acl 1 1 /dev/sda5 swap swap defaults 0 0 none /proc proc defaults 0 0
# mount /dev/sda6 /mnt/xen
# urpmi.addmedia --distrib --urpmi-root /mnt/xen urlYou must configure
urlto point to the directory containing the installation media.
# urpmi --urpmi-root /mnt/xen basesystem urpmi
# cp /etc/resolv.conf /mnt/xen/etc # cp /etc/fstab /mnt/xen/etc
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 \ /mnt/xen/etc/sysconfig/network-scripts
# urpmi --urpmi-root /mnt/xen dhcp-client
# chroot /mnt/xen
# touch /etc/mtab /etc/urpmi/urpmi.cfg /var/lib/urpmi/MD5SUM
# passwd root
# 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
# dd if=/dev/zero of=mandriva.img bs=1M count=1 seek=1024
# mke2fs -F -j mandriva.img
# mount -o loop mandriva.img /mnt/xen
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
kernel = "/boot/vmlinuz-184.108.40.206-xen-3.3.0-7mdv" ramdisk = "/boot/initrd-xen-220.127.116.11-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 = [ '' ]
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
w option explains the read-write rights to
access this partition. You could also use the
r option to set the partition as
/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
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
#if [ -x /etc/init.d/keytable -a -d /usr/lib/kbd/keymaps ]; then # /etc/init.d/keytable start #fi
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?
# /etc/init.d/numlock stop # chkconfig numlock off
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
for network access.
See XenNetworking for detailed information on networking with Xen.
# xm create -c /etc/xen/auto/mandriva
command starts a new domain instance. The
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
# xm list
# xm console Mandriva
# xm save Mandriva mandriva.chk
# xm restore mandriva.chk
Error: Error creating domain (12, 'Cannot allocate memory')
dom0_mem option on the
Xen command line in the
grub.conf entry :
Error: Error creating domain: Kernel image does not exist : /boot/vmlinuz-18.104.22.168-xen-3.3.0-7mdv
please install the
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
If you know that your processor includes a virtualisation extension even if it is not displayed, please check if your BIOS is well configured. If the option is not enable, do it. For the modification to be taken into account, a hardware reboot is not enough, you have to completely shut down the server.
The KVM website is located here: linux-kvm.org
# urpmi qemu-img kvm
# lsmod |grep kvm
#usermod -G kvm test
$id uid=500(test) gid=500(test) groupes=422(kvm),500(test)
$ 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.
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.
kvm -k en-us -m 512 -cdrom /dev/cdrom -drive file=mes5dvd,boot=on
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
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.
#chkconfig libvirtd on
You can find more informations on official Virt-manager website.