Created
September 8, 2023 05:57
-
-
Save trx1138/8b1275c00114f6d0fe8a3b00177ba3fb to your computer and use it in GitHub Desktop.
proxmox smartctl wrapper
This file contains 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 | |
# ----------------------------------------------------------------- | |
# simple mod of smartctl-wrapper.sh for proxmox | |
# https://forum.proxmox.com/threads/issues-with-hp-p420i-and-smart.79669/#post-418226 | |
# ----------------------------------------------------------------- | |
# | |
# ----------------------------------------------------------------- | |
# Copyright (c) 2021 BestSolution.at EDV Systemhaus GmbH | |
# All Rights Reserved. | |
# | |
# This software is released under the terms of the | |
# | |
# "GNU Affero General Public License" | |
# | |
# and may only be distributed and used under the terms of the | |
# mentioned license. You should have received a copy of the license | |
# along with this software product, if not you can download it from | |
# https://www.gnu.org/licenses/agpl-3.0.en.html | |
# | |
# Author: udo.rader@bestsolution.at | |
# ----------------------------------------------------------------- | |
# | |
# smartctl_cciss.sh | |
# | |
# Wrapper that converts | |
# | |
# '$ smartctl [...] /dev/sda' to '$ smartctl -d cciss,0 [...] /dev/sda' | |
# '$ smartctl [...] /dev/sdb' to '$ smartctl -d cciss,1 [...] /dev/sdb' | |
# '$ smartctl [...] /dev/sdc' to '$ smartctl -d cciss,2 [...] /dev/sdc' | |
# ... | |
# '$ smartctl [...] /dev/sdp' to '$ smartctl -d cciss,15 [...] /dev/sdp' | |
# | |
# Per definition (see man smartctl(8)), the maximum number of devices | |
# supported by the cciss driver is 15, so the /dev/sdp is the "highest" | |
# device accepted (p=15). | |
# | |
# This is useful for certain HP RAID/HBA controllers that expose the block | |
# devices they control as /dev/sdX, but still require '-d cciss,N' to be | |
# present when used with smartctl. | |
# | |
# At the bottom line, this saves you the extra commandline switch plus at | |
# the same time allows other tools to read out the SMART values without any | |
# further configuration on their side (eg. the proxmox admin interface | |
# showing SMART values). | |
# | |
# To wrap the original smartctl binary using this script, rename the script | |
# to /usr/sbin/smartctl.orig and use this script as a replacement, eg like | |
# this: | |
# | |
# $ mv /usr/sbin/smartctl /usr/sbin/smartctl.orig | |
# $ cp /path/of/the/downloaded_wrapper/smartctl_cciss.sh /usr/sbin/smartctl | |
# $ chmod 755 /usr/sbin/smartctl | |
# | |
# Later updates of the smartmontools package will probably overwrite the | |
# wrapper, so what you can do to prevent this is to make the in place | |
# wrapper immutable like this: | |
# | |
# $ chattr +i /usr/sbin/smartctl | |
# | |
# ... but this may have some sideffects afterwards (eg. updates might | |
# complain that they cannot update the now immutable file). | |
# | |
# This is a little bit hackish, but it does the job well enough for me :) | |
SMARTCTL=/usr/sbin/smartctl.orig | |
OPTIONS=("$@") | |
d_realtek=("d" "e") | |
d_jmicron=() | |
for((i=1; i<$#; ++i)); do | |
device_letter="${OPTIONS[i]#/dev/sd}" | |
# proceed only if the given device is in device lists. | |
if [[ " ${d_realtek[*]} " =~ " ${device_letter} " ]]; then | |
d_opt="-d sntrealtek" | |
# add the "-d X" option to the list of options | |
OPTIONS=($d_opt "${OPTIONS[@]}") | |
fi | |
if [[ " ${d_jmicron[*]} " =~ " ${device_letter} " ]]; then | |
d_opt="-d sntjmicron" | |
OPTIONS=($d_opt "${OPTIONS[@]}") | |
fi | |
done | |
exec $SMARTCTL "${OPTIONS[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment