Paravirtualized Gentoo Linux on Citrix XenServer

Important version numbers: Gentoo 12.0, XenServer 6.0 This post is about installing a not too supported Linux distribution – Gentoo as a paravirtualized machine to XenServer. It works also on servers not supporting HVM (hardware virtualization)


  • Installed Citrix XenServer
  • Other Linux virtual machine (i.e. Debian is easy to install)

Preparing the VM

  1. Create a new VM with “Other install media”, “Boot from network” and at least a 10G disk
  2. Get the new VM’s UUID with the command xe vm-list and search for it. Mine is 103e5d60-7412-748f-7219-4a7ce685e640, let’s call it [UUID]
  3. Change VM type to Paravirtualized (PV)

    xe vm-param-set uuid=[UUID] HVM-boot-policy=""

  4. Set the PV boot options (some values are later self-explained)

    xe vm-param-set uuid=[UUID] PV-bootloader=""
    xe vm-param-set uuid=[UUID] PV-kernel="/boot/guest/kernel_xen-2.6.38"
    xe vm-param-set uuid=[UUID] PV-args="console=tty1 xencons=tty \
    root=/dev/xvda raid=noautodetect"

  5. Restart XenCenter (the GUI). It is necessary to update the console to realize that the VM is paravirtualized.

Installing Gentoo

A slightly modified Gentoo installation follows. Let’s call the other VM debian and the new one gentoo. The difference is that we don’t have to care about booting, because it is made by the XenServer. In this example, I don’t use partitioning – I use the whole disk as a large block device.

  1. Disconnect the new VM’s hard drive and connect it to an existing VM. We assume that it will be device /dev/xvdb (We will operate on the disk.)
  2. Format the drive

    mkfs.ext3 /dev/xvdb

  3. Mount the disk.

    debian# mount /dev/xvdb /mnt/gentoo

  4. Install Stage3 and Portage.

    debian# cd /mnt/gentoo
    debian# wget\
    debian# wget\
    debian# tar xjvpf stage3-amd64-20120308.tar.bz2
    debian# mv portage-* usr/
    debian# cd usr/
    debian# tar xjvpf portage-*
    debian# rm portage-*
    debian# cd ..
    debian# rm stage3-*

  5. Create necessary /dev nodes.

    cd /mnt/gentoo/dev
    mknod -m 660 xvda b 202 0
    mknod -m 660 xvda1 b 202 1
    mknod -m 660 xvda2 b 202 2
    mknod -m 660 xvda3 b 202 3
    mknod -m 660 xvda4 b 202 4
    mknod -m 660 xvdb b 202 16
    mknod -m 660 xvdb1 b 202 17
    mknod -m 660 xvdb2 b 202 18
    mknod -m 660 xvdb3 b 202 19
    mknod -m 660 xvdb4 b 202 20

  6. chroot! mount -t proc proc /mnt/gentoo/proc
    mount --rbind /dev /mnt/gentoo/dev
    cp -L /etc/resolv.conf /mnt/gentoo/etc/
    chroot /mnt/gentoo /bin/bash
    env-update && source /etc/profile

  7. Install xen-sources (the Xen optimized kernel) and some basic applications.

    emerge --sync
    emerge xen-sources syslog-ng vixie-cron app-misc/screen vim mirrorselect

  8. Prepare a kernel. This is a bit tricky. Basically, I recommend to turn off modules support, for the kernel to be more transferrable to other machines. I’ve prepared a config file that works. KConfig_default or KConfig_with-nfsd-cifs. After that, compile the kernel.

    chroot# cd /usr/src/linux/
    chroot# make menuconfig
    ; select Load config file
    chroot# make

  9. Configure some basic things and set the root password.

    chroot# cp /usr/share/zoneinfo/Europe/Bratislava /etc/localtime
    chroot# echo "Europe/Bratislava" > /etc/timezone
    chroot# vim /etc/fstab
    /dev/xvda / ext3 noatime 0 1
    /dev/cdrom /mnt/cdrom auto noauto,ro 0 0
    chroot# mirrorselect -i -o >> /etc/make.conf
    chroot# mirrorselect -i -r -o >> /etc/make.conf
    chroot# echo 'MAKEOPTS="-j3"' >> /etc/make.conf
    chroot# nano -w /etc/locale.gen
    chroot# locale-gen
    chroot# passwd

  10. Tell the system that we’re in domU

    sed -i -e 's/#*rc_sys=""/rc_sys="xenU"/' /etc/rc.conf

  11. Unchroot and umount disks.

    debian# umount -l /mnt/gentoo/dev{/shm,/pts,}
    debian# umount -l /mnt/gentoo{/proc,}

  12. Detach disk from debian, attach it to gentoo and start it. Good Luck! I’m looking forward to your comments.

  • sam

    Him with this settings, have you the “nx” bit enable on cat /proc/cpuinfo ?

    I try to made it available with no success…