Last Christmast I received a new external USB Disk for my Raspberry PI 4.

In this Raspi I have a set of SMB mounts to use for several things including:

  • PS2 USB share (for loading PS2 games)
  • General SMB share
  • Backup of different Internet repositories I own

Previous disk was a Western Digital one that entered standby automatically after some time but my new one a 5TB Seagate was not spinning down

I research in the issue and after some time, I found out that the OS (10 Buster) was not being able to use SMART in this drive and the drive firmware seems not to have automatic power down.

The OS, using SMART, can configure automatic spindown after some time being inactive, and this is what I wanted. So, after installing smart tools package (it wasn't install in my Raspi):

sudo apt-get install smartmontools

And trying to do anything with the drive, I was getting errors regarding not supported USB drive:

Read Device Identity failed: scsi error unsupported field in scsi command

After some digging (and thinking that the USB drive from Seagate was not appropiate for the usage I wanted) I found out the issue. The problem was that the drive was using the UAS module in the operating system and this module was generating the issue with SMART mon tools, so, let's configure Raspberry PI OS for not using UAS for this drive.


Get Vendor and Product ID

fms@gate:~ $ lsusb
Bus 002 Device 003: ID 0bc2:2034 Seagate RSS LLC 
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

In my case it was Vendor ID 0bc2 and Product ID 2034.

Configure Raspberry PI OS boot sequence to not use UAS for this device.

Edit /boot/cmdline.txt and add the following parameter to the kernel loading (ensure to put the correct Vendor and Product ID you got in the previous step):

usb_storage.quirks=0bc2:2034:u

The cmdline file should look like this:

console=serial0,115200 console=tty1 root=PARTUUID=8c926f11-02 rootfstype=ext4 elevator=deadline fsck.repair=yes usb_storage.quirks=0bc2:2034:u rootwait

And reboot the Raspi to apply this setting.

Check the drive is accesible for SMART mon tools

After reboot, execute a sample smartctl command to ensure the drive is acceisble for SMART tools, for example (if your drive is mapped to /dev/sda):

sudo smartctl -a /dev/sda -d sat

You should get a full SMART response, similar to this one:

smartctl 6.6 2017-11-05 r4594 [armv7l-linux-5.4.79-v7l+] (local build)
Copyright (C) 2002-17, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Seagate Barracuda 2.5 5400
Device Model:     ST5000LM000-2AN170
Serial Number:    FMSSN
LU WWN Device Id: 5 000c50 0f21e09d5
Firmware Version: 0001
User Capacity:    5.000.981.078.016 bytes [5,00 TB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    5526 rpm
Form Factor:      2.5 inches
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ACS-3 T13/2161-D revision 5
SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 3.0 Gb/s)
Local Time is:    Sun Jan  7 11:49:27 2024 CET
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

General SMART Values:
Offline data collection status:  (0x00)	Offline data collection activity
					was never started.
					Auto Offline Data Collection: Disabled.
Self-test execution status:      (   0)	The previous self-test routine completed
					without error or no self-test has ever 
					been run.
Total time to complete Offline 
data collection: 		(    0) seconds.
Offline data collection
capabilities: 			 (0x73) SMART execute Offline immediate.
					Auto Offline data collection on/off support.
					Suspend Offline collection upon new
					command.
					No Offline surface scan supported.
					Self-test supported.
					Conveyance Self-test supported.
					Selective Self-test supported.
SMART capabilities:            (0x0003)	Saves SMART data before entering
					power-saving mode.
					Supports SMART auto save timer.
Error logging capability:        (0x01)	Error logging supported.
					General Purpose Logging supported.
Short self-test routine 
recommended polling time: 	 (   1) minutes.
Extended self-test routine
recommended polling time: 	 ( 808) minutes.
Conveyance self-test routine
recommended polling time: 	 (   2) minutes.
SCT capabilities: 	       (0x30a5)	SCT Status supported.
					SCT Data Table supported.

SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   076   069   006    Pre-fail  Always       -       44189864
  3 Spin_Up_Time            0x0003   096   096   000    Pre-fail  Always       -       0
  4 Start_Stop_Count        0x0032   100   100   020    Old_age   Always       -       29
  5 Reallocated_Sector_Ct   0x0033   100   100   010    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000f   065   060   045    Pre-fail  Always       -       3102614
  9 Power_On_Hours          0x0032   100   100   000    Old_age   Always       -       455 (149 190 0)
 10 Spin_Retry_Count        0x0013   100   100   097    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   020    Old_age   Always       -       13
183 SATA_Downshift_Count    0x0032   100   100   000    Old_age   Always       -       0
184 End-to-End_Error        0x0032   100   100   099    Old_age   Always       -       0
187 Reported_Uncorrect      0x0032   100   100   000    Old_age   Always       -       0
188 Command_Timeout         0x0032   100   100   000    Old_age   Always       -       0
189 High_Fly_Writes         0x003a   100   100   000    Old_age   Always       -       0
190 Airflow_Temperature_Cel 0x0022   075   052   040    Old_age   Always       -       25 (Min/Max 25/40)
191 G-Sense_Error_Rate      0x0032   100   100   000    Old_age   Always       -       0
192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       19
193 Load_Cycle_Count        0x0032   100   100   000    Old_age   Always       -       77
194 Temperature_Celsius     0x0022   025   048   000    Old_age   Always       -       25 (0 18 0 0 0)
195 Hardware_ECC_Recovered  0x001a   076   069   000    Old_age   Always       -       44189864
197 Current_Pending_Sector  0x0012   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0010   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x003e   200   200   000    Old_age   Always       -       0
240 Head_Flying_Hours       0x0000   100   253   000    Old_age   Offline      -       37 (147 102 0)
241 Total_LBAs_Written      0x0000   100   253   000    Old_age   Offline      -       3925279266
242 Total_LBAs_Read         0x0000   100   253   000    Old_age   Offline      -       3612908854
254 Free_Fall_Sensor        0x0032   100   100   000    Old_age   Always       -       0

SMART Error Log Version: 1
No Errors Logged

SMART Self-test log structure revision number 1
No self-tests have been logged.  [To run self-tests, use: smartctl -t]

SMART Selective self-test log data structure revision number 1
 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
    1        0        0  Not_testing
    2        0        0  Not_testing
    3        0        0  Not_testing
    4        0        0  Not_testing
    5        0        0  Not_testing
Selective self-test flags (0x0):
  After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.

We are almost there. We need SMART mon tools to be configure for setting up the spindown timer when the drive is connected to the Raspi (or the system is rebooted).

Setup a UDEV rule for setting the automatic spindown on inactivity

udev service will be the one handling the connecting of the USB drive, and as such, we can create a custom rule to automatically configure the spindown time.

The following command will create a file in the udev files folder and configure a 300 seconds spindown time (standby parameter represents a 5 seconds factor) for any "sdX" disk that is attached to the Raspi:

cat >/etc/udev/rules.d/69-usbstandby.rules <<EOF
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", RUN+="/usr/sbin/smartctl --set standby,60 -d sat /dev/%k"
EOF

Everything is ready and OK. You can check wheter this is working properly if, after 5 minutes (in my config) you can check that the drive is in standby mode. This can be done executing the following command:

sudo smartctl --nocheck standby -i /dev/sda -d sat | grep "STANDBY"
Device is in STANDBY mode, exit(2)

If you can see the response as in the example, your drive has been spinned down successfully.

Please note the --nocheck param as this will avoid smartctl spinning up the disk for SMART queries.