Skip to content

Configure XenServer 5.0 Free for Software RAID 1 + bootloader

by admin on August 2nd, 2010

To make this work, you need to drives in your system. The second drive must be identical or larger than the first, and you must have installed XenServer to the first drive without selecting the second drive as part of the storage pool.

Install XenServer as usual. Do not select any extra drives as storage pools.

After installation, boot up, and login into console 3 (Alt-F3) as root

type fdisk -l to list the partitions:

Most likely your disks are represented by SCSI device names under linux / XenServer 5.0

in that case your boot disk would be /dev/sda,

To copy the partition table from /dev/sda to /dev/sdb you can use dd

dd if=/dev/sda of=/dev/sdb bs=512 count=1

Now set the partition table up on /dev/sdb the way it should be for Linux RAID. This means setting the partition types to 0xfd.

I used the following command:

echo -e "\nt\n1\nfd\nt\n3\nfd\nw\nx" | fdisk /dev/sdb

That tells says to fdisk, “tag partition 1 as type 0xfd, tag partition 3 as type 0xfd”

Check to make sure the /dev/md? devices are present

[ -e /dev/md0 ] || mknod /dev/md0 b 9 0
[ -e /dev/md1 ] || mknod /dev/md1 b 9 1

Startup the degraded RAID devices

mdadm --create /dev/md0 --level=1 --raid-devices=2 missing /dev/sdb1
mdadm --create /dev/md1 --level=1 --raid-devices=2 missing /dev/sdb3

The following procedure is directly from the other guys notes. I’ve modified the commands to what I think works a little better.

pvcreate /dev/md1
volume_group=`vgscan | grep VG | awk -F \" '{print $2}'`
vgextend $volume_group /dev/md1
pvmove /dev/sda3 /dev/md1
# If this is a fresh install, then there won't be any data to move
vgreduce $volume_group /dev/sda3

Now we’re ready to copy the filesystem over to the RAID device /dev/md0

mkfs.ext3 /dev/md0
cd / && mount /dev/md0 /mnt && rsync -a --progress --exclude=/sys --exclude=/proc --exclude=/dev/shm --exclude=/dev/pts / /mnt
mkdir /mnt/sys
mkdir /mnt/proc
sed -r -i 's,LABEL=root-\w+ ,/dev/md0 ,g' /mnt/etc/fstab

Now let’s setup initrd

mkdir /root/initrd && cd /root/initrd
zcat /boot/initrd-`uname -r`.img | cpio -i && \
cp /lib/modules/`uname -r`/kernel/drivers/md/raid1.ko lib

Now we have to edit the init file

q="echo Waiting for driver initialization."
sed -r -i "s,^${q}$,\n\necho Loading raid1.ko module\ninsmod /lib/raid1.ko\n${q}\n,g" init
q="resume /var/swap/swap.001"
sed -r -i "s,^${q}$,${q}\necho Running raidautorun\nraidautorun /dev/md0\nraidautorun /dev/md1,g" init
r=`grep mkroot /root/initrd/init`
sed -r -i "s|^${r}$|${r/sda1/md0}|g" init

Now we’ll copy the initial ramdisk to the /boot on the new RAID

find . -print | cpio -o -c | gzip -c > /boot/initrd-`uname -r`.img
sed -r -i 's,LABEL=root-\w+ ,/dev/md0 ,g' /mnt/etc/fstab
sed -r -i 's,LABEL=root-\w+ ,/dev/md0 ,g' /etc/fstab

And setup the boot loader

sed -r -i 's,root=LABEL=root-\w+ ,root=/dev/md0 ,g' /mnt/boot/extlinux.conf
sed -r -i 's,root=LABEL=root-\w+ ,root=/dev/md0 ,g' /boot/extlinux.conf
cat /usr/lib/syslinux/mbr.bin > /dev/sdb
cd /mnt && extlinux -i boot/
extlinux -i boot/

If you’ve done this remotely, you can try the following.

cp /mnt/boot/extlinux.conf /boot/
cp /mnt/boot/initrd-`uname -r`.img /boot

Unmount /dev/md0sync, and reboot

cd ; umount /mnt || umount /dev/md0
sync
reboot

First we tag the partitions as type Linux raid, then we have to add /dev/sda to the RAID.

echo -e "\nt\n1\nfd\nt\n3\nfd\nw\nx" | fdisk /dev/sda
mdadm -a /dev/md0 /dev/sda1
mdadm -a /dev/md1 /dev/sda3

Troubleshooting

The first time I did this procedure I got stuck because my rsync didn’t copy /proc and /sys like I asked it not to. So I had to add the step of creating those two directories so they could be mounted at boot.

After messing around with it a little, I came up with this command line to boot XenServer 5 from extlinux.

mboot.c32 /boot/xen.gz dom0_mem=752M --- /boot/vmlinuz-2.6-xen root=/dev/md0  single --- /boot/initrd-2.6-xen.img
8 Comments
  1. Rhys permalink

    Beware, an error on one of the commands causes the reboot process to fail. The line:

    find . -print | cpio -o -c | gzip -c > /boot/initrd-`uname -r`.img

    Should read:

    find . -print | cpio -o -c | gzip -c > /mnt/boot/initrd-`uname -r`.img

    With that change in place this helped me tremendously. many thanks.

  2. admin permalink

    You’re right. Thanks.

  3. Digital permalink

    I have an error with the command “mdadm -a /dev/md0 /dev/sda1”.
    The error message is mdadm: error opening /dev/md0: No such file or directory. I dont know what I did wrong, because every commands before were okay.

  4. admin permalink

    hello,

    have you checked if the device is present? :
    [ -e /dev/md0 ] || mknod /dev/md0 b 9 0
    and create the raid device ?:
    mdadm –create /dev/md0 –level=1 –raid-devices=2 missing /dev/sdb1

  5. Digital permalink

    I’ve tried it, but it still doesn’t work.

  6. admin permalink

    please provide output from :
    ls -la /dev/md0
    cat /proc/mdstat

  7. A Almosawi permalink

    is it possible you can make this work with 4 drives? can you show what needs to be adjusted in the script above?

    thanks!

    (please email response to my email above.)

  8. admin permalink

    for four drives you have to repeat steps for sdb drive to sdc and sdd drives:
    partition all other 2 drives..
    dd if=/dev/sda of=/dev/sdb bs=512 count=1
    add
    dd if=/dev/sda of=/dev/sdc bs=512 count=1
    dd if=/dev/sda of=/dev/sdd bs=512 count=1

    and

    echo -e “\nt\n1\nfd\nt\n3\nfd\nw\nx” | fdisk /dev/sdb
    echo -e “\nt\n1\nfd\nt\n3\nfd\nw\nx” | fdisk /dev/sdc
    echo -e “\nt\n1\nfd\nt\n3\nfd\nw\nx” | fdisk /dev/sdd

    also change lines where creating the array:

    mdadm –create /dev/md0 –level=1 –raid-devices=2 missing /dev/sdb1
    change to :
    mdadm –create /dev/md0 –level=1 –raid-devices=4 missing /dev/sdb1 /dev/sdc1 /dev/sdd1
    and
    mdadm –create /dev/md1 –level=1 –raid-devices=2 missing /dev/sdb3
    change to:
    mdadm –create /dev/md1 –level=1 –raid-devices=4 missing /dev/sdb3 /dev/sdc3 /dev/sdd3

    or even you can create a raid10 for /dev/md1 with four drives:

    mdadm –create /dev/md1 –level=10 –raid-devices=4 missing /dev/sdb3 /dev/sdc3 /dev/sdd3

    the rest of the configurations should be the same

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS