XenServer 6.2 com RAID1 via Software

First: Install XenServer on first disk (/dev/sda) and NOT configure any local storage. /dev/sda should contain three partitions, verify this with:

# sgdisk -p /dev/sda

In some cases XenServer doesn’t create third partition, i.e. result of this command has only two partitions and looks like:

Number Start (sector) End (sector) Size Code Name
1 2048 8388641 4.0 GiB 0700
2 8390656 16777249 4.0 GiB 0700

In this case you need to create third partition manually:

# sgdisk --new=3:16779264:DISK_SIZE-34 /dev/sda
# sgdisk --typecode=3:fd00

The second partition is used for backups during a XenServer upgrade. This partition won’t used in my XenServer upgrade method. Now we are going to use /dev/sdb as the mirror disk. First clear the partition table.

# sgdisk --zap-all /dev/sdb
# reboot

install a GPT table on it

# sgdisk --mbrtogpt --clear /dev/sdb
# reboot

The following commands are dependent on your installation. You must copy the start and end sectors from /dev/sda, but in practice, for Xenserver (checked on 6.1,6.2) you must only change DISK_SIZE with sectors on /dev/sdb (first string from output of command:

# sgdisk -p /dev/sdb
# 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

create the software 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/sdb2
# mdadm --create /dev/md2 --level=1 --raid-devices=2 missing /dev/sdb3

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. (Do NOT include the LABEL=)

# 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 insert ‘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/
  Make sure the bootable flag is set on the partitions
# sgdisk /dev/sda --attributes=1:set:2
# sgdisk /dev/sdb --attributes=1:set:2
  Unmount /dev/md0
# cd
# umount /dev/md0
# sync
  Reboot ( IMPORTANT: Set your server to boot from the SECONDARY HDD before booting!)
# reboot

When XenServer is up again, include /dev/sda in the array with the following commands:

# sgdisk --typecode=1:fd00 /dev/sda
# sgdisk --typecode=2:fd00 /dev/sda
# sgdisk --typecode=3:fd00 /dev/sda
# reboot

Create MD Arrays

# mdadm -a /dev/md0 /dev/sda1
# mdadm -a /dev/md1 /dev/sda2
# mdadm -a /dev/md2 /dev/sda3

The array needs to complete its initial build/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

At last add /dev/md2 as a local SR to XenServer.

# xe sr-create content-type=user device-config:device=/dev/md2 host-uuid= name-label="Local Storage" shared=false type=lvm


linux/artigos/xs-raid1-xs62.txt · Última modificação: 13/01/2015 10:44 (edição externa)