Skip to content

Instantly share code, notes, and snippets.

@KrustyHack
Last active January 4, 2019 07:25
Show Gist options
  • Save KrustyHack/ee5d2bfe9c6f1c240822719437329c2d to your computer and use it in GitHub Desktop.
Save KrustyHack/ee5d2bfe9c6f1c240822719437329c2d to your computer and use it in GitHub Desktop.
#!/bin/bash
DEVICE_ID="$1"
MNT_DIR="$2"
if [[ "$DEVICE_ID" == "" || "$MNT_DIR" == "" ]]; then echo "Usage: ./gce-new-disk.sh DEVICE_ID MNT_DIR"; exit 1; fi
sudo mkfs.ext4 -m 0 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/$DEVICE_ID
sudo mkdir -p $MNT_DIR
sudo mount -o discard,defaults /dev/$DEVICE_ID $MNT_DIR
sudo chmod a+w $MNT_DIR
sudo cp /etc/fstab /etc/fstab.backup
echo UUID=`sudo blkid -s UUID -o value /dev/$DEVICE_ID` $MNT_DIR ext4 discard,defaults,nofail 0 2 | sudo tee -a /etc/fstab
cat /etc/fstab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment