Modified sdspin - unintended consequences?


Recommended Posts

I have a USB drive (sdb) mounted with UD:

1658500954_ScreenShot2021-03-16at3_10_21PM.thumb.png.a712a2da7e8772bd01b300265865cb46.png

 

v6.9.1 spins it down correctly but the (substandard) interface returns bad/missing sense data:

root@NAS:~# hdparm -y /dev/sdb

/dev/sdb:
issuing standby command
SG_IO: bad/missing sense data, sb[]:  f0 00 01 00 50 40 00 0a 80 00 00 00 00 1d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

 

...which this line in /usr/local/sbin/sdspin catches and records as an error:

  [[ $RET == 0 && ${OUTPUT,,} =~ "bad/missing sense" ]] && RET=1

 

So although the drive's spun down unRAID thinks it isn't causing (a) the activity LED to stay green and (b) unRAID to try to spin it down every spindown interval.


I've worked around it by modifying the code (below) to exclude USB drives from the test.

Is that risky, should I not have?

I'm not sure what cases this test is meant to handle.

 

I've also updated the status check for USB drives to use smartctl since (at least with mine) hdparm can't detect standby.

 

#!/bin/bash

# spin device up or down or get spinning status
# $1 device name
# $2 up or down or status
# ATA only

# hattip to Community Dev @doron

RDEVNAME=/dev/${1#'/dev/'}      # So that we can be called with either "sdX" or "/dev/sdX"

get_device_id () {
  LABEL="${RDEVNAME:5}"
  DEVICE_ID=`ls -l /dev/disk/by-id/ | grep -v " wwn-" | grep "${LABEL}$" | rev | cut -d ' ' -f3 | rev`
  echo "$DEVICE_ID"
}

smartctl_status () {
  OUTPUT=$(/usr/sbin/smartctl --nocheck standby -i $RDEVNAME 2>&1)
  RET=$?
  # Ignore Bit 1 error (Device open failed) which usually indicates standby
  [[ $RET == 2 && $(($RET & 2)) == 2 ]] && RET=0 
}

hdparm () {
  OUTPUT=$(/usr/sbin/hdparm $1 $RDEVNAME 2>&1)
  RET=$?
  # ignore missing sense warning which might be caused by a substandard USB interface
  if [[ ! "$(get_device_id)" =~ ^usb-.* ]]; then
    [[ $RET == 0 && ${OUTPUT,,} =~ "bad/missing sense" ]] && RET=1
  fi
}    

if [[ "$2" == "up" ]]; then
  hdparm "-S0"
elif [[ "$2" == "down" ]]; then
  hdparm "-y"
else
  # use smartctl (instead of hdparm) for USB drives
  if [[ "$(get_device_id)" =~ ^usb-.* ]]; then
    smartctl_status
  else
    hdparm "-C"
  fi
  [[ $RET == 0 && ${OUTPUT,,} =~ "standby" ]] && RET=2
fi
exit $RET

 

Edited by CS01-HS
Link to comment
On 4/16/2021 at 5:53 PM, CS01-HS said:

I've improved the script including the use of smartctl to check USB drive status (which unlike hdparm works reliably with substandard USB interfaces.)

It will error for USB drives not in the drive.h. Your drive is fine as its in the db. But if others use they should test first. Its simple to get devices added but a request needs to be submitted to the smartmontools team.

 

There is a process to update drive.h but I dont think its in unraid will need to check. 

Edited by SimonF
  • Thanks 1
Link to comment

To update drivedb.h you can add something like this to your go script:

 

wget https://raw.githubusercontent.com/smartmontools/smartmontools/master/smartmontools/drivedb.h -O /usr/share/smartmontools/drivedb.h

This will install the latest smartmontools drive database. Whether it will cover a given drive is a different question 🙂

Link to comment
15 minutes ago, doron said:

To update drivedb.h you can add something like this to your go script:

 


wget https://raw.githubusercontent.com/smartmontools/smartmontools/master/smartmontools/drivedb.h -O /usr/share/smartmontools/drivedb.h

This will install the latest smartmontools drive database. Whether it will cover a given drive is a different question 🙂

There is a script /usr/sbin/update-smart-drivedb but have not checked unraid vers works.

Link to comment
17 minutes ago, SimonF said:

There is a script /usr/sbin/update-smart-drivedb but have not checked unraid vers works.

It kind-of works (if you use with --no-verify, since gpg isn't available) but it will downgrade your db to 7.0 rather than upgrade to the latest... I guess it can be tweaked to do the right thing. Or, you can use the above.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.