Skip to content

Instantly share code, notes, and snippets.

@clintmiller
Forked from pokle/gist:9271432
Created August 22, 2017 16:01
Show Gist options
  • Save clintmiller/94f111d2e98d2debc7d2d4bb1cfd6f68 to your computer and use it in GitHub Desktop.
Save clintmiller/94f111d2e98d2debc7d2d4bb1cfd6f68 to your computer and use it in GitHub Desktop.
Automatically mount the EC2 ephermal SSDs as raid0 on Ubuntu

Launch your EC2 EBS instance with two SSDs on the second and third slots (after the root EBS volume), with this in your userdata:

#!/usr/bin/env bash

umount /dev/xvdb
umount /dev/xvdc
apt-get install mdadm -y
mkdir /u01
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

start mount-ephermal-ssd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment