Debian guest on CentOS host

The explanation below details the installation of a Debian guest on a Xen host running the CentOS/Red Hat Enterprise Linux 5 kernel. The Debian guest is installed in a logical volume, but with minor adjustments, a file-based image can be booted as well.

To get a Debian guest running on an CentOS host, you first need a Debian image file. If you have a running Debian system, do this as follows:

  $ dd if=/dev/zero of=etch_img count=1024 bs=$[1024*1024]
  $ sudo mkfs.ext3 etch_img
  $ sudo mkdir deb_mnt
  $ sudo mount -o loop etch_img ./deb_mnt
  $ sudo debootstrap --arch x386 etch deb_mnt \

After it's done, unmount and copy the file to your CentOS Xen Host.

I haven't gotten the stock CentOS Xen-enabled kernel running with the Debian guest. So download a ready-built Xen kernel from

  $ wget

or for a 64-bit machine:

  $ wget

After downloading, unpack it in a special place. I suggest /opt, but some others use the /usr/local directory.

Mount the image again:

  $ sudo mkdir deb_mnt
  $ sudo mount -o loop etch_img ./deb_mnt

Copy the /boot and /lib/modules directories from the Xen package to the virtual machine:

  $ sudo cp -r /opt/xen-3.0.2-2-install/install/lib/modules/2.6.16-xen \
  $ sudo cp -r /opt/xen-3.0.2-2-install/install/boot/* deb_mnt/boot

Edit the etc/fstab file and add the following lines:

  /dev/xvda1      /       ext3    errors=remount-ro,noatime   0   1
  proc            /proc   proc    defaults                    0   0
  /swapfile0      swap    swap    defaults                    0   0

Note that the 'noatime' option and the swapfile (instead of a swap partition) are things that aren't necessary, but just personal taste.

Edit the boot/grub/menu.lst file, and adjust the contents as follows:

  title Debian
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.16-xen ro root=/dev/xvda1

Unmount the image:

  $ sudo umount deb_mnt

Create a logical volume for the Debian guest to use:

  $ sudo lvcreate -L 2G -n debian_lv vg0 

Partition the new logical volume:

  $ sudo fdisk /dev/vg0/debian_lv

After adding one or more partitions, write the new table and create new devices pointing to the partitions:

  $ sudo kpartx -a /dev/vg0/debian_lv

Copy the image file to the partition and resize the file system to the full size that the partition allows:

  $ sudo cp deb_img /dev/mapper/debian_lv1
  $ sudo resize2fs /dev/mapper/debian_lv1

Create a new Xen configuration file for the Debian virtual machine, preferably in the /etc/xen directory, or if you want to start it up automatically when booting the physical host, in the /etc/xen/auto directory.

  name = "debian"
  memory = "64"
  # If you want to use the image file, uncomment the line below and
  # of course comment the other disk line.
  # disk = [ 'file:/home/user/deb_img,xvda1,w', ]
  disk = [ 'phy:/dev/vg0/staff_lenny,xvda,w', ]
  vif = ['mac=00:16:3e:7b:8e:61, bridge=xenbr0, vifname=x.len0', ]
  vfb = ["type=vnc,vncunused=1"]
  uuid = "076f8df4-f2a3-452d-a628-fab3c9fbe913"
  on_reboot   = 'restart'
  on_crash    = 'restart'

Now start the Debian guest:

  $ sudo xm create -c /etc/xen/debian

Upon the login prompt, type 'root' as the username and press enter when asked for a password.

What remains is to set the root password and fix networking by adding the following lines to /etc/network/interfaces:

  auto lo
  iface lo inet loopback
  auto eth0
  iface eth0 inet static
  address x.x.x.x
  broadcast x.x.x.255
  gateway x.x.x.1
  network x.x.x.0

Add nameservers to /etc/resolv.conf and bring up the interfaces:

  # ifup eth0
  # ifup lo

See if you can install the sshd daemon:

  # apt-get install ssh

If this works, you've got networking. You should also be able to ssh into the Debian host from the outside.