Skip to content

Instantly share code, notes, and snippets.

@mkdynamic
Forked from pokle/gist:9271432
Created May 11, 2014 03:32
Show Gist options
  • Save mkdynamic/fcbbe1a37fa22ce2989d to your computer and use it in GitHub Desktop.
Save mkdynamic/fcbbe1a37fa22ce2989d to your computer and use it in GitHub Desktop.

Assuming you have an EBS instance for the root filesystem, and you want to mount your SSDs (on /dev/xvdb and /dev/xvdc) as raid0 every boot/reboot.

Remove the last line of /etc/fstab that refers to /dev/xvdb, and unmount your devices if they are mounted.

umount /dev/xvdb
umount /dev/xvdc

mdadm isn't installed by default.

apt-get install mdadm -y

We're going to mount at /u01

mkdir /u01

Create an upstart configuration to re-initialise the raid device on every boot.

cat > /etc/init/mount-ephermal-ssd.conf  <<HERE
start on virtual-filesystems

script
  # Attempt a short circuit mount - one of these works 
  # after a reboot
  mount /dev/md127 /u01 && exit 
  mount /dev/md0 /u01 && exit 

  # It's possible this was a EC2 STOP/START - create everything from scratch
  # Although we specify md0, the actual device may be md127 upon reboot!!!
  yes | mdadm --create --verbose --force /dev/md0 --level=0 --raid-devices=2 /dev/xvdb /dev/xvdc

  # Last chance 
  mount /dev/md127 /u01 && exit  
  mount /dev/md0 /u01 && exit

  # Clean FS
  mkfs.ext4 /dev/md0 
  mount /dev/md127 /u01 && exit
  mount /dev/md0 /u01 && exit

end script
HERE

Now just reboot (to test it all works)

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