Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leocomelli/689266fb3d6a5d5dab256fb185583e1f to your computer and use it in GitHub Desktop.
Save leocomelli/689266fb3d6a5d5dab256fb185583e1f to your computer and use it in GitHub Desktop.
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 - https://stackoverflow.com/questions/53162620/automate-gcp-persistent-disk-initialization
#!/bin/bash
set -euxo pipefail
MNT_DIR=/mnt/disks/persistent_storage
if [[ -d "$MNT_DIR" ]]; then
exit
else
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
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment