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 fi # 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?