Skip to content

Instantly share code, notes, and snippets.

  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Use the following script to mount a persistent storage during startup. This is helpful when you provision the compute instance as well as the persistent disk using some automation tool like Terraform. StackOverFlow question -
set -euxo pipefail
if [[ -d "$MNT_DIR" ]]; then
sudo mkfs.ext4 -m 0 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/sdb; \
sudo mkdir -p $MNT_DIR
sudo mount -o discard,defaults /dev/sdb $MNT_DIR
# Add fstab entry
echo UUID=`sudo blkid -s UUID -o value /dev/sdb` $MNT_DIR ext4 discard,defaults,nofail 0 2 | sudo tee -a /etc/fstab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment