Since the cron job is scheduled to run every day 2 times, the drive sits idle for rest of the day. And after a couple of days, I noticed that the drive is getting really really warm
So, I started running hddtemp in my conky to keep a watch on the temperature and I realized that when I start my day,
$ hddtemp /dev/sdd
/dev/sdd: WDC WD30EZRX-00SPEB0: 30°C
After an hour or so,
$ hddtemp /dev/sdd
/dev/sdd: WDC WD30EZRX-00SPEB0: 48°C
Hmm... it is well within the operating range. (1-60, according to Spec here). But I don't like it. Must be using a lot of energy...
First I thought of keeping it switched off (the enclosure has a power switch). But I had to change my mind after 2 days... I keep the drive under the table and it was hard to reach. Also, I hit my head on the underside of the table ... ouch!
So, I want a mechanism to mount the drive when required and unmount it after I am done with my backup (BTW, I use luckybackp on Debian. It is a pretty neat tool for backing up data)
configuring autofs on debian/ubuntu
Install autofs# apt-get install autofs
Open /etc/auto.master and insert the following line (or similar one)
/export/esata /etc/auto.scsi --timeout=60,user,defaults,exec,suid,dev
This line tells autofs to use the map /etc/auto.scsi with mount options user,defaults,exec,suid,dev and impose a time out of 60 seconds for the mount point /export/esata
$ cat /etc/auto.scsi
wdgreen -fstype=auto :/dev/esata5
This tells automount to mount /dev/esata5 onto the directory wdgreen in /export/esata/ with file system type set to auto (will resolve to ext4, since I use ext4 on the partition)
For another drive in another system, I have the following entry
$ cat /etc/auto.usb
seagate1-2 -fstype=auto :/dev/disk/by-id/ata-ST31000528AS_6VPFKQAN-part2
Hmm... but how to make sure that the drive, when connected, will create a dev entry /dev/esata5?
[[By using /dev/disk/by-id/* entries, you can avoid the following udevadm gymnastics.]]
Udev is the answer
# udevadm info --query=name --attribute-walk /dev/sdd |less # replace sdd with your drive's block device
From the long list, pick an attribute that identifies the drive unambiguously. In my case, it is
ATTRS{model}=="WDC WD30EZRX-00SPEB0"
under
SUBSYSTEMS=="scsi"
A word of caution : the spaces within double quotes are important, do not miss them if you have space(s) at the beginning or end
Use this string to create a udev rule
# cat /etc/udev/rules.d/89-esata-disk.rules
SUBSYSTEMS=="scsi", ATTRS{model}=="WDC WD30EZRX-00SPEB0", SYMLINK+="esata%n"
Save the rule and restart udev (Sometimes you may need to restart the system, I have no idea why)
Now all is set
$ ls /export/esata
<nothing>
$ cd /export/esata/wdgreen
<will take a few seconds, you may hear the drive spinning up as well>
$ ls
<file list here>
Similarly,
$ cd /export/usbdisk/seagate1-2
$ ls
<file list here>
The auto.usb for that drive is here
$ cat /etc/auto.usb
seagate1-2 -fstype=auto :/dev/disk/by-id/ata-ST31000528AS_6VPFKQAN-part2
Putting the drive to sleep
# hdparm -y /dev/esata
/dev/esata:
issuing standby command
Shedule it in cron
# crontab -e
5,25,45 * * * * /sbin/hdparm -y /dev/
This means cron will issue the command to sleep every hour 5th, 25th and 45th minutes
You can run it at the interval you want. But please note that once the drive is in sleep mode, it takes 5-15 seconds to spin up and be accessible
After all these, when I check the temperature,
# hddtemp /dev/esata
/dev/esata: WDC WD30EZRX-00SPEB0 : drive is sleeping
# cd /export/esata/wdgreen
<takes around 10 seconds here ...>
$ hddtemp /dev/sdd
/dev/sdd: WDC WD30EZRX-00SPEB0: 34°C
Success!
Edit:
Apparently hdparm -y applies only to HGST drives (hitachi)
For other drives (e.g. ones connected over USB 3.0, you can use smartctl)
$ if [ -L /dev/disk/by-id/ata-ST31000528AS_6VPFKQAN ] ; then smartctl -d sat -s standby,60 /dev/disk/by-id/ata-ST31000528AS_6VPFKQAN ; fi
This commands sets the drive standby time to 300 seconds.
-d sat is for some USB to SATA chipsets. check smartctl for other possible values to use with -d option