Created
September 12, 2026 09:00
-
-
Save si458/bc8d847777cb3c8e2b9807c879c8b5fe to your computer and use it in GitHub Desktop.
Fix smartctl for HP Raid Controllers and Proxmox
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
| #!/bin/bash | |
| echo "=== Step 1: Moving original smartctl ===" | |
| mv /usr/sbin/smartctl /usr/sbin/smartctl.orig | |
| echo "Done." | |
| echo "" | |
| echo "=== Step 2: Creating wrapper script ===" | |
| cat > /usr/sbin/smartctl << 'EOF' | |
| #!/bin/bash | |
| # ---------------------------------------------------------- | |
| # Wrapper for smartctl for supporting HP P212 HBA and USB | |
| # Sandisk. | |
| # | |
| # Author: joanandk | |
| # Created: Apr 28, 2022 | |
| # Modified: | |
| # License: GNU Affero General Public License | |
| # Inspired by: udo.rader@bestsolution.at | |
| # ---------------------------------------------------------- | |
| # Instructions: | |
| # Move the binary in /usr/sbin/smartctl to smartctl.orig | |
| # create a script with this code and make it executable | |
| SMARTCTL=/usr/sbin/smartctl.orig | |
| # Get the block name: | |
| OPTIONS=("$*") | |
| TEMP=${OPTIONS#*/dev/} | |
| [ -z "${TEMP}" ] && exit | |
| PD_ADR="${TEMP:0:3}" | |
| # Hack for disks connected to HP Smart Array: | |
| SA_ID=$(lspci -D | grep "Smart Array" | cut -d\ -f1) | |
| SA_PD=$(readlink /sys/class/block/$PD_ADR | grep $SA_ID) | |
| if [ ! -z ${SA_ID} ] && [ ! -z ${SA_PD} ]; then | |
| PD_ALL=$(readlink /sys/block/sd* | grep $SA_ID | rev | cut -d/ -f1 | rev) | |
| INDEX=0 | |
| for Search_PD in $PD_ALL; do | |
| if [ "${PD_ADR}" == "${Search_PD}" ]; then | |
| OPTIONS="-d cciss,${INDEX} ${OPTIONS}" | |
| break | |
| fi | |
| INDEX=$[$INDEX+1] | |
| done | |
| fi | |
| # Hack for USB pendrives: | |
| USB_DEV=$(readlink /sys/class/block/$PD_ADR | grep usb | cut -d/ -f6) | |
| if [ ! -z ${USB_DEV} ]; then | |
| OPTIONS="-d scsi ${OPTIONS}" | |
| fi | |
| exec $SMARTCTL ${OPTIONS} | |
| EOF | |
| echo "Done." | |
| echo "" | |
| echo "=== Step 3: Making smartctl executable ===" | |
| chmod 755 /usr/sbin/smartctl | |
| echo "Done." | |
| echo "" | |
| echo "=== Step 4: Running smartctl -a /dev/sda ===" | |
| smartctl -a /dev/sda |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment