Skip to content

Commit

Permalink
Bug fix awslabs#75 and improvements for C5M5InstanceChecks (awslabs#92)
Browse files Browse the repository at this point in the history
* Bugs fix and imporvements

- Bug fix
- Improvements

* Bugs fix and imporvements

- Bug fix
- Improvements

* Revert "Bugs fix and imporvements"

This reverts commit 14f0b9e.
  • Loading branch information
Tawha authored and lpierillas committed Aug 2, 2019
1 parent 9a58dbb commit ea1d35b
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions EC2/C5M5InstanceChecks/c5_m5_checks_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

check_NVMe_in_initrd () {

is_amazon=`cat /etc/os-release |sed -n 's|^ID="\([a-z]\{4\}\).*|\1|p'` # Check if instance is using amazon AMI.
find_distro=`cat /etc/os-release |sed -n 's|^ID="\([a-z]\{4\}\).*|\1|p'` # Check if instance is using amazon AMI.

if [ -f /etc/redhat-release ] ; then
# Distribution is Red hat
Expand All @@ -27,7 +27,7 @@ is_amazon=`cat /etc/os-release |sed -n 's|^ID="\([a-z]\{4\}\).*|\1|p'` # Ch
echo -e '\t# sudo dracut -f -v'
fi

elif [[ "${is_amazon}" == "amzn" ]]; then
elif [[ "${find_distro}" == "amzn" ]]; then
# Amazon Linux
lsinitrd /boot/initramfs-$(uname -r).img|grep nvme > /dev/null 2>&1
if [ $? -ne 0 ]; then
Expand All @@ -36,7 +36,7 @@ is_amazon=`cat /etc/os-release |sed -n 's|^ID="\([a-z]\{4\}\).*|\1|p'` # Ch
echo -e '\t# sudo dracut -f -v'
fi

elif [ -f /etc/SuSE-release ] ; then
elif [[ "${find_distro}" == "sles" ]] ; then
# Distribution is SuSe Linux
lsinitrd /boot/initrd-$(uname -r)|grep nvme > /dev/null 2>&1
if [ $? -ne 0 ]; then
Expand Down Expand Up @@ -65,40 +65,42 @@ is_amazon=`cat /etc/os-release |sed -n 's|^ID="\([a-z]\{4\}\).*|\1|p'` # Ch
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 # Changes the entry in fstab to UUID form
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 M5/C5." # Outputs the new fstab file
printf "\nPress y to replace device names with UUID in your fstab file? (y/n) "
printf "\nEnter y to replace device names with UUID in /etc/fstab file to make it compatible for NVMe block device names.\nEnter n to keep the file as-is with no modification (y/n) "
read RESPONSE;
case "$RESPONSE" in
[yY]|[yY][eE][sS]) # If answer is yes, keep the changes to /etc/fstab
echo "Writing changes to /etc/fstab..."
echo -e "\n\n***********************"
cat /etc/fstab
cp /etc/fstab.modified.$time_stamp /etc/fstab
echo -e "***********************"
echo -e "\nOriginal fstab file is stored as /etc/fstab.backup.$time_stamp"
rm /etc/fstab.modified.$time_stamp
;;
[nN]|[nN][oO]|"") # If answer is no, or if the user just pressed Enter
echo -e "Aborting: Not saving changes...\nPrinting correct fstab file below:" # don't save the new fstab file
cat /etc/fstab
cp /etc/fstab.backup.$time_stamp /etc/fstab
echo -e "Aborting: Not saving changes...\nPrinting correct fstab file below:\n\n" # don't save the new fstab file
cat /etc/fstab.modified.$time_stamp
rm /etc/fstab.backup.$time_stamp
rm /etc/fstab.modified.$time_stamp
;;
*) # If answer is anything else, exit and don't save changes
echo "Invalid Response" # to fstab
echo "Exiting"
cp /etc/fstab.backup.$time_stamp /etc/fstab
rm /etc/fstab.backup.$time_stamp
rm /etc/fstab.modified.$time_stamp
exit 1
echo -e "------------------------------------------------"
;;
Expand All @@ -107,6 +109,8 @@ check_fstab () {
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

Expand All @@ -126,7 +130,7 @@ if [ `id -u` -ne 0 ]; then # Checks
exit 1
fi

modinfo nvme > /dev/null 2>&1
(modinfo nvme || grep 'nvme' /boot/System.map-$(uname -r)) > /dev/null 2>&1
if [ $? -ne 0 ]
then
# NVMe Module is not installed.
Expand Down Expand Up @@ -155,5 +159,4 @@ fi


check_fstab
echo -e "\n------------------------------------------------"

echo -e "\n------------------------------------------------"

0 comments on commit ea1d35b

Please sign in to comment.