I am using BitTorrent Sync on my Raspberry Pi (Raspbian) which syncs files on the external hard drive (ext4). I wrote a small script that spins down the drive after 5 minutes of inactivity. As soon as I read something it starts to spin again, so that seems to work fine.

Here is the spindown script which is executed every 5 minutes via cronjob:

# !/bin/sh

# Get new state from diskstats
NEWstate=$(cat /proc/diskstats | grep $1)
echo $NEWstate > /home/pi/bin/spindown/NEWstate.txt

# compare md5 sums
md5new=$(md5sum /home/pi/bin/spindown/NEWstate.txt | sed 's/ .*//')
md5old=$(md5sum /home/pi/bin/spindown/OLDstate.txt | sed 's/ .*//')

# if no changes, power down
if [ "$md5new" = "$md5old" ]; then
        sdparm --flexible --command=stop /dev/$1 &>/dev/null

# Write current state to file
echo $NEWstate > /home/pi/bin/spindown/OLDstate.txt

But after a few hours the hard drive is being unmounted and BT Sync can not work properly anymore. I want to use it as a private backup server so it should run all the time.

It's mounted via the /etc/fstab file like this:

/dev/sda5 /media/External ext4 defaults,noatime 0 0

Is there a way that remounts the drive automatically as soon as it gets unmounted or (even better) prevents it from doing so?

  • How are you mounting the external drive? – jasonwryan Nov 5 '13 at 21:07
  • Via /etc/fstab with default settings – Nixatty Nov 5 '13 at 21:12
  • Maybe it depends on the spindown script which uses sdparm after the hard drive has been inactive for 5 minutes. But does Raspbian unmount a spinned down drive? – Nixatty Nov 5 '13 at 22:13
  • 1
    /etc/fstab looks good. Please post the script you are using. – jasonwryan Nov 5 '13 at 22:15
  • I updated the question. The script works fine and the drive is spinned down after 5 minutes of inactivity. – Nixatty Nov 5 '13 at 22:29

I would try changing the power management setting on the HDD via hdparm.

$ hdparm -B <value> /dev/sdx


-B     Query/set Advanced Power Management feature, if the drive supports it. 
       Allow value means aggressive power  management  and  a high value means 
       better performance.  Possible settings range from values 1 through 127 
       (which permit spin-down), and values 128 through 254 (which do not permit
       spin-down).  The highest degree of power management is attained  with a 
       setting of 1, and the highest I/O performance with a setting of 254.  A 
       value of 255 tells hdparm to disable Advanced Power Management altogether 
       on the drive (not all drives support disabling it, but most do).
| improve this answer | |
  • Thank you, but the drive doesn't seem to support hdparm. – Nixatty Nov 6 '13 at 18:18

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.