Skip to content

Instantly share code, notes, and snippets.

@sreimers
Forked from psi-4ward/README.md
Created March 9, 2017 14:32
Show Gist options
  • Save sreimers/f129609206644808439ad3d70ca36e45 to your computer and use it in GitHub Desktop.
Save sreimers/f129609206644808439ad3d70ca36e45 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!

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