If you happen to have the need to run a software raid 1 setup with your xenserver install below are a simple step by step to get this working.
This setup assumes that during the install, you elected not to setup any storage repositories. I generally do that separately.
In the below, pay attention to — and ‘ as sometimes these characters get mangled during copy/pastes. Comments inline.
# Load required modules.
# WARNING: This will nuke everything on /dev/sdb.
sgdisk --zap-all /dev/sdb
sgdisk --mbrtogpt --clear /dev/sdb
# This will mirror /dev/sda partition tables to /dev/sdb and set the appropriate partition type.
sgdisk -R /dev/sdb /dev/sda
sgdisk --typecode=1:fd00 /dev/sdb
sgdisk --typecode=2:fd00 /dev/sdb
# create two raid mirrors, one for / and the other for swap.
mdadm --create /dev/md0 --level=1 --raid-devices=2 --metadata=0.90 /dev/sdb1 missing
mdadm --create /dev/md1 --level=1 --raid-devices=2 --metadata=0.90 /dev/sdb2 missing
# format and mount
mount /dev/md0 /mnt
# copy all files. note that if you make any changes on your system after this point they will be lost.
cp -xR --preserve=all / /mnt
# ensure that on boot the software raid gets assembled as expected.
mdadm --detail --scan > /mnt/etc/mdadm.conf
# actually mount /dev/md0 to /
sed -i 's/LABEL=[a-zA-Z\-]*/\/dev\/md0/' /mnt/etc/fstab
# The next several commands are centered around making sure we can actually boot into xenserver
mount --bind /dev /mnt/dev
mount -t sysfs none /mnt/sys
mount -t proc none /mnt/proc
chroot /mnt /sbin/extlinux --install /boot
dd if=/mnt/usr/share/syslinux/gptmbr.bin of=/dev/sdb
mkinitrd -v -f --theme=/usr/share/splash --without-multipath /boot/initrd-`uname -r`.img `uname -r`
sed -i 's/LABEL=[a-zA-Z\-]*/\/dev\/md0/' /mnt/boot/extlinux.conf
cd /mnt && extlinux --raid -i boot/
sgdisk /dev/sdb --attributes=1:set:2
# unmount the previously mounted.
cd && umount /mnt
Reboot, and within the bios set your machine to boot of /dev/sdb. Once xenserver starts up verify that you have booted to the proper disk by running a df -h.
You should see something like..
[root@orion ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/md0 4.0G 2.0G 1.8G 54% /
Once verified, run the following to resetup /dev/sda
# This will destroy the partition table on /dev/sda and mirror /dev/sdb
sgdisk -R /dev/sda /dev/sdb
sgdisk /dev/sda --attributes=1:set:2
# Add the disks to the existing pools
mdadm -a /dev/md0 /dev/sda1
mdadm -a /dev/md1 /dev/sda2
Now if you run
mdadm --detail /dev/md0 you can see that its syncing data from /dev/sdb.
You can point your swap to /dev/md1. Note that ideally you would never use swap. If for whatever reason you regularly plan to use swap space, doing this will impact performance.
also don’t forget to edit /etc/fstab and change it to use /dev/md1
mdadm --detail /dev/md0 until the state is clean then reboot again and this time boot from sda.
This completes the setup, and you have properly tested that you can boot cleanly from either drive.