歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 利用pm.utils解決Ubuntu中Load/Unload Cycle Count問題(即Ubuntu傷害硬盤)

利用pm.utils解決Ubuntu中Load/Unload Cycle Count問題(即Ubuntu傷害硬盤)

日期:2017/2/28 16:14:01   编辑:Linux教程

本文修復load/unload cycle count部分參考了文章《Ubuntu中Load/Unload Cycle Count問題及解決》。

本文監控load/unload cycle count部分是自個寫的。

寫本文的目的是記錄自己如何解決該問題,為以後可能出現的重裝Ubuntu提供一個指引,備忘而已。

Ubuntu版本:10.04 lucid lynx

  1. 查看硬盤設備的路徑。替換後面3個disk腳本中的設備路徑。比如有兩個硬盤的話,使用"/dev/sda /dev/sdb"替換"/dev/sda"。
    1. sudo fdisk -l
  2. 新建文件/etc/pm/config.d/disk,並賦予可執行權限。文件內容如下:
    1. # Configure disk power management settings to ensure both
    2. # long disk life and good power management.
    3. #
    4. # Space delimited list of disk devices this affects.
    5. #
    6. DEVICES_DISK_PM_NAMES="/dev/sda"
    7. #
    8. #
    9. # Power management modes
    10. #
    11. # Powersave mode off
    12. # Set APM as 255
    13. ## Set spin-down for 30 minutes
    14. #
    15. DEVICES_DISK_PM_POWERSAVE_OFF="hdparm -q -B 255"
    16. #
    17. # Powersave mode on
    18. ## Enable APM to conservative 192 and set spin-down for 21 minutes
    19. #
    20. DEVICES_DISK_PM_POWERSAVE_ON="hdparm -q -B 254"
  3. 新建文件/etc/pm/power.d/disk,並賦予可執行權限。文件內容如下:
    1. #!/bin/bash
    2. #在power.d中加入Hook腳本,作用是在使用電池和AC電源的時候可以自動切換省電模式
    3. ./usr/lib/pm-utils/functions
    4. ./etc/pm/config.d/disk
    5. if test -z "${DEVICES_DISK_PM_NAMES}"; then
    6. exit 1
    7. fi
    8. case "$1" in
    9. true)
    10. echo "**enabled pm for harddisk"
    11. for DISK_NAME in `echo ${DEVICES_DISK_PM_NAMES}`; do
    12. ${DEVICES_DISK_PM_POWERSAVE_ON} ${DISK_NAME}
    13. done ;;
    14. false)
    15. echo "**disabled pm for harddisk"
    16. for DISK_NAME in `echo ${DEVICES_DISK_PM_NAMES}`; do
    17. ${DEVICES_DISK_PM_POWERSAVE_OFF} ${DISK_NAME}
    18. done ;;
    19. esac
  4. 新建文件/etc/pm/sleep.d/disk,並賦予可執行權限。文件內容如下:
    1. #!/bin/bash
    2. #在sleep.d中加入腳本,目的是在休眠/待機之後喚醒的時候重新設定hdparm的參數
    3. ./usr/lib/pm-utils/functions
    4. ./etc/pm/config.d/disk
    5. if test -z ${DEVICES_DISK_PM_NAMES}; then
    6. exit 1
    7. fi
    8. case "$1" in
    9. thaw|resume)
    10. /usr/bin/on_ac_power;
    11. if [ "$?" -eq 0 ]; then
    12. echo "**disabled PM for harddisk"
    13. for DISK_NAME in `echo ${DEVICES_DISK_PM_NAMES}`; do
    14. ${DEVICES_DISK_PM_POWERSAVE_OFF} ${DISK_NAME}
    15. done
    16. elif [ "$?" -eq 1 ]; then
    17. echo "**enabled PM for harddisk"
    18. for DISK_NAME in `echo ${DEVICES_DISK_PM_NAMES}`; do
    19. ${DEVICES_DISK_PM_POWERSAVE_ON} ${DISK_NAME}
    20. done
    21. fi
    22. ;;
    23. esac
  5. 確保laptop-mode是禁用的(默認就是禁用的)。查看文件/etc/default/acpi-support,看文件中是否有這一行:
    1. ENABLE_LAPTOP_MODE=true
    如果有這一行,表明laptop-mode是啟用的,那麼一定要設置為false!
那麼如何監控load/unload cycle count的數值呢?
  1. 安裝smartmontools。
    1. sudo apt-get install smartmontools
  2. 在家目錄下新建文件AskPassProg.sh,並賦予可執行權限。文件內容如下:
    1. #!/bin/bash
    2. # this file serves as sudo ask program, you must not delete this file.
    3. # if user 'bruce' 's password is changed, modify this file please.
    4. # 請修改字符串為你用戶的登錄密碼!
    5. echo "11111111"
  3. 在家目錄下新建文件monlcc.sh,並賦予可執行權限。文件內容如下:
    1. #!/bin/sh
    2. export SUDO_ASKPASS=~/AskPassProg.sh
    3. while true;
    4. do
    5. cur_date=`date`;
    6. lcc=`sudo -A smartctl -a /dev/sda | grep 193`;
    7. echo $cur_date : $lcc;
    8. echo $cur_date : $lcc >> monlcc.log;
    9. sleep 300;
    10. done;
    11. export SUDO_ASKPASS=""
直接執行monlcc.sh,就會在家目錄下生成一個文件monlcc.log,可以實時看到load/unload cycle count數值了。現在不用擔心ubuntu傷害硬盤了吧! 為了隨機啟動該腳本,你可以在啟動應用程序(系統->首選項->啟動應用程序)中添加相關配置。 命令輸入框顯示不全(易用性不夠啊同學!),全部命令如下:
  1. gnome-terminal --geometry +0+30 -e ~/monlcc.sh
Copyright © Linux教程網 All Rights Reserved