Situation
I've got a WD Element Drive that behaves oddly. It took forever for the Drive to spin down, And I'm not able to set the standby (spindown) timeout for the Drive using different methods.
For example using hdparm
causes SG_IO
error:
$ sudo hdparm -S 25 /dev/sdx
dev/sdx:
setting standby to 25 (2 minutes + 5 seconds)
SG_IO: bad/missing sense data, sb[]: ...
It seems that the Drive's controller doesn't support these methods.
However, strangely I'm able to put the drive into standby mode using -y
switch:
$ sudo hdparm -y /dev/sdx
It gives the same SG_IO
error but drive spins down. And I'm fine with that.
Real problem
It seems that suspending Ubuntu, causes an effect similar to unplugging and plugging the drive.
When I want to suspend Ubuntu, say using: systemctl suspend
:
- If drive is on standby mode, it spins up and never spins down again.
- If it's not on standby mode, then it first spins down, after a second it spins up again and never spins down.
The only way to spin it down is to resume Ubuntu and run hdparm -y
on the drive manually and if I suspend Ubuntu again, the same thing happens.
What I already tried
I tried to run hdparm -y
on suspend to put the drive on standby
mode:
$ cat /usr/lib/systemd/system-sleep/suspend_drive
#!/bin/sh
case $1 in
pre)
hdparm -y /dev/sdc ;;
esac
It does not have any effect. And as I already said, while Ubuntu is going to sleep, drive first spins downs for a second anyway, and then it starts working again.
What I'm looking for...
Is there anyway to troubleshot this problem?
I'm looking for a solution to prevent the drive from spinning up in the first place when the system is going to sleep. And if the drive is already awake, it should go to standby mode with the system.
Notes:
- Running Ubuntu 20.04.
- I'm not interested in detaching the drive (or using any method that takes away the power from USB ports, as it has the same result of unplugging the drive).
- or using something like
udiskctl poweroff
. - Here is another similar question: Prevent external USB hard drive from spinning up during suspend to RAM
Updates
If I use
udisksctl power-off /dev/sdc
to safely remove the drive, suspending the Ubuntu acts like unplugging and re-pluging and I can mount and use the drive again (something that should not happen).I was able to set a standby timer for the drive using
sdparm
but it did not solved the issue, after suspending Ubuntu drive spins-up and never spins down, even if the timer is set to a small value like one minute.As I encountered different outcomes, I'm not 100% sure, but it seems that I'm only experiencing the problem while the drive is attached to a USB3 port.
- But USB2 has it's own problems too, for example after resuming Ubuntu drive spins-up.
I can confirm than I'm also experiencing the same problem in Windows.
When Western Digital devices are returning
SG_IO
errors it generally means that, whilehdparm
will perform some of the operations requested, it is not the correct tool for that particular disk. Instead, thesdparm
utility is required.For some of the USB3.0 WD disks I have around here, these are the settings that were required to have the things remain spun down after a connected notebook was suspended:
Note: Be sure to replace
/dev/sdX
with the correct device.The first command sets the device to spin down after 5 minutes (assuming the drive's
SCT
value is100ms
). The second command allows the drive to enter standby mode on its own.You can show all the parameters and settings for your disk with the following command:
Edit - Try
hd-idle
There are many reports how
hdparm
doesn't work properly with WD drives.The utility hd-idle is written for Linux.
Although its "claim to fame" is spinning down external drives after 10 minutes of inactivity, there may be a method of calling it to spin down during a suspend operation.
hd-idle
has been forked on GitHub. Options are provided to keep a log file and to spin down on demand.I've posted variations of this same answer many times in Ask Ubuntu. This variation comes from the Q&A:
( ... First part of answer is snipped ... )
Easier solution power off all USB ports
I recently ran into a problem where an unknown port was preventing laptop from suspending. I found this solution (credit in code) which I modified.
Create the file
/lib/systemd/system-sleep/custom-xhci_hcd
usingsudo
powers and insert this code:As I found out that putting the system in sleep mode acts like unplugging and re-plugging the drive, I got suspected that there might be some issues with the USB ports and their power source.
I went through the BIOS and set "Always On USB" to "Enable"; It seems that setting this parameter to Enable has fixed the issue.