Last active
September 6, 2019 08:12
-
-
Save camme/d59bf88701adfd28f49763c8e775b24e to your computer and use it in GitHub Desktop.
Mount AWS external drive
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 | |
echp Add a new mounted volue and mset it up to be mounted on boot | |
echo "instructions from https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html" | |
if [ "$EUID" -ne 0 ] | |
then echo "Please run as root" | |
exit | |
fi | |
echo Checking if the volume is empty | |
# if ! grep -q "data" $TEMP_FILE_CHECK; then | |
export TEMP_FILE_CHECK=$(file -s /dev/xvdb) | |
if [[ $TEMP_FILE_CHECK != "/dev/xvdb: data" ]]; then | |
echo "Volume needs to be data" | |
exit 1 | |
fi | |
echo Set the volume in the correct format | |
mkfs -t xfs /dev/xvdb | |
echo Create the mount point | |
mkdir /data | |
echo Mount it | |
mount /dev/xvdb /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 'xvdb.*?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