Skip to content

Instantly share code, notes, and snippets.

@drewr
Created December 9, 2014 19:56
Show Gist options
  • Save drewr/8e0c072f4dd86d6a5392 to your computer and use it in GitHub Desktop.
Save drewr/8e0c072f4dd86d6a5392 to your computer and use it in GitHub Desktop.
`./md0 /mnt /dev/xvdb /dev/xvdc /dev/xvdd`
#!/bin/bash
mount=$1; shift
devices=$*
if [[ -z $devices ]]; then
echo $0 /dev/DEV [/dev/DEV]
exit 99
fi
sw="$#"
echo $sw $devices
sudo apt-get -q update >/dev/null
sudo apt-get install -q --no-install-recommends mdadm xfsprogs
firstdev=`echo $devices | cut -d' ' -f1`
if ! mount | fgrep " $mount " && [ -b $firstdev ]; then
echo making $mount
[ -d $mount ] || sudo mkdir $mount
echo creating array
/usr/bin/yes | sudo /sbin/mdadm --create /dev/md0 --level=0 -c256 --raid-devices=$sw $devices
echo making mdadm.conf
echo "DEVICE $devices" | sudo tee /etc/mdadm/mdadm.conf
echo "MAILADDR root" | sudo tee -a /etc/mdadm/mdadm.conf
sudo sh -c "/sbin/mdadm --detail --scan >>/etc/mdadm/mdadm.conf"
echo update-initramfs
sudo update-initramfs -u
sudo blockdev --setra 512 /dev/md0
sudo mkfs -t xfs -f -d su=256k -d sw=$sw /dev/md0
sudo mount -t xfs -o noatime /dev/md0 $mount
fgrep /md0 /etc/fstab || sudo sh -c "echo /dev/md0 $mount xfs defaults,noatime,nobootwait 0 0 >>/etc/fstab"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment