I have a PC running Ubuntu 12.10 server as my custom home server. There are a number of hard drives connected to it via USB. The server runs 24-7 and I was wondering if there is any way or any commands that can be used to turn off the drives if they are not used and once a read/write request for the drive is submitted, the drives will automatically be turned on again to handle the request?

So I basically want a script that can do the following (if this is not digging to deep into the Linux kernel):

  1. If no read/write request to drive X was submitted for y minutes, turn of X and remember that X was connected.

  2. If a read/write request is submitted destined for X, turn on X and handle the request.

  3. Start from 1 again.

Some of these drives contain data that I sometimes don't use for weeks/months, so I don't want their lifespan to be reduced by just sitting there in idle. And I don't want to switch the drives on/off every time I use them.


Solution 1:

I think you are looking for the hdparm util which allows you to play with drive parameters.

Different drives take different parameters, and different disks have different levels of support for example -J wukk set a WD Green drives idle timeout. (but you probably want something like -S or conceivably -s, but man hdparm will provide the lowdown.