Fedora Linux Support Community & Resources Center
  #1  
Old 13th December 2008, 02:43 PM
tonytiger Offline
Registered User
 
Join Date: Jun 2004
Posts: 168
How to turn off usb hard drive automatically?

Hi,
I have a usb hard drive, which i mainly use to back up my files (automatically using cron).
I'd like to keep the hd mounted after the back up is done, but switch the hd off, for it consumes energy and makes noise. The best solution would be if the hd is automatically turned off after, say 30 min, it has been accessed.

Any ideas?

Thank you.

-Tony
Reply With Quote
  #2  
Old 13th December 2008, 03:25 PM
marko Offline
Registered User
 
Join Date: Jun 2004
Location: Laurel, MD USA
Posts: 6,113
Quote:
Originally Posted by tonytiger View Post
Hi,
I have a usb hard drive, which i mainly use to back up my files (automatically using cron).
I'd like to keep the hd mounted after the back up is done, but switch the hd off, for it consumes energy and makes noise. The best solution would be if the hd is automatically turned off after, say 30 min, it has been accessed.

Any ideas?

Thank you.

-Tony
see hdparm -S option:
quoting hdparm man page
Quote:
-S Set the standby (spindown) timeout for the drive. This value is used
by the drive to determine how long to wait (with no disk activity)
before turning off the spindle motor to save power. Under such cir-
cumstances, the drive may take as long as 30 seconds to respond to a
subsequent disk access, though most drives are much quicker. The
encoding of the timeout value is somewhat peculiar. A value of zero
means "timeouts are disabled": the device will not automatically enter
standby mode. Values from 1 to 240 specify multiples of 5 seconds,
yielding timeouts from 5 seconds to 20 minutes. Values from 241 to
251 specify from 1 to 11 units of 30 minutes, yielding timeouts from
30 minutes to 5.5 hours. A value of 252 signifies a timeout of 21
minutes. A value of 253 sets a vendor-defined timeout period between 8
and 12 hours, and the value 254 is reserved. 255 is interpreted as 21
minutes plus 15 seconds. Note that some older drives may have very
different interpretations of these values.

Quote:
hdparm -S 241 /dev/sdc
option value 241 should result in 30 mins idle wait if /dev/sdc is the usb drive

The question is that hdparm has some features that don't work on usb drives,
this -S might be one.
Reply With Quote
  #3  
Old 13th December 2008, 05:38 PM
tonytiger Offline
Registered User
 
Join Date: Jun 2004
Posts: 168
This seems to be exactly what i'm looking for. However, i get the following message:
Code:
tony@tony-laptop:~$ sudo hdparm -S 241 /dev/sdb

/dev/sdb:
 setting standby to 241 (30 minutes)
 HDIO_DRIVE_CMD(setidle1) failed: Input/output error
tony@tony-laptop:~$
Does this mean the feature isn't supported for (my) usb hd?

-Tony
Reply With Quote
  #4  
Old 15th December 2008, 04:57 PM
fwelland Offline
Registered User
 
Join Date: Mar 2005
Location: US
Posts: 114
Well I don't know if the hdparam -S option will take you anywhere... I hope you find luck with that as I have a similar problem and wouldn't mind a solution.

Some of the research I did suggested you can't really 'tell' USB mounted HDs to spin down...Yes the HD when hooked via SATA or IDE may have this ability -- but when hooked via USB some of the finer control over the drive is lost as there is no way to send some of these commands to the drive via USB --- This was all stuff I did more than 1 year ago -- things may have changed or may not have been looking in the correct place.... I did see some fancy USB enclosures and USB raid things that did have some idle spin down 'stuff' built in to the USB enclosure -- but this was transparent to the USB host......

This not exactly what you are looking for -- but may generate some ideas:

In my case I wanted my USB drives to power up/down with my Fedora frankenbox that acts as my backup server accessible via NFS & SAMBA --- further I don't keep is powered on 24/7 and start it via WOL. I didn't mind the drives being fully powered while the backup server was ON.

