本文修复load/unload cycle count部分参考了文章《Ubuntu中Load/Unload Cycle Count问题及解决》。
本文监控load/unload cycle count部分是自个写的。
写本文的目的是记录自己如何解决该问题,为以后可能出现的重装Ubuntu提供一个指引,备忘而已。
Ubuntu版本:10.04 lucid lynx
- 查看硬盘设备的路径。替换后面3个disk脚本中的设备路径。比如有两个硬盘的话,使用”/dev/sda /dev/sdb”替换”/dev/sda”。
- sudo fdisk -l
- 新建文件/etc/pm/config.d/disk,并赋予可执行权限。文件内容如下:
- # Configure disk power management settings to ensure both
- # long disk life and good power management.
- #
- # Space delimited list of disk devices this affects.
- #
- DEVICES_DISK_PM_NAMES=“/dev/sda”
- #
- #
- # Power management modes
- #
- # Powersave mode off
- # Set APM as 255
- ## Set spin-down for 30 minutes
- #
- DEVICES_DISK_PM_POWERSAVE_OFF=“hdparm -q -B 255”
- #
- # Powersave mode on
- ## Enable APM to conservative 192 and set spin-down for 21 minutes
- #
- DEVICES_DISK_PM_POWERSAVE_ON=“hdparm -q -B 254”
- 新建文件/etc/pm/power.d/disk,并赋予可执行权限。文件内容如下:
- #!/bin/bash
- #在power.d中加入Hook脚本,作用是在使用电池和AC电源的时候可以自动切换省电模式
- ./usr/lib/pm-utils/functions
- ./etc/pm/config.d/disk
- if test -z “${DEVICES_DISK_PM_NAMES}”; then
- exit 1
- fi
- case “$1” in
- true)
- echo “**enabled pm for harddisk”
- for DISK_NAME in `echo ${DEVICES_DISK_PM_NAMES}`; do
- ${DEVICES_DISK_PM_POWERSAVE_ON} ${DISK_NAME}
- done ;;
- false)
- echo “**disabled pm for harddisk”
- for DISK_NAME in `echo ${DEVICES_DISK_PM_NAMES}`; do
- ${DEVICES_DISK_PM_POWERSAVE_OFF} ${DISK_NAME}
- done ;;
- esac
- 新建文件/etc/pm/sleep.d/disk,并赋予可执行权限。文件内容如下:
- #!/bin/bash
- #在sleep.d中加入脚本,目的是在休眠/待机之后唤醒的时候重新设定hdparm的参数
- ./usr/lib/pm-utils/functions
- ./etc/pm/config.d/disk
- if test -z ${DEVICES_DISK_PM_NAMES}; then
- exit 1
- fi
- case “$1” in
- thaw|resume)
- /usr/bin/on_ac_power;
- if [ “$?” -eq 0 ]; then
- echo “**disabled PM for harddisk”
- for DISK_NAME in `echo ${DEVICES_DISK_PM_NAMES}`; do
- ${DEVICES_DISK_PM_POWERSAVE_OFF} ${DISK_NAME}
- done
- elif [ “$?” -eq 1 ]; then
- echo “**enabled PM for harddisk”
- for DISK_NAME in `echo ${DEVICES_DISK_PM_NAMES}`; do
- ${DEVICES_DISK_PM_POWERSAVE_ON} ${DISK_NAME}
- done
- fi
- ;;
- esac
- 确保laptop-mode是禁用的(默认就是禁用的)。查看文件/etc/default/acpi-support,看文件中是否有这一行:
- ENABLE_LAPTOP_MODE=true
那么如何监控load/unload cycle count的数值呢?
- 安装smartmontools。
- sudo apt-get install smartmontools
- 在家目录下新建文件AskPassProg.sh,并赋予可执行权限。文件内容如下:
- #!/bin/bash
- # this file serves as sudo ask program, you must not delete this file.
- # if user ‘bruce’ ‘s password is changed, modify this file please.
- # 请修改字符串为你用户的登录密码!
- echo “11111111”
- 在家目录下新建文件monlcc.sh,并赋予可执行权限。文件内容如下:
- #!/bin/sh
- export SUDO_ASKPASS=~/AskPassProg.sh
- while true;
- do
- cur_date=`date`;
- lcc=`sudo -A smartctl -a /dev/sda | grep 193`;
- echo $cur_date : $lcc;
- echo $cur_date : $lcc >> monlcc.log;
- sleep 300;
- done;
- export SUDO_ASKPASS=””
直接执行monlcc.sh,就会在家目录下生成一个文件monlcc.log,可以实时看到load/unload cycle count数值了。现在不用担心ubuntu伤害硬盘了吧!
为了随机启动该脚本,你可以在启动应用程序(系统->首选项->启动应用程序)中添加相关配置。
命令输入框显示不全(易用性不够啊同学!),全部命令如下:
- gnome-terminal –geometry +0+30 -e ~/monlcc.sh