Creating a new Xen VM in CentOS 5.1

I would recommend not using LVM within a VM because it makes it harder to back up the files within the VM

/usr/sbin/lvcreate -L 5G -n vm_testvm VolGroup00 #first create a logical volume for the machine
/usr/sbin/lvcreate -L 512M -n vm_testvm_swp VolGroup00 #create the LV swap file
/sbin/mkswap /dev/VolGroup00/vm_testvm_swp

An install source is needed: List of install media sites: (duke university worked: or )

To create a Centos 5.1 DomU, Run either /usr/sbin/virt-install or the graphical front end (same questions)

Here are the questions for virt-install

  • Full virtualization? <-- no
  • What is the name of your virtual machine? <-- testvm
  • How much RAM should be allocated (in megabytes)? <-- 512
  • What would you like to use as the disk (path)? <-- /dev/VolGroup00/vm_testvm
  • Would you like to enable graphics support? (yes or no) <-- yes note that this is only graphical support for the installer
  • What is the install location? <--
  • Note that during the guest install, you should remove default lvm partitioning and create one filesystem that completely fills the available drive. Ignore the swap warning, it will be added later. It should look like this:
    /dev/xvda1 /boot ext3 y 101 1 13
    /dev/xvda2 / ext3 y nnnn 14 nnnn
    where nnnn depends on the size of your LV

Post-install changes

  • After the first boot of the guest image, update fstab in the image to include the swap space:
    vi /etc/fstab
    /dev/xvdb swap swap defaults 0 0
    halt #Then shut down the guest os
  • In the host xen system, edit the /etc/xen/image file to shrink the ram(optional) and add the swap:
    vi /etc/xen/image
    disk = [ 'phy:/dev/VolGroup00/vm_testvm,xvda,w', 'phy:/dev/VolGroup00/vm_testvm_swp,xvdb,w' ]
  • The xen domains can be made to boot automatically when the host boots by simlinking them to /etc/xen/auto
    ln -s /etc/xen/www /etc/xen/auto/www
    /sbin/chkconfig xendomains on #tell the system to start them on next boot

Useful resource: