Skip to content

Instantly share code, notes, and snippets.

@omerh
Created December 23, 2018 14:30
Show Gist options
  • Save omerh/90480f89c386470ba894cd5d9e8980a8 to your computer and use it in GitHub Desktop.
Save omerh/90480f89c386470ba894cd5d9e8980a8 to your computer and use it in GitHub Desktop.
AWS NVMe user data to add to /etc/fstab
#!/bin/bash
## nvme to fstab blkid
##
##
## Disk mapping:
## Cassandra commitlog: /dev/sdb
## Cassandra data: /dev/sdc
##
######################################
apt update
apt install -y nvme-cli
BOOT=$(sudo blkid | grep nvme | grep -w cloudimg-rootfs | awk '{print $1}' | cut -d':' -f1)
DATA_DISKS=$(sudo fdisk -l | grep nvme | grep -v $BOOT | awk '{print $2}' | cut -d':' -f1)
mkdir -p /cassandra-commitlog /cassandra-data
cp /etc/fstab /etc/fstab.ORIG
function set_mount_efstab() {
echo "checking disk $1 with aws mount $2"
disk_id=$(blkid $1 | awk '{print $2}' | tr -d "\"")
case $2 in
sdb)
echo "setting commitlog to disk $1 with mount $2"
echo "$disk_id /cassandra-commitlog xfs defaults,auto,noatime,noexec,nodiratime 0 0" >> /etc/fstab
;;
sdc)
echo "setting data to disk $1 with mount $2"
echo "$disk_id /cassandra-data xfs defaults,auto,noatime,noexec,nodiratime 0 0" >> /etc/fstab
;;
*)
echo "failed to set disk $1 with aws_mount $2"
;;
esac
}
for disk in $DATA_DISKS; do
# Format disk
mkfs.xfs -f $disk
# Locate aws mount
aws_mount=$(nvme id-ctrl --raw-binary $disk | cut -c3073-3104 | tr -s ' ')
# setting fstabl
set_mount_efstab $disk $aws_mount
done
mount -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment