I want to connect another hard disk to my computer, which I want to sleep 99% of the time. I will only use it for a few things, but I need it to be mounted at all times.

To achieve this I would like to know:

  1. How do I log which processes accesses a device? I need the logging to be able to tell what is causing the hard disk to wake up if it does, so I may act on it.
  2. Are there any special kernel settings I need to make so that the device may sleep longer?
  3. How do I set the sleep intervals of the hard disk?
link|improve this question

44% accept rate
feedback

4 Answers

http://en.wikipedia.org/wiki/Fuser%5F%28Unix%29 - fuser is a UNIX command used to show which processes are using a specified file, file system, or socket.

http://sourceforge.net/projects/hdparm/ - get/set ATA/SATA drive parameters under Linux (look for -S option)

http://sg.danny.cz/sg/sg3%5Futils.html - The sg3_utils package contains utilities that send SCSI commands to devices. As well as devices on transports traditionally associated with SCSI (look for sg_start)

link|improve this answer
Thanks for your informative answer! It looks like fuser only tells me which processes are using a file, filesystem och socket at the instance of issuing the command. While this is very useful if a process does something quick, like list the contents of the device root directory, I might miss it even if I have fuser running in a loop. If there were something which would wait and log all activity until I tell it to stop, it would be even more helpful in this situation. Do you know of any? – Deleted Dec 13 '09 at 11:12
I guess hdparam is what i'll use to setup wait time before sleeping? And the sg3_utils is just a powerful tool but I won't use it in this case? (As I guess I won't have to specifying manually when the HDD should sleep after setting it up using hdparam?) – Deleted Dec 13 '09 at 11:13
feedback

lsof +D /path/to/mount should show you every process which has any opened file in the path indicated.

link|improve this answer
feedback

Sleep interval is called "APM" (Automatic Power Management) and spindown_time. This is controlled with hdparm like this:

hdparm -B 50 -S 36 /dev/disk/by-label/BACKUP-HDD

It will make your HDD to spindown on ~3min inactivity.

link|improve this answer
feedback

btrace or blktrace (a wrapper of btrace) track kernel block I/O and can help you there.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.