mdadm Software mirror (raid 1) inschakelen voor XenServer 713-07-2016

Ok omdat het mij even uitzoekwerk kostte deel ik graag met iedereen die het ook nodig heeft de onderstaande commando's om van een Xenserver 7 (te downloaden via een software raid opstelling te maken zodat je bij uitval van 1 disk gewoon direct weer verder kan ;-)


### START ###
# I assume the standard disk (with a clean Xenserver 7 default installation) is /dev/sda and the empty disk is /dev/sdb
xe sr-list
xe pbd-list sr-uuid=<local storage-uuid>
xe pbd-unplug uuid=<uuid>
xe sr-forget uuid=<local storage-uuid>
sed -i 's/metadata_read_only = 1/metadata_read_only = 0/' /etc/lvm/lvm.conf
lvremove [press tab twice to show correct lvm]
vgremove [press tab twice to show correct lvm]
pvremove /dev/sda3
sed -i 's/metadata_read_only = 0/metadata_read_only = 1/' /etc/lvm/lvm.conf
sgdisk -R /dev/sdb /dev/sda
sgdisk --typecode=1:fd00 /dev/sdb
sgdisk --typecode=2:fd00 /dev/sdb
sgdisk --typecode=3:fd00 /dev/sdb
sgdisk --typecode=5:fd00 /dev/sdb
sgdisk --typecode=6:fd00 /dev/sdb
reboot server
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 missing
mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sdb2 missing
mdadm --create /dev/md2 --level=1 --raid-devices=2 /dev/sdb3 missing
mdadm --create /dev/md4 --level=1 --raid-devices=2 /dev/sdb5 missing
mdadm --create /dev/md5 --level=1 --raid-devices=2 /dev/sdb6 missing
mkfs.ext3 /dev/md0
mkfs.ext3 /dev/md4
mkswap /dev/md5
mount /dev/md0 /mnt
mkdir -p /mnt/var/log
mount /dev/md4 /mnt/var/log
cp -xa / /mnt
cp -xa /var/log /mnt/var
echo "MAILADDR root" > /mnt/etc/mdadm.conf
echo "auto +imsm +1.x -all" >> /mnt/etc/mdadm.conf
echo "DEVICE /dev/sd*[a-z][1-9]" >> /mnt/etc/mdadm.conf
mdadm --detail --scan >> /mnt/etc/mdadm.conf
cp /mnt/etc/mdadm.conf /etc
sed -i 's/LABEL=root-[a-zA-Z\-]*/\/dev\/md0/' /mnt/etc/fstab
sed -i 's/LABEL=swap-[a-zA-Z\-]*/\/dev\/md5/' /mnt/etc/fstab
sed -i 's/LABEL=logs-[a-zA-Z\-]*/\/dev\/md4/' /mnt/etc/fstab
cp /mnt/etc/fstab /etc
e2label /dev/sda1 |xargs -t e2label /dev/md0
mount --bind /dev /mnt/dev
mount --bind /sys /mnt/sys
mount --bind /proc /mnt/proc
chroot /mnt /bin/bash
cp /boot/initrd-$(uname -r).img /boot/initrd-$(uname -r).img.bak
dracut --mdadmconf --fstab --add="mdraid" --add-drivers="raid1" --force /boot/initrd-$(uname -r).img $(uname -r) -M
sed -i 's/quiet/ rhgb quiet/' /boot/grub/grub.cfg
sed -i 's/LABEL=root-[a-zA-Z\-]*/\/dev\/md0/' /boot/grub/grub.cfg
sed -i '/search/ i\  insmod gzio part_msdos diskfilter mdraid1x' /boot/grub/grub.cfg
sed -i '/search/ c\  set root=(md/0)' /boot/grub/grub.cfg
grub-install /dev/sda # Not sure if this works, since there is no raid on sda yet, so grub-install might not add the mdraid1x driver
grub-install /dev/sdb
cp /mnt/boot/initrd-3.10.0+10.img /boot/
cp /mnt/boot/grub/grub.cfg /boot/grub/grub.cfg
sgdisk -R /dev/sda /dev/sdb
mdadm -a /dev/md0 /dev/sda1
mdadm -a /dev/md1 /dev/sda2
mdadm -a /dev/md2 /dev/sda3
mdadm -a /dev/md4 /dev/sda5
mdadm -a /dev/md5 /dev/sda6
# To be super save install grub on sda again, since it discovers the raid and adds the required drivers.
grub-install /dev/sda
#get the UUID
xe host-list | grep ^uuid
xe sr-create content-type=user device-config:device=/dev/md2 host-uuid=<host-uuid> name-label="Local storage" shared=false type=lvm
# to be shure, check partition style
# and check raid rebuild progress
cat /proc/mdstat
# Don't forget to test the raid with one disk startup, to be sure it works!
#Thats all folks! Now just sit back and relax and hopefully you never need the raid disk ;-)
### END ###


Reageer op dit artikel<----

Eerdere reactie(s):