Fixing SMART Data Reporting for HS-HUB-MHC201 USB Enclosure

Fabricio Ferrari

Active Member
Apr 11, 2018
5
2
43
52
Problem:

I was having issues getting Proxmox to correctly report SMART data for a hard drive connected via a HS-HUB-MHC201 USB enclosure. Proxmox relies on smartctl for SMART data, but the enclosure's USB-to-SATA bridge was causing smartctl to misbehave. Specifically, smartctl --scan was not detecting the device correctly, and the necessary -d sat option was not being applied.

Symptoms:

  • Proxmox not displaying SMART data for the drive.
  • smartctl commands failing or returning incorrect information.
Cause:

The HS-HUB-MHC201 USB enclosure uses a USB-to-SATA bridge that is not fully compatible with the default smartctl settings.

Solution:

I needed to create a replacement script for smartctl that would selectively apply the -d sat option to the HS-HUB-MHC201 enclosure while leaving other drives unaffected.

With the assistance of Gemini, a large language model, we developed the following script:

Code:
#!/bin/bash

# Target vendor name.
TARGET_VENDOR="HIKSEMI"

# Function to check if the device matches the target vendor.
check_vendor() {
  local device_path="$1"
  local vendor

  # Check if the device is a /dev/sd* device.
  if [[ "$device_path" =~ ^/dev/sd[a-z][0-9]*$ ]]; then
    # Get the vendor name from /sys/class/block/<device>/device/vendor.
    if [[ -d "/sys/class/block/$(basename "$device_path")/device" ]]; then
      vendor=$(cat "/sys/class/block/$(basename "$device_path")/device/vendor" 2>/dev/null | tr -d ' ')

      # Check if the vendor matches the target vendor.
      if [[ "$vendor" == "$TARGET_VENDOR" ]]; then
        return 0 # Match found.
      fi
    fi
  fi

  return 1 # No match.
}

# Check if any argument matches /dev/sd* and the target vendor.
for arg in "$@"; do
  if [[ "$arg" =~ ^/dev/sd[a-z][0-9]*$ ]] && check_vendor "$arg"; then
    sudo /usr/sbin/smartctl.orig -d sat "$@"
    exit $?
  fi
done

sudo /usr/sbin/smartctl.orig "$@"
exit $?


Installation and Usage:

  1. Backup the original smartctl binary:
    sudo mv /usr/sbin/smartctl /usr/sbin/smartctl.orig

  2. Save the script: Save the script to a file, for example, smartctl_replacement.sh.
  3. Make the script executable:
    chmod +x smartctl_replacement.sh

  4. Create a symbolic link:
    sudo ln -s /path/to/smartctl_replacement.sh /usr/sbin/smartctl

    (Replace /path/to/smartctl_replacement.sh with the actual path to your script.)
Explanation:

  • The script identifies the HS-HUB-MHC201 enclosure by checking the vendor name in /sys/class/block/device/device/vendor.
  • If the vendor matches "HIKSEMI," the script calls smartctl.orig with the -d sat option.
  • Otherwise, it calls smartctl.orig with the original parameters.
  • The script loops through all of the arguments passed to it, so it will work regardless of the order of the arguments.
Important Notes:

  • This solution targets the HS-HUB-MHC201 enclosure specifically. If you have a different enclosure, you may need to modify the TARGET_VENDOR variable.
  • Gemini was instrumental in helping me debug and refine this script, providing valuable insights and code examples throughout the process.
Benefits:

  • Correct SMART data reporting for HS-HUB-MHC201 enclosures in Proxmox.
  • Reliable monitoring of hard drive health.
  • Prevention of potential data loss.
I hope this helps anyone else experiencing similar issues! A big thank you to Gemini for the excellent assistance!

All of the above was written by Gemini, it took us quite a while to figure a reliable way to identify this device, as the USB ID (152d:0580, reported as a JMicron Technology Corp. / JMicron USA Technology Corp. HIKSEMI) seems to be also used by other devices, and the page at HIKSEMI says they use a VIA VL716 bridge, not a JMicron one.

I've had issues in the past with getting SMART data on proxmox showing correctly when using some RAID controllers in HBA mode, but this one was quite different.

It was a strange and eye-opening experience relying on an AI (for the first time) to solve this and believe me, I was going down and endless rabbit hole with udevadm getting nowhere.
 
  • Like
Reactions: Kingneutron