Skip to content

Instantly share code, notes, and snippets.

@camme
Last active October 22, 2019 11:39
Show Gist options
  • Save camme/75c85478cd90ad954a39ad389d21c986 to your computer and use it in GitHub Desktop.
Save camme/75c85478cd90ad954a39ad389d21c986 to your computer and use it in GitHub Desktop.
#!/bin/bash
echp Add a new mounted volue and mset it up to be mounted on boot
echo "instructions from https://devopscube.com/mount-extra-disks-on-google-cloud/"
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
apt-get update
apt-get install file -y
echo Checking if the volume is empty
# if ! grep -q "data" $TEMP_FILE_CHECK; then
export TEMP_FILE_CHECK=$(file -s /dev/sdb)
if [[ $TEMP_FILE_CHECK != "/dev/sdb: data" ]]; then
echo "Volume needs to be data"
exit 1
fi
echo Set the volume in the correct format
mkfs -t xfs /dev/sdb
echo Create the mount point
mkdir /data
echo Mount it
mount /dev/sdb /data
echo Test if its listed
df -h
echo Make a copy of the original fstab file
cp /etc/fstab /etc/fstab.orig
echo Add the mount info
echo "UUID=\"$(blkid | grep -Po 'sdb.*?UUID="\K.*?(?=")')\" /data xfs defaults,nofail 0 2" >> /etc/fstab
echo Unmount it
umount /data
echo Mount it with fstab
mount -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment