This adapded article is based on the following Debian Wiki article:
http://wiki.debian.org/PyGrub
In this article I assume:
– The reader is familiar with Linux and Xen Hypervisor
– The DOMu system partition is using a file image instead of a physical partition.
Introduction:
This method offers the advantage of loading the kernel which is installed in the DOMu. For this we use a Python script(/usr/lib/xen-default/bin/pygrub) which is located on DOM0. It understands the EXT3 filesystem of DOMu, loads and starts the Kernel(vmlinuz) and Ramdisk(initrd.img) files from DOMu defined in its Grub legacy configuration file(/boot/grub/menu.lst).
Prerequisites:
– The DOMu filesystem is EXT3
– The disk devices are using the format ‘xvda1/2/3…’
– The system image is the first listed in the DOMu xen configuration file.
Example:
root = '/dev/xvda1 ro'
disk = [
'file:/xen/VMS/disk.img,xvda1,w',
'file:/xen/VMS/disk.swp,xvda2,w',
]
On the DOMu:
Start the DOMu as done before and:
Make sure in the DOMu /etc/fstab that the mount points refer to /dev/xvd{a,b}1, /dev/xvd{a,b}2, …..
Example:
/dev/xvda1 / ext3 noatime,nodiratime,errors=remount-ro,usrquota,grpquota 0 1
/dev/xvda2 none swap sw 0 0
For Debian Squeeze DOMu install the Debian grub-legacy and latest kernel packages:
aptitude install grub-legacy linux-image-2.6-xen-amd64
For Debian Wheezy DOMu use this command:
aptitude install linux-image-amd64 grub-legacy
Create the pyGrub configuration file based on the system storage device (/dev/xvda1):
mkdir /boot/grub
vim /boot/grub/menu.lst
Content:
default 0
timeout 2
#
title Debian GNU/Linux
root (hd0,0)
kernel /vmlinuz root=/dev/xvda1 ro
initrd /initrd.img
#
title Debian GNU/Linux (recovery mode)
root (hd0,0)
kernel /vmlinuz root=/dev/xvda1 ro single
initrd /initrd.img
Stop DOMu.
halt
IMPORTANT: After every kernel update in the DOMU Debian tries to overwrite this file.
After each Kernel update issue the following commands:
mv /boot/grub/menu.lst /boot/grub/menu.lst.debian
mv /boot/grub/menu.lst~ /boot/grub/menu.lst
Reason: After a kernel upgrade the install script recreates its own grub.lst file which is not compatible with pygrub.
In DOM0:
Check that grub was properly installed on the domU. For DOM0 in Debian Squeeze with the command:
/usr/lib/xen-default/bin/pygrub /xen/VMS/disk.img
If your DOM0 is Debian Wheezy, then use this command instead:
/usr/lib/xen-4.1/bin/pygrub /xen/VMS/disk.img
This should give you a Grub boot menu as if the system will start but will kick out a couple of sec later with an error message. Ignore the error message, the presence of the boot menu was the indicator that everything is ready in the DOMu.
Replace the older kernel and ramdisk lines in the Xen DOMu configuration file as follows:
Example:
REPLACE:
kernel = '/boot/vmlinuz-2.6.32-5-xen-amd64'
ramdisk = '/boot/initrd.img-2.6.32-5-xen-amd64'
WITH:
bootloader = '/usr/lib/xen-default/bin/pygrub'
For Debian Wheezy, use the following entry instead.
bootloader = '/usr/lib/xen-4.1/bin/pygrub'
That was it. Now start the DOMu.