Last active
March 4, 2020 14:06
-
-
Save shortcord/b5c25604ea8f0c42d271161ba3fa3a08 to your computer and use it in GitHub Desktop.
Utility script to wipe disks and report Wearout (Wearout for SSD Only)
This file contains hidden or 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
#!/usr/bin/env bash | |
# Built for CloudSouth.com | |
# This script wipes disk partition tables via wipefs(8) and reports Wearout via smartctl(8). | |
# Mainly built for SSDs, hence the Wearout reporting. | |
# Currently Supports Intel, Kingston, and Micron | |
# If you wish to add support for a disk that isn't listed | |
# run smartctl -A /dev/disk/sdx, where sdx is the disk you want to add. | |
# Look for the attribute that is for reporting disk wear, this differs per manufacturer and not every disk reports wear. | |
# Add that attribute in the egrep command where the "wear" variable is being assiged. | |
# This script is built with the idea of a general server in service at CloudSouth | |
# C6220 Gen1 with a LSI 9265-8i running the latest firmware and JBOD enabled | |
# This script also requires LSI's StorCli package installed and a softlink of the exec in the path | |
# example; ln -s /bin/storcli /opt/MegaRaid/storcli/storcli64 | |
# It will try to clear any forign configs then force set all disks to UGood, minus the bootdisk, if any. | |
# Once in JBOD, we can read smart, pull the needed info regarding wear and wipe the disk with wipefs. | |
shopt -s nullglob; | |
clear; | |
echo "Wiping forign configs, if any."; | |
if ! storcli /call/fall delete > /dev/null; then | |
echo "Failed to wipe forign configs."; | |
exit 1; | |
fi | |
echo "Forcing disks to UGood."; | |
ubadDisks=$(storcli /c0/e18/sall show j | jq --raw-output '.Controllers[0]."Response Data"."Drive Information"[] | select(.State == "UBad") | ."EID:Slt"' | awk -F ':' '{print $2}'); | |
for badDisk in ${ubadDisks[@]}; do | |
if [ ! "${badDisk}" = ' ' ]; then | |
echo "Setting bad config diskID 18:${badDisk} to good."; | |
if ! storcli /c0/e18/s${badDisk} set good force > /dev/null; then | |
echo "Failed to convert disk to UGood"; | |
exit 1; | |
fi; | |
fi; | |
done; | |
unset ubadDisks; | |
echo "Converting disks to JBOD."; | |
ugoodDisks=$(storcli /c0/e18/sall show j | jq --raw-output '.Controllers[0]."Response Data"."Drive Information"[] | select(.State == "UGood") | ."EID:Slt"' | awk -F ':' '{print $2}'); | |
for goodDisk in ${ugoodDisks[@]}; do | |
if [ ! "${goodDisk}" = ' ' ]; then | |
echo "Setting good config diskID 18:${goodDisk} to JBOD."; | |
if ! storcli /c0/e18/s${goodDisk} set jbod > /dev/null; then | |
echo "Failed to convert disk to JBOD."; | |
exit 1; | |
fi; | |
fi; | |
done | |
unset ugoodDisks; | |
echo "Waiting for Kernel to refresh SMART data."; | |
sleep 15; | |
disks=(/dev/disk/by-id/ata-*); | |
if [ ${#disks[@]} -eq 0 ]; then | |
echo "Couldn't find any disks."; | |
echo "Check LEDs!!"; | |
exit 0; | |
fi; | |
if [ ${#disks[@]} -lt 22 ]; then | |
echo "Found less disks than 22." | |
echo "Got ${#disks[@]} instead of 22."; | |
read -p "Contiune? [y/N] " -n 1 -r; | |
echo ""; | |
if [[ "${REPLY}" =~ ^[Yy]$ ]]; then | |
echo "Continuing..."; | |
else | |
exit 0; | |
fi; | |
fi; | |
healthStatus=""; | |
echo "Wiping ${#disks[@]} disks..."; | |
for disk in "${disks[@]}"; do | |
# This is to hide the disks with software RAID, since wiping the underlying disk will remove the raid | |
if [[ ! "${disk}" == *"-part"* ]]; then | |
echo "Wiping disk ${disk##*/}"; | |
if ! wipefs -af "${disk}" > /dev/null 2>&1; then | |
echo "Failed to wipe disk."; | |
exit 1; | |
fi; | |
echo "Gathering Health..."; | |
healthStatus+="======\n"; | |
healthStatus+="${disk}\n"; | |
healthStatus+=$(smartctl -i "${disk}" | egrep '(Device Model|Serial Number|User Capacity)'); | |
wear=$(smartctl -A "${disk}" | egrep '(Media_Wearout_Indicator|Percent_Lifetime_Remain|SSD_Life_Left)' | awk '{printf "%d%\n", $4}'); | |
healthStatus+="\nWear: ${wear}\n"; | |
unset wear; | |
fi; | |
done; | |
echo "Waiting for the Kernel to re-read the disks."; | |
# sleep 15; | |
lsblk; | |
echo "Wipe Complete."; | |
echo "Printing Heath of wiped disks."; | |
sleep 3; | |
echo -e "${healthStatus}"; | |
echo ""; | |
# sometimes when you freshly convert a disk to JBOD, smartctl doesn't see the attributes yet, seems a rerun would fix it | |
echo "If there are blank health status for disks, please rerun 'wipedisks'."; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment