Skip to content

Instantly share code, notes, and snippets.

@double-p
Created October 14, 2016 15:14
Show Gist options
  • Save double-p/2978c6f8847418b4074b608b8b8b29a5 to your computer and use it in GitHub Desktop.
Save double-p/2978c6f8847418b4074b608b8b8b29a5 to your computer and use it in GitHub Desktop.
/sbin/modprobe raid1
# create software-raid devices, one disk on sdb, the other 'missing' for now (sda added later)
yes|mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 missing --metadata=0.90
yes|mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sdb2 missing
yes|mdadm --create /dev/md2 --level=1 --raid-devices=2 /dev/sdb3 missing
mkfs.ext3 /dev/md0
tune2fs -i 0 /dev/md0
mount /dev/md0 /mnt
cd /
cp -ax . /mnt
HDUUID=`blkid | grep ^/dev/md0 | awk {'print $2'} | sed s/\"//g`
perl -p -i -e 's#^LABEL=root.*#'${HDUUID}' / ext3 defaults 1 1#g' /mnt/etc/fstab
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
awk '{ print } /raidautorun/ { print "raidautorun /dev/md1"; print "raidautorun /dev/md2"; print "raidautorun /dev/md3"; next; }' in
it > init.new
mv init.new init
chmod 700 init
find . -print | cpio -o -Hnewc | gzip -c > /mnt/boot/initrd-`uname -r`-raid.img
rm -f /mnt/boot/initrd-3.10-xen.img
ln -s initrd-`uname -r`-raid.img /mnt/boot/initrd-3.10-xen.img
rm -f initrd-`uname -r`.img
ln -s initrd-`uname -r`-raid.img /mnt/boot/initrd-`uname -r`.img
perl -p -i -e 's#root=LABEL=root[a-z0-9-]*#root='${HDUUID}'#g' /mnt/boot/extlinux.conf
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
umount /mnt/dev
umount /mnt/sys
umount /mnt/proc
mknod /mnt/dev/md0 b 9 0
mknod /mnt/dev/md1 b 9 1
mknod /mnt/dev/md2 b 9 2
mknod /mnt/dev/md3 b 9 3
mdadm --detail --scan >> /mnt/etc/mdadm.conf
cd
umount /dev/md0
sync
sgdisk /dev/sda --attributes=1:set:2
sgdisk /dev/sdb --attributes=1:set:2
# Kill sda MBR
dd if=/dev/zero of=/dev/sda bs=1024 count=5
sgdisk --replicate=/dev/sda /dev/sdb
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment