System Rescue CD Xen

Booting into a livecd using Xen as a para-virtualized guest is impossible with just the ISO alone. Xen does provide CD support, but a kernel is still required to boot into an OS. That's accomplished by extracting the kernel from the ISO first, and then into the image.

In the examples below, here's the filesystem structure I use in this guide:

  • /mnt/iso - temporary mount directory for ISO
  • /etc/xen/configs/sysresccd - Xen guest configuration file
  • /etc/xen/kernels/sysresccd/ - directory for kernel, initrd files
  • /etc/xen/isos - directory for livecd ISOs

Another consideration is that I only cover the amd64 kernel here.

Before anything else, get the kernel and initrd that the live CD uses. Mount the ISO as a loop device, and read-only:

mkdir /mnt/iso
mount -o loop,ro systemrescuecd-x86-4.8.0.iso /mnt/iso
cp /mnt/iso/rescue64 /mnt/iso/altker64 /mnt/iso/initram.igz /etc/xen/kernels/sysresccd

That's all that's needed from the ISO here, so it can be unmounted.

umount /mnt/iso

Next, you will need to boot into a SystemRescueCd ISO somewhere else, so that you can go through the build process of creating a custom ISO. This guide will cover only a few of all the possible steps provided in their instructions, to get a Xen guest ISO up and running only.

Boot into the livecd, and mount a drive at /mnt/custom so that you can start to build your own.

mount /dev/sdaX /mnt/custom

On the ISO, there is a file named sysrcd.dat. This is where the actual contents of the OS are when booting the CD. Everything else that you may see on the ISO is related to the bootloader as well as some other tools. It's this sysrcd.dat file that will be rebuilt.

Fortunately, sysresccd ships with some good tools to make this easy. Extract the contents of the image to /mnt/custom:

sysresccd-custom extract

When that's done, there are only two files that will need to be modified on our custom filesystem.

Edit /mnt/custom/customcd/files/etc/init.d/fixinittab and insert a line for the Xen console in the start function, before telinit q is called:

echo "c0:2345:respawn:/sbin/agetty 38400 hvc0 linux" >> /etc/inittab

The second file to be modified is /mnt/custom/customcd/files/etc/securetty. Here, add an entry for hvc0 at the end of the file. This will enable the root user to log in at the prompt.


That's it for all the changes!

Now, build your new customized sysrcd.dat file:

sysresccd-custom squashfs

And finally, the complete ISO (with a custom volume name):

sysresccd-custom isogen beandog

Your final ISO will be found in /mnt/custom/customcd/isofile.

That solves the problem of creating a Xen-guest-friendly ISO, but we still need to create a configuration file for Xen to use.

We'll walk through the settings.

When booting a guest, there are two options – either use a bootloader such as pygrub or pvgrub (for examples), or pass a kernel directly to boot off of. Here, we use the kernel and initrd extracted from the ISO earlier.

Here's the start of /etc/xen/configs/sysresccd:

name = 'sysresccd'
kernel = '/etc/xen/kernels/sysresccd/altker64'
ramdisk = '/etc/xen/kernels/sysresccd/initram.igz'

The Xen guest emulates a CD drive, and we attach the ISO to the block device that it would have in it. You can specify the emulated device name. In this case, I'm using xvdc.

disk = ['file:/etc/xen/isos/sysresccd-20160714-2242.iso,xvdc:cdrom,r']

If you're adding other drives to access from the CD (which you most likely are), then you'll need to tell the config to boot from the CD drive first:

boot = 'c'

Booting off of that will now get you a console on a Xen guest with a login prompt. SystemRescueCd will scramble the root password by default, so you cannot log in as user root directly from the console. We can work around that by passing kernel parameters to the kernel that will then be processed by the OS, and allow you to log in with that user.

There's lots of other options you can pass as kernel parameters (see here). In this case, set the password to rescue, by adding this to the Xen guest config file:

extra = 'rootpass=rescue'

Boot into the ISO, and you'll now be good to go!

xl create /etc/xen/configs/sysresccd -c

From the kernel parameters earlier, one way you can make your life simpler is by having the OS send a DHCP request to get on the network. Just add dohcp to the extra parameters as well as setting the root password, then you could SSH into the new guest.

As a final note, here's an example working Xen guest configuration file that I use.

name    = 'sysresccd'
kernel  = '/etc/xen/kernels/sysresccd/altker64'
ramdisk = '/etc/xen/kernels/sysresccd/initram.igz'
extra   = 'dodhcp setkmap=us scandelay=5 rootpass=rescue'
disk    = ['phy:/dev/vg0/lvol0,xvda,rw','file:/tmp/sysresccd-20160714-2331.iso,xvdc:cdrom,r']
boot    = 'c'
memory  = 1024
vcpus   = 1
vif     = ['bridge=br0']