As you probably know external USB enclosures/adapters usually have their own power supply. For me, these power supplies had a tendency to keep my drives spinning all the time -- even when the frankenbox was powered down (i.e. there is not 'relationship' between the PC's on-ness/off-ness and the powersupply for the USB drives). Where I could, I used power from the PSU of the frankenbox -- but I couldn't always do that.

Really what I wanted was some way I could turn on/off my USB drives via software. Not just spin them down -- physically power down/up.

There is actually a variety of network aware toggle switches and even more sophisticated stuff to power up/down stuff based on WOL packets and other control packets and protocols. These tended to get pricey -- but is pretty cool stuff.... It would be pretty easy, to get one of these and script up something that sent control packets to these switches after an idle timeout to turn/on off drives or even do more interesting stuff.....

In the end -- I found & bought USB Power relays. These plugged into standard wall socket. One outlet on the relay has constant power and the other socket only has power when the relay is activated by USB signal (i.e. just 5v power -- no actual data on USB input line). I used a simple USB cable from the frankenbox to the relay and the relays powered my USB drives....and then WOL was able to turn on 'everything'. When I shutdown the franken box -- the USB drives powered down too.....
Reply With Quote
  #5  
Old 15th December 2008, 08:33 PM
tonytiger Offline
Registered User
 
Join Date: Jun 2004
Posts: 168
Ok,
This is close to a solution
Code:
tony@tony-laptop:~$ sudo sg_start --stop /dev/sdb
This spins down the hard drive. Unfortunately, I don't know how to do this automatically.

There are also power option arguments for sg_start, but in my case those arguments seems to just spin down the hd similarly as the --stop argument does.


Tony
Reply With Quote
  #6  
Old 15th December 2008, 09:44 PM
fwelland Offline
Registered User
 
Join Date: Mar 2005
Location: US
Posts: 114
again probably not what you want -- but maybe generate some ideas...


I wonder if you can put a simple script in /etc/acpi/events to automate sg_start --stop ?


...Hm....but you want power down on inactivity of the device not the whole box -- so maybe ACPI is not the right thing...

I wonder if you could use iNotify for this? Maybe something like this:

configure inotify so that everytime you touch the filesystem that corresponds to your device; run a bit of script or code that deletes any existing device shutdown job(s) in CRON or AT; and creates a new device shutdown job for 30 mins in the future....

the device shutdown job would just be you sg_start --stop command....


Basically this is a 30 minute timer that shuts down your device. You reset the timer with every touch to that file system...
Reply With Quote
  #7  
Old 15th December 2008, 10:16 PM
marko Offline
Registered User
 
Join Date: Jun 2004
Location: Laurel, MD USA
Posts: 6,113
does this look good? (use spindown with sg_start )

http://www.linux.com/feature/132422
Reply With Quote
  #8  
Old 16th December 2008, 11:04 PM
tonytiger Offline
Registered User
 
Join Date: Jun 2004
Posts: 168
Ok,
The link http://www.linux.com/feature/132422 Marko pointed out is about a daemon called spindown http://code.google.com/p/spindown/. It works well.
To use the daemon on a usb hard drive, sg_start must also be installed. Other than that, there are no dependencies. The installation and configuration of the spindown is easy and well documented.

Problem solved! Thank you all.

Tony
Reply With Quote
Reply

Tags
automatically, drive, hard, turn, usb

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard drive dma issues (can't turn on DMA) Gustavo Melo Hardware & Laptops 1 5th November 2006 05:38 PM
USB hard drive not mounting automatically in FC2 guy Hardware & Laptops 9 1st February 2005 01:31 PM


Current GMT-time: 14:21 (Friday, 26-12-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
...Coomba Park - Kvilletorget - Chowking Festival Mall Alabang Photos on Instagram - Serebryanyye Prudy