- Setup SoftwareRAID for the CoreOS root partition without data-loss.
- Only for ext4!
- The Trick is to use the right volume label and fs-types :)
- We assume CoreOS is on
/dev/sdaX
and the second RAID Device is/dev/sdb
- Drawback: only
/
gets mirrored, Node goes down when sda fails
-
Boot into any recovery system like Grml
-
If not already done: install CoreOS
-
Backup
/dev/sda9
mkdir -p /root/sda9 mount /dev/sda9 /mnt || exit 1 rsync -a /mnt/* /root/sda9 umount /dev/sda9
-
Prepare the partition layout
# delete sda9 sgdisk /dev/sda --delete=9 # create new /dev/sda9 partition (max size) START=`sgdisk /dev/sda -f` END=`sgdisk /dev/sda -E` sgdisk /dev/sda --new=9:$START:$END --type=9:fd00 sleep 0.5 partprobe /dev/sda # Remove partition table from sdb sgdisk --clear -g /dev/sdb || exit 1 # create a partition sdb9 with the size of sda9 PARTDATA=( $(sgdisk -i 9 /dev/sda | grep 'Partition size' || exit 1) ) SECTORS=$(expr ${PARTDATA[2]} + 2048) sgdisk /dev/sdb -a 2048 --new=9:2048:$SECTORS --type=9:fd00 || exit 1 sleep 0.5 partprobe /dev/sdb
-
Create the RAID
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda9 /dev/sdb9 mkfs.ext4 -I 128 -L ROOT /dev/md0
-
Copy the Data
mount /dev/md0 /mnt "rsync -a /root/sda9/* /mnt" || exit 1 umount /mnt
-
Wait until resync is finished
watch -n 1 cat /proc/mdstat
-
reboot!
coreos doesn't seem to init mdadm on boot, as a result the boot fails and you're dropped into the dracut shell (after a large delay as it tries to look for ROOT by-label which isn't there. It should just be returning as soon as it isn't found, though...).
Running a mdadm --assemble --scan on that shell and exiting out allows the normal boot to continue.
Any way to automate this?
Edit (Answering my own question):
Pass rd.auto to the kernel with https://coreos.com/os/docs/latest/other-settings.html#adding-custom-kernel-boot-options
Thanks to kayrus@freenode for assisting me with this.