Skip to content

Instantly share code, notes, and snippets.

@psi-4ward
Last active June 13, 2017 13:02
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save psi-4ward/c1cece78cdf8fa9d64e7 to your computer and use it in GitHub Desktop.
Save psi-4ward/c1cece78cdf8fa9d64e7 to your computer and use it in GitHub Desktop.
CoreOS mdadm RAID1 for ROOT

CoreOS mdadm RAID1 for ROOT

  • 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
  1. Boot into any recovery system like Grml

  2. If not already done: install CoreOS

  3. Backup /dev/sda9

    mkdir -p /root/sda9
    mount /dev/sda9 /mnt || exit 1
    rsync -a /mnt/* /root/sda9
    umount /dev/sda9
  4. 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
  5. Create the RAID

     mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda9 /dev/sdb9
     mkfs.ext4 -I 128 -L ROOT /dev/md0
  6. Copy the Data

     mount /dev/md0 /mnt
     "rsync -a /root/sda9/* /mnt" || exit 1
     umount /mnt
  7. Wait until resync is finished

    watch -n 1 cat /proc/mdstat
  8. reboot!

@stresler
Copy link

I'm attempting this using Core itself as the in-RAM system. Two things are happening currently:

  1. rsync doesn't support ACLs and throws an error on the copy. Removing the A flag lets it succeed, but I don't know what repercussions that might have. Is there another tool that might work for this? I would think maybe dd would be appropriate here, but I'm not certain.
  2. On reboot the machine hangs. Oddly the last output is looking for a PS/2 Mouse device, so I presume it is some issue before that which is really crashing it. I'll try to get into a rescue system and parse logs soon.

Thanks for your work on this. I'm hoping to refine it into something we can build into our provisioning.

@shenhequnying
Copy link

you just backup the sda9 partition.
sda1 or other partition also can backup use this solution?
thanks.

@Wintereise
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment