FS#60665 - USB external HDDs aren't properly powered off during system shutdown

Attached to Project: Arch Linux
Opened by magiblot (magiblot) - Thursday, 01 November 2018, 02:12 GMT
Last edited by Andreas Radke (AndyRTR) - Tuesday, 10 December 2019, 11:44 GMT
Task Type Bug Report
Category System
Status Closed
Assigned To No-one
Architecture x86_64
Severity Medium
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Hello,

I have Arch Linux installed on a SATA 2.5" HDD which I share between a netbook and a laptop. I usually take the netbook to college because it's more comfortable. Then, I properly install the drive in the SATA socket. However, at home, I often need more power and switch to the laptop. I use a SATA-to-USB adapter for this purpose, because it's too much trouble to change HDDs on this laptop (there are other solutions, but that's not the point).

When the drive is directly plugged through SATA, system shutdown carries out flawlessly. The drive peacefully spins down before the system shuts down completely. However, it's not the same when it's connected via USB. Power is cut while it's still spinning, so the disk makes a loud clicking noise (emergency head parking).

This has been quite an obscure problem for some time, since there are forum topics like https://ubuntuforums.org/showthread.php?t=1257395 or https://bbs.archlinux.org/viewtopic.php?id=189356 which got no clear answer.

A solution, as pointed out in https://forum.odroid.com/viewtopic.php?f=97&t=29069, is to create a systemd-shutdown script which takes care of parking the spinning drives immediately before the system powers off. This in fact used to work for me with a custom script I made (enclosed file issue-standby.shutdown) but, since a few time ago (I don't know why), stopped being effective.

This script uses hdparm to issue a standby command to all devices, the one mounted as root in last place. It can be appended to mdadm.shutdown (the file that's placed by default in /usr/lib/systemd/system-shutdown/) to make sure it is actually run the last. This no longer works because the root drive is for some reason accessed again after running this script, which, I insist, I can't tell if it's consequence of a regression or a setting of my own.

In order to investigate further into the issue, I modified the script to power the drive off instead of just spinning it down (with hdparm -Y). During system shutdown, after that happens, the console cursor keeps blinking for about 30s and then drive powers on again (in spite of hdparm's manpage stating a reset is required before the device can be again accessed) and the system finally shuts down (with the hard drive making the clicking noise again).

However, if I unplug the drive just after it is powered down by the script, then the following error messages are displayed and the system shuts down silently:

https://i.imgur.com/DxPwwGy.png

I followed the instructions in https://serverfault.com/questions/315700/how-to-determine-which-file-inode-occupies-a-given-sector to track down the files these sector numbers map to, and both turned out to belong to /usr/lib.

Anyway, removing this (unnecessary?) access to disk would only be a fix for the workaround. It seems to me that support for proper poweroff of external devices, just like it already is for SATA drives, should be provided by default. Although few users may be in the same situation, this is a clear danger for our device's health.

Thank you very much.
This task depends upon

Closed by  Andreas Radke (AndyRTR)
Tuesday, 10 December 2019, 11:44 GMT
Reason for closing:  Upstream
Additional comments about closing:  either a kernel task or user desired configuration
Comment by magiblot (magiblot) - Thursday, 01 November 2018, 02:17 GMT
systemd-shutdown script to spin drives down before system shutdown.

Loading...