Creating VMs

From Wikislax

Jump to: navigation, search

Contents

the xm tool

There is a variety of tools and commands to handle virtual machines. Here we will use the Xen xm command.

Xen supports paravirtualisation and hardware virtualization. Both can be used at the same time on a single Xen system.

Creating a PV VM

Paravirtualization requires storing the kernel to boot in the dom0 filesystem, and populating the system in a virtual partition. The kernel generated must be able to manage the QEMU devices and include the .config file domU options. Here is a minimal example of such a .config domU file. The swap partition and VM filesystem can be created as below :

# dd if=/dev/zero of=XenGuest1.swap bs=1024k seek=1024 count=0
# mkswap XenGuest1.swap
# dd if=/dev/zero of=XenGuest1.img bs=1024k seek=8192 count=0
# mkfs -t ext3 XenGuest1.img
# mkdir /tmp/loop
# mount -o loop XenGuest1.img /tmp/loop
# cp -ax /{bin,dev,etc,lib,root,sbin,usr,var} /tmp/loop
# mkdir /tmp/loop/{home,proc,opt,sys,tmp}
# chmod 777 /tmp/loop/tmp

Then a PV config file needs to be created. Samples are available from the /etc/xen directory. Here is a running example for slackware 12.1 (32 bits). The main config options to modify are :

# Kernel image file in dom0 filesystem
kernel = "/boot/vmlinuz-domU"
# Not using any optional ramdisk
#ramdisk = "/boot/initrd.gz"
# Initial memory allocation (in megabytes) for the new domain.
memory = 2048
# A name for the new domain. All domains have to have different names,
name = "sl12"
# Number of virtual CPUs
vcpus = 4
# Define network interfaces
vif = [ ' ' ]
# Define disk devices. Note the device names xvda and xvdb
disk = [ 'file:/mnt/xen/sl12.img,xvda1,w', 'file:/mnt/xen/sl12.swap,xvdb,w' ]
# Define frame buffer device. Use sdl to view virtual machine in a window
vfb = [ 'sdl=1' ]
# Set root device.
root = "/dev/xvda1 ro"
# Window resolution additional parameters
extra = "xen-fbfront.video=16,1280,768"

The VM can then be launched with xm create file :

root@inner:/etc/xen# xm create sl12
Using config file "./sl12".
Started domain sl12 (id=1)
root@inner:/etc/xen#

Creating a HVM

Full hardware virtualization requires only a disk image to execute in. Then a HV config file needs to be created. Samples are available from the /etc/xen directory. Here is a running example for Windows 7 (64 bits). The main config options to modify are :

# Initial memory allocation (in megabytes) for the new domain.
memory = 2048
# A name for the new domain. All domains have to have different names,
name = "win7"
# Number of virtual CPUs
vcpus = 4
# Define network interfaces
vif = [ 'type=ioemu, bridge=eth0' ]
# Define disk devices. Note the device names xvda and xvdb
disk = [ 'file:/mnt/xen/win7.img,hda,w', 'file:/mnt/temp/win7.iso,hdc:cdrom,r' ]
# enable SDL library for graphics, default = 0
sdl=1
# enable VNC library for graphics, default = 1
vnc=0
# set VNC display number, default = domid
vncdisplay=7
#   Enable USB mouse support
usbdevice='tablet'
#   Set keyboard layout, default is en-us keyboard.
keymap='fr'

The VM can then be launched with xm create file :

root@inner:/etc/xen# xm create win7
Using config file "./win7".
Started domain win7 (id=2)
root@inner:/etc/xen#

A little screen shot

The 3 VMs displayed on this slackware 13.37 dom0 are slackware 12.1, windows 7 and windows 8.

Screenshot.png


Compiling Grub2 Main Page OpenSSL
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox