To further build upon samiam's answer, you can set udev rules to do these things for you.
For this example, you'd have to fill in a file in /etc/udev/rules.d
(ideally name it something along the lines of 45-sdX-power.rules
to respect the conventions, but it doesn't really matter...), with the following:
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sdX", ATTR{queue/rotational}=="1", RUN+="/path/to/hdparm -S 1 /dev/sdX"
where you will need to fill in sdX
and provide the full path to the hdparm
binary (which hdparm
).
This will automatically stop your drive from spinning after 5 seconds of inactivity whenever your laptop boots.
This is ideal for a dual boot disk (my case), and backup disks you only startup once a week or so (in which case just mounting it before issuing your backup will turn it on and it will be off the rest of the time).
As for hdparm -Y /dev/sdX
, it is less useful here as it only stops the disk from spinning once, after which any access to the disk (like mounting it) will re-start it and you will have to issue the command again.
hdparm -Y
in the man which seems to set the drive in a deeper sleep mode. Is that not recommended? – Totor Feb 02 '14 at 17:24