Tuesday, September 13, 2011

Xen - Creating an HVM domU guest

Xen supports fully virtualized guest domains by using hardware assisted virtualization. Currently processors featuring the Intel Virtualization Technology (Intel-VT) or the AMD Virtualization Technology (AMD-V) are supported. For a way to see if your processor has virtualization technology run the following command if xend is running:

root@dom0$ xm dmesg | grep -i hvm

If xend is not running, to check if our Intel based system supports this feature we can run:

root@dom0$ cat /proc/cpuinfo | grep vmx

For AMD based processors, we can run the following command:

root@dom0$ cat /proc/cpuinfo | grep svm


If your system does not include this support you can still use Xen in paravirtualization mode. You will not, however, be able to run unmodified operating systems such as Microsoft Windows as a Xen guest operating system.
In order to install an HVM guest some form of disk storage is needed to contain the guest operating system. We can use as storage a whole physical disk (e.g. ‘/dev/sda’), a physical disk partition (e.g. ‘/dev/sda1’), or a disk image file. Here we will follow the last approach. To create the disk image file for the HVM guest we use the ‘dd’ utility:

root@dom0$ dd if=/dev/zero of=/home/giorgos/xen/domuhvm.img bs=1024K count=0 seek = 8192

This example creates an 8GB disk image. The next step is to install the guest operating system onto the disk image by a suitable installation media (such as a DVD or ISO image). This task can be performed with the help of the domain’s configuration file. More specifically, the HVM guest configuration file should have an option to provide CD-ROM support to the guest as well as a boot device specification in order to boot from the CD-ROM device and install the operating system. 
Xen includes a sample configuration file, ‘/etc/xen/xmexample.hvm’ which can be used as a starting point for an HVM domU guest configuration file. Many of these values can be left unchanged. Some key values will be discussed in the remainder of this section. Let’s take a look at the following configuration file:

#  -*- mode: python; -*-
#=========================================
# Python configuration setup for 'xm create'.
# This script sets the parameters used when a domain is created using 'xm create'.
# You use a separate script for each domain you want to create, or
# you can set the parameters for the domain on the xm command line.
#=========================================

# Kernel image file.
kernel = "hvmloader"

# The domain build function. HVM domain uses 'hvm'.
builder='hvm'

# Initial memory allocation (in megabytes) for the new domain.
# Allocating less than 32MBs is not recommended.
memory = 128

# A name for your domain. All domains must have different names.
name = "domu-hvm"

# The number of cpus guest platform has, default=1
vcpus=1

# Enable/disable HVM guest PAE, default=1 (enabled)
pae=1

# Enable/disable HVM guest ACPI, default=1 (enabled)
acpi=1

# Enable/disable HVM APIC mode, default=1 (enabled)
# Note that this option is ignored if vcpus > 1
apic=1

# Primary network interface
vif = [ 'type=ioemu, bridge=xenbr0' ]

# Define the disk devices you want the domain to have access to
disk = [ 'file:/home/giorgos/xen/domuhvm.img,hda,w', ',hdc:cdrom,r' ]

# Device Model to be used
device_model = 'qemu-dm'

# boot on floppy (a), hard disk (c), Network (n) or CD-ROM (d)
# default: hard disk, cd-rom, floppy
boot="dc"

# Enable SDL library for graphics, default = 0
sdl=0

# Enable OpenGL for texture rendering inside the SDL window, default = 1
# valid only if sdl is enabled.
# opengl=1

# Enable VNC library for graphics, default = 1
vnc=1

# The address that should be listened on for the VNC server if vnc is set.
# default is to use 'vnc-listen' setting from
# auxbin.xen_configdir() + /xend-config.sxp
#vnclisten="127.0.0.1"

# Set VNC display number, default = domid
#vncdisplay=1

# Try to find an unused port for the VNC server, default = 1
#vncunused=1

# Set password for domain's VNC console
# default is depents on vncpasswd in xend-config.sxp
vncpasswd=''

# No graphics, use serial port
#nographic=0

# Enable stdvga, default = 0 (use cirrus logic device model)
stdvga=0

#   Serial port re-direct to pty deivce, /dev/pts/n
#   then xm console or minicom can connect
serial='pty'

#   tsc_mode
tsc_mode=0

#   Qemu Monitor, default is disable
#   Use ctrl-alt-2 to connect
#monitor=1

# Enable sound card support, [sb16|es1370|all|..,..], default none
#soundhw='sb16'

# Set the real time clock to local time [default=0 i.e. set to utc]
localtime=1

# Start in full screen
#full-screen=1

# Enable USB support
#usb=1

# Enable USB mouse support
#usbdevice='mouse'
#usbdevice='tablet'

# Set keyboard layout, default is en-us keyboard.
#keymap='en-us'

# Enable/disable xen platform PCI device, default=1 (enabled)
#xen_platform_pci=1

Let’s discuss now the key settings of the above configuration file:
  • kernel = “hvmloader”: This option defines the HVM firmware loader, which in our case is ‘/etc/lib/xen/boot/hvmloader’. This setting must be left unchanged.
  • builder = ‘hvm’: This option specifies the domain build function and must be left unchanged.
  • memory = 128: Initial memory allocation (in megabytes) for the new domain. Note that creating a domain with insufficient memory may cause out of memory errors. The domain needs enough memory to boot kernel.
  • name = “domu-hvm”: This option gives a name to the guest domain. Here we name it as ‘domu-hvm’.
  • vcpus = 1: Defines the number of the domain’s virtual CPUs.
  • acpi = 1: Enables HVM guest ACPI.
  • apic = 1: Enables HVM guest APIC.
  • pae = 1: Enables HVM guest PAE.
  • disk = [‘file:/home/giorgos/xen/domuhvm.img,hda,w’, ‘,hdc:cdrom,r’]: Defines the disk devices you want the domain to have access to, and what you want accessible as. If using a physical device as the HVM guest’s disk, each disk entry is of the form ‘phy:UNAME,ioemu:DEV,MODE,’ where UNAME is the host device file, DEV is the device name the domain will see, and MODE is ‘r’ for read-only, ‘w’ for read-write. ‘ioemu’ means the disk will use ‘ioemu’ to virtualize the HVM disk. If not adding ‘ioemu’, it uses ‘vbd’ like paravirtualized guests. On the other hand, if using a disk image file, its form should be like ‘file:FILEPATH,ioemu:DEV,MODE’. Optional devices can be emulated by appending ‘cdrom’ to the device type: ‘,hdc:cdrom,r’. It is also possible to define an ISO image as the guest’s CD-ROM device. To do this we can use this setting: disk=[‘file:/home/giorgos/xen/domuhvm.img,hda,w’,‘file:/home/giorgos/somedvd.iso,hdc:cdrom,r’].
  • boot = “dc”: This option specifies the boot device priority. boot on floppy (a), hard disk (c), Network (n) or CD-ROM (d). For example with the value “dc” the guest will boot from CD-ROM and failback to hard disk.
  • device_model = ‘qemu-dm’: The device emulation tool for HVM guests. This parameter should not be changed.
  • sdl = 0: This option enables SDL library for graphics. The default is disabled.
  • vnc = 1: This option enables VNC library for graphics. The default is enabled. Note, that if you have ‘vnc’ enabled you must disable ‘sdl’ and vice versa.
  • vnclisten = “127.0.0.1”: Defines the address that should be listened on for the VNC server if ‘vnc’ is set.
  • nographic = 0: Disables graphics.
  • usb = 1: Enable USB support without defining a specific USB device.
  • usbdevice = ‘mouse’: Enable USB support and also enable support for the given device. Devices that can be specified are ‘mouse’, ‘tablet’ and ‘host:id1:id2’.
  • localtime = 1: set the real time clock to local time [default=0 i.e. set to utc].

Since we have to install the operating system before we can boot from the hard disk drive we need to place the CD-ROM first in the boor order by specifying: boot = ‘dc’. It is also required to provide a CD-ROM device or an ISO image to the guest as stated above. Now, we can save the above file as ‘/etc/xen/domu-hvm.config’ and start the guest domain:

root@dom0$ xm create –c domu-hvm.config

The guest domain will boot and the installation process from the given media will begin. If SDL was chosen for the graphical console then the console should appear when the guest starts up. Otherwise, if VNC was selected and the HVM domainU was not automatically start vncviewer, it is necessary to connect manually. By default the VNC port is the ID of the domain to which we wish to connect (which can be obtained using the ‘xm list’ command). For example, to connect to domain with ID 1 we run:

root@dom0$ vncviewer localhost:1

References



No comments:

Post a Comment