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:
- 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.
- Are there any special kernel settings I need to make so that the device may sleep longer?
- How do I set the sleep intervals of the hard disk?
Sleep interval is called "APM" (Automatic Power Management) and spindown_time. This is controlled with
hdparm
like this:It will make your HDD to spindown on ~3min inactivity.
As you are on linux, you can use the new
fatrace
utility, which logs every file access and tells you which process is responsible:https://launchpad.net/fatrace
More information here:
http://www.piware.de/2012/02/fatrace-report-system-wide-file-access-events/
It makes use of the linux fanotify API (more details) available since linux kernel 2.6.37.
fatrace
isn't packaged by all distributions as of July 2014 (it entered debian testing recently, so should ship in 'jessie'), but is easy to install from source.I have similar issue. I have SSD,
/dev/sdb
, with OS (Linux Mint 18.1 based on Ubuntu Xenial) and HDD,/dev/sda
, with data, which I use time to time. Both disks are encrypted. HDD's partitions are not mounted. And anyway in periods of several minutes HDD wakes up, then sleeps, then wakes up again. Mess.Here is a duplicate question with helpful answer, which suggests
auditd
to find the bad-behaving process.Then I force HDD to sleep with
hdparm -Y /dev/sda
. Then wait until I hear HDD spinning up again. Then runausearch -f /dev/sda
. In my case it shows entries like the following.Relevant part is exe="/usr/lib/udisks2/udisksd". Though I also had
smartmontools
whosesmartd
was also the culprit. I uninstalledsmartmontools
and stoppedudisk2
service withservice udisks2 stop
. After that HDD sleeps as expected.Note that
udisks2
will automatically start when I, for instance, open Disks application, so I have to stop it again. Another downside is that SMART parameters are not monitored for both disk, which is not good but as a workaround it fits.Also one thing that is not clear, is that this bug report says
udisks2
doesn't do polling disks which is now done by kernel. But the evidence seems to indicate the contrary.http://en.wikipedia.org/wiki/Fuser_%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_utils.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)
btrace
orblktrace
(a wrapper ofbtrace
) track kernel block I/O and can help you there.lsof +D /path/to/mount
should show you every process which has any opened file in the path indicated.