6

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:


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.

Ravexina
  • 55,668
  • 25
  • 164
  • 183

3 Answers3

2

When Western Digital devices are returning SG_IO errors it generally means that, while hdparm will perform some of the operations requested, it is not the correct tool for that particular disk. Instead, the sdparm 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:

sudo sdparm --flexible -6 -l --save --set SCT=3000 /dev/sdX
sudo sdparm --flexible -6 -l --save --set STANDBY=1 /dev/sdX

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 is 100ms). 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:

sudo sdparm --flexible -6 -l -a /dev/sdX
matigo
  • 22,138
  • 7
  • 45
  • 75
  • Although I was able to change the standby timer using --set SCT=3000 but it did not solved the real problem. STANDBY was already set to 1 with SCT of 18000. Drive still spins-up when I suspend the system and won't spin-down. What I'm looking for is actually to prevent the drive from spinning up in the first place when system is going to sleep. I also tested it with a WD My Passport drive and same thing happens. – Ravexina Apr 15 '22 at 10:07
  • It’s odd that your drives remain active after suspend. Mine, if not running at the time of suspend, will spin up then shut down almost immediately after the platters reach their optimal rotation speed – matigo Apr 15 '22 at 12:17
1

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.

enter image description here

Ravexina
  • 55,668
  • 25
  • 164
  • 183
0

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 using sudo powers and insert this code:

#!/bin/bash

Original script was using /bin/sh but shellcheck reporting warnings.

NAME: custom-xhci_hcd

PATH: /lib/systemd/system-sleep

CALL: Called from SystemD automatically

DESC: Suspend broken for USB3.0 as of Oct 25/2018 various kernels all at once

DATE: Oct 28 2018.

NOTE: From comment #61 at: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/522998

TMPLIST=/tmp/xhci-dev-list

Original script was: case "${1}" in hibernate|suspend)

case $1/$2 in pre/) echo "$0: Going to $2..." echo -n '' > $TMPLIST for i in `ls /sys/bus/pci/drivers/xhci_hcd/ | egrep '[0-9a-z]+:[0-9a-z]+:.$'; do # Unbind xhci_hcd for first device XXXX:XX:XX.X: echo -n "$i" | tee /sys/bus/pci/drivers/xhci_hcd/unbind echo "$i" >> $TMPLIST done ;; post/*) echo "$0: Waking up from $2..." for i incat $TMPLIST`; do # Bind xhci_hcd for first device XXXX:XX:XX.X: echo -n "$i" | tee /sys/bus/pci/drivers/xhci_hcd/bind done rm $TMPLIST ;; esac

  • Same result, however it seems while using this script Power-Off_Retract_Count is being incremented. – Ravexina Apr 15 '22 at 20:00
  • @Ravexina Hmm, I would think the script would make the drive behave the same as if the USB cable was unplugged. If you unplug the cable (don't do this with dirty buffers), does the drive automatically spin up? – WinEunuuchs2Unix Apr 15 '22 at 20:23
  • @Ravexina I found a program called hd-idle worth investigating if you haven't done that already. I've updated answer with links. – WinEunuuchs2Unix Apr 15 '22 at 21:01
  • I'm not sure why, but it seems that the script is not working as expected in my system. I guess it's somehow related to my USB ports as I just found out that I have the same problem in windows too. – Ravexina Apr 17 '22 at 19:10
  • @Ravexina Perhaps there is a diagnostics utility you can run? There is this one from WD but it boots from DOS. Mind you grub can chain load to DOS. – WinEunuuchs2Unix Apr 19 '22 at 00:45