I'm looking for a way to schedule when an external hard drive connected to my Linux (Debian 9) box goes to sleep (stops spinning).

To put this into content: I have a Linux box that runs as a multimedia server. If a call is made to fetch content that is on the external hard drive, it often takes 15-30 seconds for the hard drive to wake and start spinning which a) is frustrating and b) sometimes causes timeouts with the multimedia server. I could set the hard drive to be awake and spinning 24/7, but this seems a waste when most of the time I only use the multimedia server when I'm at home.

Is there any software tool or command I could use to set a weekly schedule for when the hard drive is spinning - e.g. Monday-Friday: SPINNING between 5pm and 11pm Saturday-Sunday: SPINNING between 3pm and 11pm OTHERWISE SPINNING on demand and sleep as per system timer

  • 1
    So you are decreasing disk run time, but starting/stopping your disk -40 times a week. Starting/stopping a disk is not without its costs. Unless electricity is very expensive where you are, it might not be worth the effort. – waltinator Jun 3 at 2:39
  • 1
    @waltinator Modern HDDs are designed to handle hundreds of thousands of start-stop cycles, so having one cycle per day is absolutely not harmful. It will literally take a thousand years to kill the HDD from excessive number of spin-downs at this rate. If anything, I would be more concerned about hours of useless spinning. – Dmitry Grigoryev Jun 3 at 11:47
  • @waltinator Fair argument, but the whole point is that this would actually result in a net DECREASE in spin ups/downs, as at the moment it spins up and down more or less every time content is requested from the multimedia server, particularly during the times I want scheduling. As you say, it probably costs more energy every time the drive spins up - so leaving it spinning in the evenings would probably level off energy use. – Alex Ward Jun 3 at 15:24

A cronjob would allow this:

# At 11pm every day, enable sleep after 30s
0 23 * * * /sbin/hdparm -S6 /dev/disk/by-id/...

# At 5pm on weekdays, disable sleeping
0 17 * * 1-5 /sbin/hdparm -S0 /dev/disk/by-id/...

# At 3pm on the weekend, disable sleeping
0 15 * * 0,6 /sbin/hdparm -S0 /dev/disk/by-id/...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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