Checking SUSE bootability on POWER

This little script checks the GRUB boot image for the VG/LV/file string pointing to the correct place, e.g. /boot/grub/grub.cfg.

This works on SUSE / SLES on POWER.

# SLES bootability monitor
#
# Henrik Morsing 1.0 24-FEB-2023 Initial

ver=1.0

[[ “${1}” == “DEBUG” ]] && DEBUG=1

unset ERR

# Find rootvg disks

rootlv=”$(mount | grep ‘ / ‘ | awk ‘{ print $1 }’)”
rootvg=$(mount | grep ‘ / ‘ | awk ‘{ print $1 }’ | awk -F- ‘{ print $1 }’ | awk -F/ ‘{ print $NF }’)
disk=”$(/usr/sbin/pvs | grep ${rootvg} | awk -F- ‘{ print $1 }’ | awk -F/ ‘{ print $NF }’)”

PV=”$(/usr/sbin/pvs | grep ${rootvg} | awk ‘{ print $1 }’)”
boot_LV=”$(/usr/sbin/fdisk -l | grep PReP | grep mapper | awk ‘{ print $1 }’)”


# This checks the PVid and LVid in the boot LV
# points to the disk in the rootvg.
# It also checks the grub image pointed to exists.

/usr/local/bin/dd_wrapper ${boot_LV} 2>/dev/null | strings | grep lvmid | grep grub2 | awk -F / ‘{ print $2,$3 }’ | tr -d ‘)’ | while read vgid lvid
do

checkVG=”$(/sbin/vgdisplay -c | grep ${vgid} | awk -F: ‘{ print $1 }’ | tr -d ‘ ‘)”

if [[ “${checkVG}” == “${rootvg}” ]]
then
[[ ${DEBUG} ]] && printf “Boot image points to correct volume group\t\t\033[1;32m[OK]\033[0m\n”
else
[[ ${DEBUG} ]] && printf “Boot image does NOT point to correct volume group\t\t\033[1;31m[FAIL]\033[0m\n”
ERR=1
fi

# This is painfully annoying. lvdisplay command just lacks sensible output.

while read lv parm value
do

# If parm is “Path”, store value in case UUID matches what we are looking for.

if [[ “${parm}” == “Path” ]]
then
final_path=”$(ls -l ${value} | awk ‘{ print $NF }’)”
fi

if [[ “${parm}” == “UUID” ]]
then
if [[ “${value}” == “${lvid}” ]]
then
break
fi
fi
done < <(/sbin/lvdisplay | grep -E “LV Path|LV UUID”)

if [[ “${final_path}” == “$(ls -l ${rootlv} | awk ‘{ print $NF }’)” ]]
then
[[ ${DEBUG} ]] && printf “Boot image points to correct logical volume\t\t\033[1;32m[OK]\033[0m\n”
else
[[ ${DEBUG} ]] && printf “Boot image does NOT point to correct logical volume\t\t\033[1;31m[FAIL]\033[0m\n”
ERR=1
fi

done

# Last check, grub file

grub_file=”$(/usr/local/bin/dd_wrapper ${boot_LV} 2>/dev/null | strings | grep lvmid | grep grub2 | awk -F / ‘{ print “/”$(NF-1)”/”$NF”/grub.cfg” }’)”

if [[ -s ${grub_file} ]]
then
[[ ${DEBUG} ]] && printf “grub.cfg exists in correct location\t\t\t\033[1;32m[OK]\033[0m\n”
else
[[ ${DEBUG} ]] && printf “grub.cfg does NOT exist in correct location\t\t\033[1;31m[FAIL]\033[0m\n”
ERR=1
fi

[[ “${ERR}” == “” ]] && echo “Success” || echo “Fail”

exit 0

This entry was posted in IBM POWER, Linux and tagged , , , , , . Bookmark the permalink.

Leave a Reply