-   Linux - General (
-   -   Determining power status of USB hard disk (

matthewg42 11-02-2012 01:33 PM

Determining power status of USB hard disk
I have an external USB hard drive which has a couple of truecrypt partitions used for backups and such.

If the disk has been idle for a while, it spins down as part of the power management features (using stock Kubuntu with default power settings).

From a script I want to be able to determine if it has spun down or not. I also want to be able to issue a command to make it spin up again. I suppose just touching a file would do that, so it's not a problem... but determining if it has gone into power saving - does anyone know how to do this?

Device is /dev/sdb, partitions /dev/sdb{1,2,3}


hunternet93 11-05-2012 03:49 PM

I'm not sure how you'd do that. What are you trying to do?

BoraxMan 11-09-2012 11:12 PM

I'm not sure either, but I think the information might be in the /sys directory heirachy

Go to /sys/bus/usb/devices
there will be some directories representing devices and one will correspond to the USB device

In the case of my WD Elements drive, its 1-2

the 'dmesg' command will tell you, with a line like.

usb 1-2: Manufacturer: Western Digital

Somewhere in this directory heirachy, is a file which may have the information you seek.

propofol 11-10-2012 06:16 AM

How about:


hdparm -C /dev/sda
or with smartmontools

smartctl --nocheck=standby -i /dev/sda

matthewg42 11-10-2012 06:44 AM

I had previously looked at the hdparm manual page, but couldn't figure out how to use it. I think it's no good with my specific device... same goes for the smartctl approach:

# hdparm -C /dev/sdb
SG_IO: bad/missing sense data, sb[]:  70 00 01 00 00 00 00 0a 00 00 00 00 00 1d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 drive state is:  unknown

# smartctl --nocheck=standby -i /dev/sdb
smartctl 5.43 2012-06-30 r3573 [i686-linux-3.5.0-18-generic] (local build)
Copyright (C) 2002-12 by Bruce Allen,

CHECK POWER MODE: incomplete response, ATA output registers missing
CHECK POWER MODE not implemented, ignoring -n option

I guess this means for my USB drive it is not possible to get this information. No biggie. I was just curious if there was a good method. Thanks for the response.

propofol 11-11-2012 02:52 AM

The problem could be the usb drive enclosure. It may be worth taking the drive out of the enclosure, attach it to an internal sata & power connector and try again.

catkin 11-11-2012 03:33 AM

Maybe sdparm would work. I have successfully used it to stop USB HDDs spinning but have not used it to report their status (listening to the drive spin down gave the required confirmation).

sdparm requires a /dev/sg* argument. The sgutils package is the easiest way to find the /dev/sg* corresponding to a /dev/sd* device file but the same info can be found via the /sys tree. Here's a bash scrippet that does it. It requires $disk_dev_file to be something like /dev/sdc:

    # Get the /dev/sg* corresponding to /dev/sd*
    buf=$( stat --format %N /sys/block/$sdX 2>&1 )
    buf=$( stat --format %n /sys/$buf/scsi_generic/* )

    # Run sdparm using the /dev/sg*
    sdparm <your chosen options> $dev_sgX

All times are GMT -5. The time now is 03:18 PM.