http://www.virtuatopia.com/index.php/Xen_Virtualization_Essentials
http://wiki.xen.org/wiki/Xen_Configuration_File_Options
XL reference:
http://xenbits.xen.org/docs/4.2-testing/man/xl.1.html

Disk spec:  http://xenbits.xen.org/docs/4.3-testing/misc/xl-disk-configuration.txt

 


 

apt-get install xen-hypervisor-4.4-amd64
apt-get install xen-utils-4.4  xen-utils-common
apt-get install xen-tools  libxen-4.4
apt-get install xenstore-utils  libxenstore3.0
apt-get install libvirt0  libvirt-bin  libvirt-dev  libvirt-doc

apt-get install vncviewer

 

Check for HVM support:

 

(Intel:)    grep  vmx  /proc/cpuinfo
(AMD:)   grep  svm  /proc/cpuinfo

 

Edit /etc/default/grub, add line

 

GRUB_CMDLINE_XEN_DEFAULT="dom0_mem=min:768M,max:768M loglvl=all guest_loglvl=all"

 

Can also edit /etc/default/grub.d/xen.cfg

 

update-grub   => creates in grub2.cfg:

 

kernel  /boot/xeb-version  dom0_mem=768M,max:768M loglvl=all guest_loglvl=all

boot parameters: 
http://xenbits.xen.org/docs/unstable/misc/xen-command-line.html

 

reboot

 



Building HVM vitrtual machine

 

dd  if=/dev/cdrom  of=os-cd.iso

dd  if=/dev/zero  of=/guest/myvm/disk.img  bs=1M  seek=30000  count=0

 

create swap space:

 

dd  if=/dev/zero  of=myvm.swap   bs=1G  seek=10  count=0

mkswap  myvm.swap

 

create a copy of system image:

 

dd  if=/dev/zero  of=/guest/myvm/mylinux.img  bs=1M  seek=30000  count=0
mkfs.ext3  mylinux.img

mount  -o loop  mylinux.img  /mnt

cp  -ax  /{bin,dev,etc,lib,root,sbin,usr,var} /mnt
mkdir /mnt/{home,proc,opt,sys,tmp}
chmod 777 /mnt/tmp

 

create /guest/myvm/myvm.cfg

 

sample windows-guest.cfg

sample linux-guest.cfg

 

#import os, re

#arch = os.uname()[4]

#if re.search('64', arch):

#    arch_libdir = 'lib64'

#else:

#    arch_libdir = 'lib'

 

#device_model = '/usr/' + arch_libdir + '/xen/bin/qemu-dm'

 

#device_model = '/usr/lib/xen-4.4/bin/qemu-dm'

 

### Domain name

name="w7a"

 

# 128-bit UUID for the domain.  The default behavior is to generate a new UUID

# on each call to 'xm create'.

#uuid = "06ed00fe-1162-4fc4-b5d8-11993ee4a8b9"

 

builder="hvm"

 

# Kernel image file

#kernel = "/usr/lib/xen-4.4/boot/hvmloader"

 

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

vcpus=2

 

# List of which CPUS this domain is allowed to use, default Xen picks

#cpus = ""         # leave to Xen to pick

#cpus = "0"        # all vcpus run on CPU0

#cpus = "0-3,5,^1" # run on cpus 0,2,3,5

 

memory="2048"

 

# 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

 

# Shadow pagetable memory for the domain, in MB.

# If not explicictly set, xend will pick an appropriate value.

# Should be at least 2KB per MB of domain memory, plus a few MB per vcpu.

#shadow_memory = 8

 

### Disks

disk = [

    'file:/xenvirt/vm/w7a/disk.img,ioemu:hda,w',

    'file:/xenvirt/iso/win7-sp1-x64.iso,ioemu:hdc:cdrom,r',

]

 

# 'phy:/dev/cdrom,hdc:cdrom,r'

# 'phy:/dev/sdb11,hda,w'

# 'file:/path/xxx.img,hda,w'

 

# Disk spec:  http://xenbits.xen.org/docs/4.3-testing/misc/xl-disk-configuration.txt

#  write to temporary files instead of disk image files

#snapshot=1

 

#   serial port re-direct to pty deivce, /dev/pts/n

#   then xm console or minicom can connect

serial='pty'

 

#   Enable USB mouse support (only enable one of the following, `mouse' for

#                             PS/2 protocol relative mouse, `tablet' for

#                             absolute mouse)

 

usbdevice='mouse'

#usbdevice='tablet'

 

# Optionally define mac and/or bridge for the network interfaces.

# Random MACs are assigned if not given.

 

# type=ioemu specify the NIC is an ioemu device not netfront

#vif = [ 'type=ioemu, ip=192.168.1.210, mac=00:26:B9:48:74:d9, bridge=virbr0 , model=ne2k_pci' ]

vif = [ 'type=ioemu, ip=192.168.1.210, mac=00:26:B9:48:74:d9, bridge=virbr0' ]

 

#vif = [

#  'type=ioemu, mac=00:16:3e:09:f0:12, bridge=virbr0',

#  'type=ioemu, mac=00:16:3e:09:f0:13, bridge=virbr1'

#]

 

 

### Networking: use default parameters and DHCP

#vif = [ '' ]

 

#dhcp = "dhcp"

 

### Behavior

 

#  Enable VNC or SDL libraries for graphics

#  SDL is faster, but local only and closing screen terminates the domain

# Default: sdl=0, vnc=1

sdl=1

vnc=0

#sdl=0

#vnc=1

 

# enable spawning vncviewer for domain's console

# (only valid when vnc=1), default = 0

#vncconsole=1

 

