XEN vmachine howto

I wanted to create a Linux guest in XEN, this is how i did it i could go two ways, rpm based OR debian based

  • rpm based
  1. create the disk "data disk" on which the guest will be installed

    this could be either an raw disk (lvm or partition or disk) or a simple file

  2. create filesystem on this disk using mke2fs
  3. create another disk for the guest machine swap
  4. mount the "data disk" for example /mnt/xenguest
  5. yum --installroot=/mnt/xenguest groupinstall base
  6. edit /mnt/xenguest/etc/network/interfaces and put in the following
  7. auto lo
    iface lo inet loopback
    auto eth0
    iface lo inet dhcp
  8. edit /mnt/xenguest/etc/fstab
  9. proc /proc proc defaults 0 0
    /dev/hda1 / ext3 defaults,errors=remount-ro 0 1
    /dev/hda2 none swap sw 0 0
  10. unmount the "data disk"
  11. create the xen cfg file in /etc/xen/xenguest_1
  12. kernel = "/boot/vmlinuz-2.6.11-xenU"
    memory=128
    name = "domu1"
    vif = [' bridge=xen-br0' ]
    disk = ['phy:/path/to/disk,hda1,w','phy:/path/to/swap,hda2,w']
    root = "/dev/hda1 ro" extra = "4"
  13. xm create -c xenguest_1
  • Debian based, do this istead of step 4: debootstrap sarge /mnt/xenguest

How to create a data disk using lvm:

  1. pvcreate /dev/hda5
  2. vgcreate lvmxen /dev/hda5
  3. vcreate -L1G -n domu1 lvmxen
  4. vcreate -L256M -n domu1-swap lvmxen
  5. mke2fs /dev/lvmxen/domu1
  6. tune2fs -j /dev/lvmxen/domu1

How to create a data disk using files:

  1. dd if=/dev/zero of=/mnt/xenguest.img bs=1 count=0 seek=25G
  2. dd if=/dev/zero of=/mnt/xenguestswap.img bs=1G count=1
  3. mke2fs /mnt/xenguest.img
  4. tune2fs -j /mnt/xenguest.img
  5. disk = ['file:/mnt/xenguest.img,hda1,w','file:/mnt/xenguestswap.img,hda2,w']

Else just use a /dev/xxx device directly

 

References:

http://wiki.xensource.com/xenwiki/DebianDomU

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