Graceful way to spin down (unload head) USB attached mobile hard drive BEFORE shutdown(poweroff/reboot/halt)

After some digging into the code.
I probably find the reason why the usb-storage, uas, and some sas driver do not handle this.
Driver need to operate generic devices, maybe the chip itself handling spindown must be the proper way. Sadly, chip manufactures often have their unique quirks.
Such as this Asmedia chip asm1135. :joy:
But if Chips do not handle this as a routine, then the driver should take responsibility to tackle with it.
I found the commit Damien Le Moal did last year for Firewire. It clearly show this type of device configuration need to be done within low level driver.

So as to usb-storage and uas, need to add

sdev->manage_runtime_start_stop = 1;
sdev->manage_shutdown = 1;

as well in their configuration.
For usb-storage:

For uas:

Other driver also need similar change to adapt Damien Le Moal changed last year.

I did made some mod in kernel for my own use. But I have never post a patch to kernel mailing list, I think it is not a easy thing to start.
So if someone is experienced and willing to make a patch for upstream kernel driver, I will be appreciated! :+1: :pray:

For average user who using kernel version 6.1 and beyond, as Harddisk spin down on shutdown no longer works mentioned.
Apply udev rule

ACTION=="add|change", DRIVERS=="usb-storage|uas", SUBSYSTEM=="scsi_disk", ATTR{manage_runtime_start_stop}="1", ATTR{manage_shutdown}="1"

is enough according to linux/drivers/ata/libata-scsi.c at eca631b8fe808748d7585059c4307005ca5c5820 · torvalds/linux · GitHub

For user using kernel before 6.1, apply the old udev rule.

ACTION=="add|change", DRIVERS=="usb-storage|uas", SUBSYSTEM=="scsi_disk", ATTR{manage_start_stop}="1"
2 Likes