Guest User

Untitled

a guest
Jan 15th, 2013
224
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/sh
  2. #
  3. # This script adjusts hard drive APM settings using hdparm. The hardware
  4. # defaults (usually hdparm -B 127) cause excessive head load/unload cycles
  5. # on many modern hard drives. We therefore set hdparm -B 254 while on AC
  6. # power. On battery we set hdparm -B 128; this still does not guarantee
  7. # disk parking, but is safer than causing lots of mechanical wear on disks
  8. # as we seem to get currently with 127.
  9. #
  10. # Refactored from acpi-support's 90-hdparm.sh for pm-utils
  11.  
  12. if grep -wq "nohdparm" /proc/cmdline ; then
  13. exit 0
  14. fi
  15.  
  16. # Do nothing when called via /etc/init.d/acpi-support; udev rules take care
  17. # of setting the initial hdparm policy for us.
  18. if ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ]; then
  19. exit 0
  20. fi
  21.  
  22. if [ -e /usr/sbin/laptop_mode ] ; then
  23. LMT_CONTROL_HD_POWERMGMT=$(. /etc/laptop-mode/laptop-mode.conf && echo "$CONTROL_HD_POWERMGMT")
  24. if [ "$LMT_CONTROL_HD_POWERMGMT" != 0 ] \
  25. && [ -e /var/run/laptop-mode-tools/enabled ]
  26. then
  27. # Laptop mode controls hdparm -B settings, we don't.
  28. exit 0
  29. fi
  30. fi
  31.  
  32. . /lib/hdparm/hdparm-functions
  33.  
  34. resume_hdparm_apm()
  35. {
  36. for dev in /dev/sd? /dev/hd? ; do
  37. if [ -b $dev ] && hdparm_try_apm $dev ; then
  38. # Check for APM support; discard errors since not all
  39. # drives support HDIO_GET_IDENTITY (-i).
  40. if hdparm -i $dev 2> /dev/null | grep -q 'AdvancedPM=yes'
  41. then
  42. for option in $(hdparm_options $dev); do
  43. case $option in
  44. -B*)
  45. apm_opt=$option
  46. ;;
  47. *)
  48. ;;
  49. esac
  50. done
  51. if [ -n "$apm_opt" ]; then
  52. hdparm $apm_opt $dev
  53. fi
  54. fi
  55. fi
  56. done
  57. }
  58.  
  59. resume_hdparm_spindown()
  60. {
  61. for dev in /dev/sd? /dev/hd? ; do
  62. if [ -b $dev ] && hdparm_try_apm $dev ; then
  63. # Check for APM support; discard errors since not all
  64. # drives support HDIO_GET_IDENTITY (-i).
  65. if hdparm -i $dev 2> /dev/null | grep -q 'AdvancedPM=yes'
  66. then
  67. for option in $(hdparm_options $dev); do
  68. case $option in
  69. -S*)
  70. apm_opt=$option
  71. ;;
  72. *)
  73. ;;
  74. esac
  75. done
  76. if [ -n "$apm_opt" ]; then
  77. hdparm $apm_opt $dev
  78. fi
  79. fi
  80. fi
  81. done
  82. }
  83.  
  84. case "$1" in
  85. true|false) # powersaving on/off
  86. resume_hdparm_apm
  87. ;;
  88. thaw|resume)
  89. resume_hdparm_apm
  90. # only set the -S option on resuming, not necessary for power.d
  91. resume_hdparm_spindown
  92. ;;
  93. *)
  94. exit 254
  95. ;;
  96. esac
RAW Paste Data