Sunday, December 16, 2007

First Impressions with Xen

I've been a VMware boy for years. I started with at least Workstation 3, probably Workstation 2. I think they have an excellent product. VMware Infrastructure is quite amazing and VMware server is a great free product.


I've been half heartedly trying to get Xen vm's up for the past couple of weeks. I haven't really read documentation -- I've mostly been googling around for instructions. Most of what I have done is based on the CentOS Wiki.

I finally got a VM going this morning. I ran into trouble in a few areas. First, I couldn't get xen to mount virtual disks. That problem turned out to be a corrupted install.

My second problem had to do with network interfaces. The VM would boot, but it couldn't find the network card to do the install over. Some of the documentation said to set vif0= in the config file. It turns out that in the version I'm using, it's vif=. I don't know if it changed recently, but changing it solved my problem.

So, this is what I did:
  1. On my CentOS 5 machine, I made sure that xen-libs, kernel-xen, xen-devel and xen were all installed.
  2. I downloaded the kernels from http://mirror.centos.org/centos/5/os/i386/images/xen/ and put them in /var/xen/kernels/i386/
  3. I created a new lvm partition, /var/xen/, to hold images and kernels, etc.
  4. I made sure xend was set to boot on start (chkconfig --level 2345 xend on)
  5. I rebooted, making sure I was booting into the xen kernel
  6. I created my disk image with dd if=/dev/zero of=/var/xen/test.img oflag=direct bs=1M seek=4096 count=1
  7. I created a kickstart file like the one below and put it on a webserver:

    install
    url --url http://mirror.centos.org/centos/5/os/i386
    lang en_US.UTF-8
    network --device eth0 --bootproto dhcp
    # Bogus password, change to something sensible!
    rootpw bogus
    firewall --enabled --port=
    authconfig --enableshadow --enablemd5
    selinux --enforcing −−port=22:tcp
    timezone --utc Europe/Amsterdam
    bootloader --location=mbr --driveorder=xvda --append="console=xvc0"
    reboot

    # Partitioning
    clearpart --all --initlabel --drives=xvda
    part /boot --fstype ext3 --size=100 --ondisk=xvda
    part pv.2 --size=0 --grow --ondisk=xvda
    volgroup VolGroup00 --pesize=32768 pv.2
    logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow
    logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=256 --grow --maxsize=512

    %packages
    @core
  8. The xen install config file looks like
    kernel = "/var/xen/kernels/i386/vmlinuz"
    ramdisk = "/var/xen/kernels/i386/initrd.img"
    extra = "text ks=http://the webserver you uploaded to/test.cfg"
    name = "test"
    memory = "512"
    disk = [ 'tap:aio:/var/xen/test.img,xvda,w' ]
    vif = [ '' ]
    vcpus=2
    on_reboot = 'destroy'
    on_crash = 'destroy'

    Put it in /etc/xen/test. Be sure to replace the correct webserver name.
  9. Start the install with xm start test. You can watch it with xm console test
  10. When it's done, overwrite your config file with the following:

    name = "test"
    memory = "512"
    disk = [ 'tap:aio:/var/xen/test.img,xvda,w' ]
    vif = [ '' ]
    vcpus=2
    on_reboot = 'restart'
    on_crash = 'restart'
    bootloader="/usr/bin/pygrub"
  11. Boot it back up with xm create test. When you want to turn it off, run xm destroy test. That doesn't actually destroy your file, it only turns off the vm.
BTW, I highly recommend *not* running /etc/xen/scripts/network-bridge stop on a remote system. Bad things will happen. Lesson learned.

Comparing to VMware Server, xen seems way better. VMware Server doesn't handle load well and tends to make everything slow on a moderately loaded server. That is why I wanted to give Xen a go instead. Xen feels a lot more like ESX (which makes sense being a similar sort of hypervisor). 

2 comments:

Jason Antman said...

Congrats on getting Xen working.

I also started out with VMware, but I've found that when running Linux on Linux, Xen seems to have much better performance. It also has the wonderful feature of being fully manageable from the command line, so it works great for virtualizing servers.

Gary said...

Actually, vmware does have command line management tools, at least Server and ESX do. They even have an API (I haven't played with the API, but I have used the command line tools).