# set password for domain's VNC console

# default is depents on vncpasswd in xend-config.sxp

vncpasswd='abc'

 

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

#vncunused=1

# don't automatically assign unused port based on domain id

vncunused=0

 

# VNC display number, i.e. port number to be added to "5900"

# e.g.:     vncdisplay=2  => port=5902

#           vncdisplay=30 => port 5930

# default = domid

# connect as vncviewer host:2 (not host:5902)

vncdisplay=2

 

# address that should be listened on for the VNC server if vnc is set.

# default is to use 'vnc-listen' setting from /etc/xen/xend-config.sxp

#vnclisten="127.0.0.1"

 

# no graphics, use serial port

#nographic=0

 

# enable stdvga, default = 0 (0 = use Cirrus Logic device model)

stdvga=1

videoram=16  # upto 2048x1536x32

 

### Boot

#boot='a'       # boot from floppy

boot='c'       # boot from HDD

#boot='d'        # boot from CD

#boot='dc'      # boot from CD + HDD

 

#   Qemu Monitor, default is disable

#   Use ctrl-alt-2 to connect

#monitor=1

 

#  start in full screen

#full-screen=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

 

# set the real time clock offset in seconds [default=0 i.e. same as dom0]

#rtc_timeoffset=3600

 

# Configure the behaviour when a domain exits.  There are three 'reasons'

# for a domain to stop: poweroff, reboot, and crash.  For each of these you

# may specify:

#

#   "destroy",        meaning that the domain is cleaned up as normal;

#   "restart",        meaning that a new domain is started in place of the old one;

#   "preserve",       meaning that no clean-up is done until the domain is

#                  manually destroyed (using xm destroy, for example); or

#   "rename-restart", meaning that the old domain is not cleaned up, but is

#                  renamed and a new domain started in its place.

#

# The default is

#

#   on_poweroff = 'destroy'

#   on_reboot   = 'restart'

#   on_crash    = 'restart'

 

xl create myvm.cfg  -c

 

xl list

xl console  myvm   => exit with Ctrl-]

vncviewer localhost:10  (where “10” is dom-id)
vncviewer  :10


Building Linux PV or HVM virtual machine


Similar to above, but can load kernel image from local FS (only for PV, not HVM):

kernel = "/boot/vmlinuz-id"
ramdisk = "/boot/initrd-id.img"
root = "/dev/xvda1 ro"

Can also use tap:aio for disk images.

file: uses dom0 kernel page cache, and thus might give better performance than phy: or tap:aio: (on drive images shared by multiple VMs), but it's also more insecure because of the caching.

tap:aio: uses direct IO, so it bypasses dom0 kernel caches, and works like phy: in that sense.

Do not mix file and  tap, may not work, at least in some versions of Xen.

# whole disk, may be partitioned
disk = [ "tap:tapdisk:aio:/path/images/disk.img,xvda,w" ]

# partitions, cannot be subpartitioned
disk = [ "tap:tapdisk:aio:/path/images/disk.img,xvda1,w" ]
disk = [ "tap:tapdisk:vhd:/path/images/disk.vhd,xvda2,w" ]
disk = [ "tap:qcow2:/path/images/disk.qcow2,xvda3,w" ]
disk = [ "tap:tapdisk:aio:/path/images/somedistro.iso,xvdb1,r" ]

in /etc/fstab:

/dev/xvda1               /                       ext3    defaults 1 1
/dev/xvda2               none                    swap    sw       0 0

QCOW2 is a QEMU format with delayed allocation of storage.
VHD is Microsoft VHD and provides an option for dynamic expansion (sparse storage).

Boot with NFS root

nfs_root = "/xen"
nfs_server = "192.168.2.12"
root = "/dev/nfs"

in /etc/fstab:
                /dev/nfs     /    ext3  defaults  1  1



Adding USB device permanently:

 

lsusb

 

Bus 003 Device 001: ID 0000:0000 

Bus 004 Device 001: ID 0000:0000 

Bus 005 Device 005: ID 4971:cb07 

Bus 005 Device 001: ID 0000:0000 

Bus 001 Device 006: ID 03f0:a004 Hewlett-Packard DeskJet 5850c

 

Add

 

#   Enable USB support (specific devices specified at runtime

#   through the monitor window)

usb=1

usbdevice=[ ‘host:03f0:a004’ ]

 

(and restart the domain)

 

Adding USB device temporarily:

 

Must use SDL, not VNC:

 

monitor=1

sdl=1

vnc=0

 

Ctrl-Alt-F2 to access QEMU

 

(HVMXen)  usb_add  host:03f0:a004
(HVMXen)  usb_del  host:03f0:a004

 

Ejecting CD ISO image in QEMU

(qemu) eject -f hdc
(qemu) change hdc /path/cd-rom-image.iso

xl  cd-insert  myvm  hdc  /path/image.iso,raw,hdc,cdrom
xl  cd-eject  myvm  hdc


Monitoring

xl info
xenmon
xentop  [--vbd]  [--vcpus]


Enabling RDP in Ubuntu

apt-get install xrdp  vino
/etc/init.d/xrdp start

mstsc … to Ubuntu machine

if desktop comes blank, create file ~/.xsession with content:

gnome-session –session=Ubuntu-2d

and  /etc/init.d/xrdp restart

vino-preferences => allow …

/etc/xrdp/xrdp.ini

 

# set empty username because VNC auth

# doesn't actually use username, so no

# point in asking the user for one.

 

[xrdp1]

name=Active Local Login

lib=libvnc.so

username=

password=ask

ip=127.0.0.1

port=5900

 

Client:  rdesktop