LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 11-02-2012, 12:33 PM   #1
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
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
 
Old 11-05-2012, 02:49 PM   #2
hunternet93
Member
 
Registered: Jun 2009
Posts: 87

Rep: Reputation: 31
I'm not sure how you'd do that. What are you trying to do?
 
Old 11-09-2012, 10:12 PM   #3
BoraxMan
Member
 
Registered: Apr 2010
Posts: 84

Rep: Reputation: 8
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.
 
Old 11-10-2012, 05:16 AM   #4
propofol
Member
 
Registered: Nov 2007
Location: Seattle
Distribution: Debian Wheezy & Jessie; Ubuntu
Posts: 261

Rep: Reputation: 50
How about:

hdparm:
Code:
hdparm -C /dev/sda
or with smartmontools
Code:
smartctl --nocheck=standby -i /dev/sda
Regards,
Stefan
 
Old 11-10-2012, 05:44 AM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Original Poster
Rep: Reputation: 62
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.
 
Old 11-11-2012, 01:52 AM   #6
propofol
Member
 
Registered: Nov 2007
Location: Seattle
Distribution: Debian Wheezy & Jessie; Ubuntu
Posts: 261

Rep: Reputation: 50
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.
 
Old 11-11-2012, 02:33 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,531
Blog Entries: 27

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
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
 
  


Reply

Tags
hard disk, power management, scripting, usb


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy of IBM Server hard disk data to Another USB External Hard disk mazharcdn Linux - Server 2 09-02-2009 12:41 AM
Help getting hard disk activity status from linux Ogi Programming 0 01-06-2008 05:00 PM
60GB laptop hard disk & 200GB external USB hard disk linux compatibility powah Linux - Hardware 0 03-07-2006 10:55 AM
How to set hard disk power management philb2k Mandriva 4 07-05-2004 03:42 PM
effect of power cut on hard disk and motherboard kushalshah Linux - Hardware 6 06-30-2004 03:50 PM


All times are GMT -5. The time now is 12:54 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration