XCP/XenServer on RAID1: booting pitfalls
Getting XCP to boot from a RAID1 partition has been worked out in a nice article: http://blog.codeaddict.org/?p=5
I discovered a few things on the way:
parteddoes nasty things to the boot configuration, and
- what to do if the XCP install becomes unbootable;
- how to bootstrap if the BIOS won't allow you to select a boot disk and you don't want to swap cables
If the XCP install will not enter
extlinux or boot the kernel
It turns out that using
parted for any of the partitioning work will do at least two of: overwrite the MBR, unset the root partition's legacy BIOS bootable flag and otherwise foul the
Aside from following the cookbook, there are a few things to check to ensure the system is bootable. This setup should ensure that XCP will boot even with a root disk missing.
Be sure the MBR is installed.
Outlined in the cookbook, but it doesn't hurt to do it again if the partition configuration has changed at all.
dd if=/usr/share/syslinux/gptmbr.bin > /dev/sda dd if=/usr/share/syslinux/gptmbr.bin > /dev/sdb
Be sure the boot partition's bootable flag is set
extlinux will not consider a boot partition without the bootable flag set. If any partitions are modified with
parted, it will clear any bootable flags. Set the flag and check it for both partiions:
sgdisk --attributes=1:set:2 /dev/sda # set the flag for sda sgdisk --attributes=1:show /dev/sda # show the flag for sda sgdisk --attributes=1:set:2 /dev/sdb # set the flag for sdb sgdisk --attributes=1:show /dev/sdb # show the flag for sdb
It doesn't hurt to install extlinux repeatedly, so do it again after any partitioning.
The codeaddict.org cookbook doesn't mention the
--raid flag to
extlinux: if the MBR on
sda is ok, but the filesystem on
sda1 is corrupt (or the bootable flag was accidentally wiped!), it will try the next disk.
Be sure that at least
/dev is mounted on
/mnt/dev before running this.
chroot /mnt extlinux -i -r /boot
extlinux boots linux, but linux cannot mount the root partition
There are a few things to check here.
Check the partition's RAID flag
If the partition's RAID flag is not set, the kernel will not automatically assemble the RAID array. Install the flag:
sgdisk --typecode=1:fd00 /dev/sda # set the flag for sda1 sgdisk --info=1 /dev/sda # check first line for 'Linux RAID' sgdisk --typecode=1:fd00 /dev/sdb # set the flag for sdb1 sgdisk --info=1 /dev/sdb # check first line for 'Linux RAID'
Be sure that the root device is specified correctly as
root=/dev/md0 in the
label xe section,
Check the initrd
Build a new initrd, ensuring that the RAID1 kernel module is included.
Assuming the XCP root filesystem is mounted on
mkinitrd -v -f --without-multipath --fstab=/mnt/etc/fstab \ /mnt/boot/initrd-`uname -r`.img `uname -r`
Be sure you see a line
Adding module raid1 near the end of the output.
What to do if you get stuck
The install may be rescued using the XCP install image.
Boot the XCP install image.
When presented with the keyboard selection screen, switch to the shell <Alt>-<F2>
Mount half of the mirror read-only and copy the mdadm tool into the miniroot.
mkdir /mnt mount -o ro /dev/sda1 /mnt cp /mnt/sbin/mdadm.static /sbin/mdadm umount /mnt
Assemble the RAID array, and mount it and the supporting filesystems.
mdadm --examine --scan > /etc/mdadm.conf mdadm -A /dev/md0 mount /dev/md0 /mnt mount -o bind /dev /mnt/dev mount -o bind /sys /mnt/sys # and optionally, chroot /mnt
Perform needed repairs
At this point, the system is ready to execute any of the commands listed in earlier sections.
When finished, be sure to unmount things, because XCP doesn't know how.
umount /mnt/dev umount /mnt/sys umount /mnt
Please post any problems or success stories in the comments below. Thanks for reading.