1

My intention is to spin-down an external USB drive after 20 minutes of not being used. In the normal case I would use hdparm for this but unfortunately this doesn't work on my external USB drive. It gives me errors like this:

hdparm -S240 /dev/sdc

/dev/sdc:
 setting standby to 240 (20 minutes)
SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Then I head of sgparm.

sdparm --flexible -C stop /dev/sdc
    /dev/sdc: SAMSUNG   HD153WI 

It spins down the disk for less than one second and then immediately spins up again. Even if the filesystem is not mounted.

Then I found out that

eject /dev/sdc

indeed spins down the disk but also unmounts it.

The next idea was to use automount to mount the drive when someone accesses its mount-path in the filesystem. Mounting works but after the drive unmounts, it doesn't spin down. What I want to do is to execute the eject command as above after automount unmounts the drive.

Do you have any ideas how to do that? Or even better do you have an easier solution?

1

I reasonably sure, that automount does not have post-unmount options. But I found something in the sdparm (1.07) manpage:

-r, --readonly

override other logic to open DEVICE in read-only mode. This option may be useful if a command is being sent to an ATA disk via a SCSI command set. For example in Linux '-C stop' may require this option to stop an ATA disk being restarted immediately.

I don't have a USB-harddisk at the moment, os I cannot test it, but this seems to match the problem you are having. I'm not sure how to measure the idle time of the drive, though.

If the disk does not stay of dispite this option you may have run into this problem described in the same man-page:

In the Linux 2.6 series, especially with ATA disks, using sdparm to stop (spin down) a disk may not be sufficient and other mechanisms will start the disk again some time later. The user might additionally mark the disk as "offline" with 'echo offline > /sys/block/sda/device/state' where sda is the block name of the disk. To restart the disk "offline" can be replaced with "running".


You also could combine automount with eject. That is use automount for mounting and eject for unmounting. It seems to work just fine, but eject has to run with root-permissions.

  • Hi Adaephon, thank you for your comment. I will try your suggestions when I'm at home and will let you know if it works. – Björn Jacobs Nov 19 '13 at 16:34
  • I tried you suggestions with success. Although the disks spins right up even with the -r parameter when it's mounted, it doesn't spin up when it's unmounted. This will be sufficient for me, with this I can build a script that automounts the drive and unmounts and stops it when it's not used for a while. I'll post a link when I'm done with the script. :) – Björn Jacobs Nov 19 '13 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.