Get USB HDD to sleep in Ubuntu automatically

I installed Ubuntu on my Android TV stick MK908 and have been using it as a low-powered home server. Tiny as it is , it delivers very decent performance. I set up mail, ftp, http, VPN ansd smb servers on it, and it’s been running pretty well so far. But one problem is that the USB HDD being attached to it got very hot in the morning. That means the USB HDD was not put into suspend mode even the computer had entered into standby mode. After googling for a while, i came across HD-IDLE, which can suspend your USB HDD after a specified period of time. and you can learn more about it on its project page

here’s the steps to install and configure it in Ubuntu

Download and Compile HD-IDLE

it’s a very small, easy-use program. just CD into the source folder, issue ‘make’ and an executable file named HD-IDLE will be generated in the same folder. Copy it to /usr/bin/

Start HD-IDLE at boot

copy the following scripts and save it in /etc/init.d/hd-idle


# Provides:          hd-idle
# Required-Start:    
# Required-Stop:     $local_fs
# Default-Start:     1 2 3 4 5
# Default-Stop:
# Short-Description: put USB HDD to sleep after a specified period of idle time
# Description: 

start () {
      if pgrep -f "$PROGRAM" 1>/dev/null;then
             echo "$PROGRAM_NAME is already running"
             exit 1
          "$PROGRAM" -a sda -i 600 -l $LOG_PATH
          echo "$PROGRAM_NAME is starting"
          sleep 1

stop () {

       if pgrep -f "$PROGRAM" 1>/dev/null;then
             killall "$PROGRAM" > /dev/null 2>&1

          if [ $? -eq 0 ];then
             echo "$PROGRAM_NAME is terminated"
  case $1 in 
       start) start;;
       stop) stop;;
       restart|reload) stop && start;;

then add execution permissions to it

chmod 755 /etc/init.d/hd-idle

Add startup links for it

update-rc.d -f hd-idle defaults

start it

service hd-idle start

This will put your USB HDD to sleep after it being idle for 6 minutes, and you can change the time in the initscript to whatever you like.