我在 Raspberry Pi (Raspbian) 上使用 BitTorrent Sync,同步外部硬盘驱动器 (ext4) 上的文件。我编写了一个小脚本,可在 5 分钟不活动后降低驱动器转速。当我读到一些东西时,它又开始旋转,所以看起来效果很好。
以下是通过 cronjob 每 5 分钟执行一次的 spindown 脚本:
# !/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
但几个小时后,硬盘被卸载,BT Sync 无法再正常工作。我想将它用作私人备份服务器,因此它应该始终运行。
它是通过/etc/fstab
这样的文件安装的:
/dev/sda5 /media/External ext4 defaults,noatime 0 0
有没有一种方法可以在驱动器卸载后立即自动重新安装驱动器,或者(甚至更好)阻止它这样做?
答案1
我会尝试通过更改硬盘上的电源管理设置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).