Forked from raj-saxena/gcp_compute_mount_persistent_disk.sh
Created
March 31, 2020 04:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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