Xenserver 6.2 software raid 1 with mdadm

5 years ago by in cycling Tagged: , ,

mdadm software raid Raid 1 Xen 6.2

After initial installation of Xenserver 6.2 (DO NOT configure any local storage!)

Check /dev/sda partition table
# gdisk -l /dev/sda
Number Start (sector) End (sector) Size Code Name
1 2048 8388641 4.0 GiB 0700
2 8390656 16777249 4.0 GiB 0700

Prepare second drive for GPT:
sgdisk –zap-all /dev/sdb
sgdisk –mbrtogpt –clear /dev/sdb

After listing the sdb partition with sgdisk we will get info:
sgdisk -p /dev/sdb
Disk /dev/sdb: 250069680 sectors, 119.2 GiB    –> this is DISK_SIZE !
First usable sector is 34, last usable sector is 250069646

We need to make sure the size is exactly the same as on sda:
sgdisk –new=1:2048:8388641 /dev/sdb
sgdisk –typecode=1:fd00 /dev/sdb
sgdisk –attributes=1:set:2 /dev/sdb
sgdisk –new=2:8390656:16777249 /dev/sdb
sgdisk –typecode=2:fd00 /dev/sdb
sgdisk –new=3:16779264:DISK_SIZE-34 /dev/sdb
sgdisk –typecode=3:fd00 /dev/sdb

in my case DISK_SIZE-34 is 250069680-34=16779264
Pay attention if sgdisk says the kernel is still using the old partition table. You need to reboot if that is the case.

Now it is time (REboot if needed) to create the software RAID devices.

mknod /dev/md0 b 9 0
mknod /dev/md1 b 9 1
mknod /dev/md2 b 9 2
mdadm –create /dev/md0 –level=1 –raid-devices=2 missing /dev/sdb1
mdadm –create /dev/md1 –level=1 –raid-devices=2 missing /dev/sdb2
mdadm –create /dev/md2 –level=1 –raid-devices=2 missing /dev/sdb3

Create bitmaps for each RAID device:

mdadm –grow /dev/md0 -b internal
mdadm –grow /dev/md1 -b internal
mdadm –grow /dev/md2 -b internal

Format the RAID root disk, mount it at /mnt and copy all to it

mkfs.ext3 /dev/md0
mount /dev/md0 /mnt
cp -vxpR / /mnt

Modify /mnt/etc/fstab and change root filesystem to /dev/md0
sed -i ‘s/LABEL=[a-zA-Z\-]*/\/dev\/md0/’ /mnt/etc/fstab

Create a new boot image and uncompress it:

mkdir /mnt/root/initrd-raid
mkinitrd -v –fstab=/mnt/etc/fstab /mnt/root/initrd-raid/initrd-`uname -r`-raid.img `uname -r`
cd /mnt/root/initrd-raid
zcat initrd-`uname -r`-raid.img | cpio -i

Edit init and raidautorun:
sed -i ‘s/raidautorun \/dev\/md0/raidautorun \/dev\/md0\nraidautorun \/dev\/md1\nraidautorun \/dev\/md2/’ init

Copy the new ramdisk to the /mnt/boot folder and modify boot menu

find . -print | cpio -o -Hnewc | gzip -c > /mnt/boot/initrd-`uname -r`-raid.img
rm /mnt/boot/initrd-2.6-xen.img
cd /mnt/boot
ln -s initrd-`uname -r`-raid.img initrd-2.6-xen.img

Replace in /mnt/boot/extlinux.conf string “root=LABEL=root-…” to “root=/dev/md0″ in all menu entries.

sed -i ‘s/LABEL=[a-zA-Z\-]*/\/dev\/md0/’ extlinux.conf
Set up MBR for GPT on /dev/sdb

cat /mnt/usr/share/syslinux/gptmbr.bin > /dev/sdb
cd /mnt
extlinux –raid -i boot/

Reboot (IMPORTANT: Set your server to boot from the SECONDARY HDD before booting!)
When XenServer is up again, include /dev/sda in the array with the following commands:

sgdisk –attributes=1:set:2 /dev/sda
sgdisk –typecode=1:fd00 /dev/sda
sgdisk –typecode=2:fd00 /dev/sda
sgdisk –typecode=3:fd00 /dev/sda
mdadm -a /dev/md0 /dev/sda1
mdadm -a /dev/md1 /dev/sda2
mdadm -a /dev/md2 /dev/sda3

The array needs to complete its synchronisation. That is gonna take a while. Follow its progress with:

watch -n 1 cat /proc/mdstat
When it’s done on all three arrays, copy the RAID setup to /etc/mdadm.conf

mdadm –detail –scan >> /etc/mdadm.conf

Add the md3 as the local storage:

xe sr-introduce uuid=UUID_from_section_3 type=type_from_section_3 name-label=”Local storage” content-type=user
xe pbd-create sr-uuid=UUID_from_section_3 device-config:device=/dev/md2 host-uuid=[TAB]
xe pbd-plug uuid=previous_returned_UUID

Several neat mdadm commands that might be useful to remember:
removing disk from raid:
mdadm /dev/mdX -r /dev/sdX
adding to raid
mdadm /dev/mdX -a /dev/sdX

The author didnt add any Information to his profile yet

  • Published: 37 posts