Tech > XenTips

Xen Tips

Introduction

This document is just a basic stub - to be fleshed out

Capabilities

Before installing Xen, the following command indicates whether your cpu supports HVM.

$ egrep --color 'vmx|svm' /proc/cpuinfo

The following should show control_d when booted using Xen dom0 kernel:

$ cat /proc/xen/capabilities
control_d

Debian Squeeze

Install the Xen packages (32bit):

$ sudo apt-get install xen-hypervisor-4.0-i386 linux-image-xen-686 \
xen-qemu-dm-4.0 xen-tools

or (64bit)

$ sudo apt-get install xen-hypervisor-4.0-amd64 linux-image-xen-amd64 \
xen-qemu-dm-4.0 xen-toolsq

Optionally install documentation

$ sudo apt-get install xen-docs-4.0 

Create domU Guest

$ sudo xen-create-image --hostname lucid01 --ip 10.0.0.255 --dist lucid

or

$ sudo xen-create-image --hostname lucid02 --ip 10.0.0.255 \
--install-method=copy --install-source=/mnt/lucid01 --dist lucid

$ sudo xen-create-image --hostname lucid02 --ip 10.0.0.255 \
--install-method=tar --install-source=image.tar --dist lucid

Note: When using the copy or tar method, the scripts hangs waiting for input to ssh-keygen - tail the log whilst the image is being created to see when those points are reached and whether you need to hit the return key to move the script along.

Basic Commands

# xend start
# xm create -c /etc/xen/my_vm.cfg
# xm list
# xm shutdown my_vm
# xm list
# xm console my_vm
# xend stop

Using an ISO Image for an HVM Guest

Amend the disk configuration in the guest configuration file to refer to the iso image as a file. E.g.

disk        = [
                  'phy:/dev/vg0/my-disk,xvda,w',                                          
                  'phy:/dev/vg0/my-swap,xvdb,w',                                          
                  'file:/var/local/isos/debian-6.0.3-i386-DVD-1.iso,xvdc:cdrom,r'           
              ]

Mounting an HVM Disk Image on Dom0

You can mount an HVM disk image on Dom0 as follows:

  1. Use fdisk to calculate the start position of the partion within the disk image. E.g. for a LVM image:

    # fdisk -ul /dev/vg0/lenny-hvm-disk
    Disk /dev/vg0/lenny-hvm-disk: 10.7 GB, 10737418240 bytes
    255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x000f2d38
    
              Device Boot      Start         End      Blocks   Id  System
    /dev/vg0/lenny-hvm-disk1              63    20964824    10482381   83  Linux
  2. The start location is the sector size multiplied by the start sector number. In the above example this is 512 * 63 = 32,256.

  3. Mount the image, setting the offset to the calculated value. e.g.

    # mkdir /mnt/lenny-hvm
    # mount -o loop,offset=32256 /dev/vg0/lenny-hvm-disk /mnt/lenny-hvm

See http://www.gnu.org/software/hurd/hurd/running/qemu.html

-- Frank Dean - 11 Dec 2011

Clock Syncing

The domU clocks should be synced with dom0. Alternatively, install ntp and configure the Xen wallclock to be independent.

# echo "xen.independent_wallclock = 1" >/etc/sysctl.d/xen.conf

If you can't access an NTP server, install chrony (which can act as an NTP server) on the dom0 host and set the domU guests to use the host as the NTP server. See the LinuxClockGuide.

It appears the xen.independent_wallclock setting has been removed from more recent pvops kernels. See independent_wallclock in Xen 4, Xen in Debian wiki and Xen/Clocksource. It appears adding an entry of "disable kernel" to /etc/ntp.conf should fix the issue.

See also:

-- Frank Dean - 12 Jul 2012

Bridge

You probably also want to disable Network Manager. By de-selecting Network Manager's 'Enable Networking' option, Network Manager simply won't take part in managing the network connections, leaving it to you to configure /etc/network/interfaces appropriately.

See Also

Troubleshooting

Error: 'NoneType' object has no attribute 'rfind'

Install the xen-qemu-dm-4.0 package - Debian bug #587090

References

Related Topics: LinuxHintsAndTips, LinuxClockGuide

-- Frank Dean - 17 Oct 2009