Virtualization with Xen


https://help.ubuntu.com/community/Xen

Utilization

Useful Commands

 xm list

List all domU

 xm create foo.cfg

Creates (boots) a new domU named foo (/etc/xen/foo.cfg)

 xm console foo

Use **CTRL+]** to release the console when done

Installation

Server

 - Install Ubuntu Server using PXE
 - sudo aptitude install ubuntu-xen-server
 - edit /etc/xen/xend-config.sxp and be sure to have: (network-script network-bridge)
 - edit /etc/modules and increment the number of loop devices: loop max_loop=64
 - reboot 

Setup

Create a new Guest

 - edit /etc/xen-tools/xen-tools.conf and pay attention to the defaults
 - export $VMHOST="chatter.public.example.net"
 - run `xen-create-image --hostname=$VMHOST --ip=xx.xx.xx.xx`
 - edit /etc/xen/$VMHOST.cfg and '''s/file:/tap:aio:/'''
 - run `xm create -c /etc/xen/chatter.public.example.net.cfg`

Note that **-c** attaches to the console to return back to the host do **CTRL+]**

After logging in, make sure to set a password for the root user.

   vi /etc/xen-tools/xen-tools.conf 
   xen-create-image --hostname=chatter.public.example.net --ip=192.168.0.231
   General Information
   --------------------
   Hostname       :  chatter.public.example.net
   Distribution   :  hardy
   Partitions     :  swap            1024Mb (swap)
                     /               4Gb   (xfs)
   Image type     :  sparse
   Memory size    :  2048Mb
   Kernel path    :  /boot/vmlinuz-2.6.24-22-xen
   Initrd path    :  /boot/initrd.img-2.6.24-22-xen
   Networking Information
   ----------------------
   IP Address 1   : 192.168.0.231 [MAC: 00:16:3E:73:C8:68]
   Netmask        : 255.255.255.0
   Broadcast      : 192.168.0.255
   Gateway        : 192.168.0.1
   Creating partition image: /var/xen/domains/chatter.public.example.net/swap.img
   Done
   Creating swap on /var/xen/domains/chatter.public.example.net/swap.img
   Done
   Creating partition image: /var/xen/domains/chatter.public.example.net/disk.img
   Done
   Creating xfs filesystem on /var/xen/domains/chatter.public.example.net/disk.img
   Done
   Installation method: debootstrap
   Done
   Running hooks
   Done
   No role scripts were specified.  Skipping
   Creating Xen configuration file
   Done
   All done
   Logfile produced at:
            /var/log/xen-tools/chatter.public.example.net.log

Automatically Start Guest

 - cd /etc/xen/auto
 - ln -s ../chatter.public.example.net.cfg .

Configuration

Grub2

grub-pc on Ubuntu/Debian

This mostly applies to Ubuntu Karmic

create /etc/grub.d/09_xen with

   menuentry "Xen 3.3" {
       multiboot (hd0,1)/xen-3.2-1-amd64.gz dom0_mem=256M
       module (hd0,1)/vmlinuz-2.6.18-5-xen-amd64 root=/dev/sda2 ro
       module (hd0,1)/initrd.img-2.6.18-5-xen-amd64
   }

To display the menu you will need to edit /etc/default/grub with

   GRUB_DEFAULT=0
   #GRUB_HIDDEN_TIMEOUT=0
   GRUB_HIDDEN_TIMEOUT_QUIET=false
   GRUB_TIMEOUT="10"
   GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
   GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,9600n8"
   GRUB_CMDLINE_LINUX=""
   ...

Multiple Network Cards

Say you have 2 physical network ports and you need to have your domU (guests) on both of those interfaces:

 - create a script called /etc/xen/scripts/multi-interface-bridge 
   dir=$(dirname "$0")
   "$dir/network-bridge" "$@" vifnum=0 netdev=eth0
   "$dir/network-bridge" "$@" vifnum=1 netdev=eth1
 - edit /etc/xen/xend-config.sxp 
   (network-script 'multi-interface-bridge')
 - edit /etc/xen/chatter.public.example.net.cfg 
   vif         = [ 'ip=192.168.1.28,mac=00:16:3E:23:4E:05,bridge=eth1', 'ip=192.168.0.28,mac=00:16:3E:23:4E:06,bridge=eth2' ]
 - Then restart Xend 
   /etc/init.d/xendomains stop; /etc/init.d/xend restart; /etc/init.d/xendomains start

Advertisement