#!/bin/sh # Script to fix the hard disk power management bug. # by Hansgeorg Schwibbe (hansgeorg.schwibbe@gmx.de) device=$1; deviceName="${device##*/}"; installRootPath="/etc/acpi/"; scriptName="hdparm-apm-"$deviceName".sh"; scriptPath=$installRootPath$scriptName; linkName="99-"$scriptName; linkPath1=$installRootPath"start.d/"$linkName; linkPath2=$installRootPath"resume.d/"$linkName; linkPath3=$installRootPath"ac.d/"$linkName; linkPath4=$installRootPath"battery.d/"$linkName; scriptCode="#!/bin/sh\n\n if on_ac_power; then\n \t# on AC so don't do any head parking\n \thdparm -B 254 $device\n else\n \t# either on battery or power status could not be determined\n \t# so quickly park the head to protect the disk\n \thdparm -B 253 $device\n fi\n"; case "$2" in install) echo "Installing power management fix for $device"; # test the block device if ! [ -b $device ]; then echo "$device is not a valid block device!"; exit 1; fi # construct the script echo $scriptCode > $scriptPath; chmod 0755 $scriptPath; # link the script ln -s $scriptPath $linkPath1; ln -s $scriptPath $linkPath2; ln -s $scriptPath $linkPath3; ln -s $scriptPath $linkPath4; exit 0; ;; remove) echo "Removing power management fix for $device"; # remove all installation files rm $scriptPath; rm $linkPath1; rm $linkPath2; rm $linkPath3; rm $linkPath4; exit 0; ;; *) echo "Usage: $0 device {install|remove}"; exit 1; ;; esac