-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfix_smartctl
54 lines (48 loc) · 1.52 KB
/
fix_smartctl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
## https://forum.proxmox.com/threads/disk-smart-status-no-longer-working.82748/
cat > smartctl.sh <<'endmsg'
#!/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}
endmsg
mv /usr/sbin/smartctl /usr/sbin/smartctl.orig
cp smartctl.sh /usr/sbin/smartctl
chmod 755 /usr/sbin/smartctl
chattr +i /usr/sbin/smartctl