Skip to content

Instantly share code, notes, and snippets.

@mashayev
Last active May 13, 2020 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mashayev/516cc12bac3010f9152b5f12aa6b1f4f to your computer and use it in GitHub Desktop.
Save mashayev/516cc12bac3010f9152b5f12aa6b1f4f to your computer and use it in GitHub Desktop.
#!/bin/bash
set -x
set -u
check_fstab () {
time_stamp=$(date +%F-%H:%M:%S)
cp /etc/fstab /etc/fstab.backup.$time_stamp
cp /etc/fstab /etc/fstab.modified.$time_stamp
sed -n 's|^/dev/\([sx][v]*d[a-z][0-9]*\).*|\1|p' </etc/fstab >/tmp/device_names # Stores all /dev/sd* and /dev/xvd* entries from fstab into a temporary file
while read LINE; do
# For each line in /tmp/device_names
UUID=`ls -l /dev/disk/by-uuid | grep "$LINE" | sed -n 's/^.* \([^ ]*\) -> .*$/\1/p'` # Sets the UUID name for that device
if [ ! -z "$UUID" ]
then
sed -i "s|^/dev/${LINE}|UUID=${UUID}|" /etc/fstab.modified.$time_stamp # Changes the entry in fstab to UUID form
fi
done </tmp/device_names
if [ -s /tmp/device_names ]; then
echo -e "\n\nERROR Your fstab file contains device names. Mount the partitions using UUID's before changing an instance type to Nitro." # Outputs the new fstab file
echo "Writing changes to /etc/fstab..."
cp /etc/fstab.modified.$time_stamp /etc/fstab
echo -e "\nOriginal fstab file is stored as /etc/fstab.backup.$time_stamp"
rm /etc/fstab.modified.$time_stamp
rm /tmp/device_names
else
rm /etc/fstab.backup.$time_stamp
rm /etc/fstab.modified.$time_stamp
echo -e "\n\nOK fstab file looks fine and does not contain any device names. "
fi
}
check_fstab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment