LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Determining power status of USB hard disk (https://www.linuxquestions.org/questions/linux-general-1/determining-power-status-of-usb-hard-disk-4175435327/)

matthewg42 11-02-2012 12: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}

Thanks,
M

hunternet93 11-05-2012 02:49 PM

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

BoraxMan 11-09-2012 10: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 05:16 AM

How about:

hdparm:
Code:

hdparm -C /dev/sda
or with smartmontools
Code:

smartctl --nocheck=standby -i /dev/sda
Regards,
Stefan

matthewg42 11-10-2012 05: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:
Code:

# hdparm -C /dev/sdb
/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, http://smartmontools.sourceforge.net

CHECK POWER MODE: incomplete response, ATA output registers missing
CHECK POWER MODE not implemented, ignoring -n option
=== START OF INFORMATION SECTION ===
...

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 01: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 02: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:
Code:

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

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



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