Linux的好处不用讲,缺点也一大堆,实在是我等懒人不太好使用的。比如我的工作笔记本T61,坚持3年用下来,因为RHEL5.x操作系统没有集成电池充放保护模块,电池满的时候交流电也还在充,弄坏了2块电池,虽然是资本家出钱不心疼,总归不爽。朋友推荐Ubuntu下面有个tp_smapi模块什么的,可以像windows一样保护电池,google一把,发现Fedora这方面居然落伍了,没有将upstream集成进来,可惜可惜,只有麻烦点DIY了。
根据高手的指导,搞这个东东需要先使用akmods,装好akmod-tp_smapi之后,再进行modprobe装载smapi电池管理模块,最后设置充电起始和终止的阈值,细节如下:
点击这里下载为Fedora编译好的akmod模块,版本低点没关系。
解压后使用rpm -ivh akmod-tp_smapi-0.40-1.fc11.i686.rpm安装之,注意,这个rpm需要kernel devel的支持
调用service akmods restart,之后rpm -qa|grep smapi一下,可以看到为F14有关kernel弄好的rpm已经生成安装了
这时候可以使用modprobe -l| grep smapi看看模块是不是ready了,随后modprobe tp_smapi装载模块试试。
于是乎,可以使用下面的指令设置充电阈值,BAT表示笔记本默认的电池(BAT1好像是BIOS电池,不用管它)
- # echo 20 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
- # echo 80 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh
# echo 20 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
# echo 80 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh
做到这里,基本上4和5是在每次需要启用这个功能之前必须做的,因此,不如搞个service,缺省启动,用起来方便(/etc/init.d/tp_smapi):
- #!/bin/sh
- #
- # chkconfig: 12345 21 80
- . /etc/init.d/functions
- SMAPILOCK=/var/lock/tp_smapi_lock
- start()
- {
- echo -n $“Starting tp_smapi service: “
- /sbin/modprobe -q tp_smapi
- echo 20 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
- echo 80 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh
- echo
- touch $SMAPILOCK
- echo
- }
- stop()
- {
- /sbin/modprobe -r tp_smapi
- rm -f $SMAPILOCK
- }
- status()
- {
- status=0
- if [ -f $SMAPILOCK ]; then
- echo “RUNNING”
- else
- echo “UNUSED”
- status=1
- fi
- return $status
- }
- case “$1” in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart)
- stop
- start
- ;;
- status)
- status
- exit $?
- ;;
- *)
- echo “Usage: $0 {start|stop|status|restart}”
- exit 1
- ;;
- esac
#!/bin/sh每一次F14升级内核后,有关的akmod都要重新弄,偷懒写个脚本解决吧
#
# chkconfig: 12345 21 80
. /etc/init.d/functions
SMAPILOCK=/var/lock/tp_smapi_lock
start()
{
echo -n $”Starting tp_smapi service: ”
/sbin/modprobe -q tp_smapi
echo 20 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
echo 80 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh
echo
touch $SMAPILOCK
echo
}
stop()
{
/sbin/modprobe -r tp_smapi
rm -f $SMAPILOCK
}
status()
{
status=0
if [ -f $SMAPILOCK ]; then
echo “RUNNING”
else
echo “UNUSED”
status=1
fi
return $status
}
case “$1” in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
exit $?
;;
*)
echo “Usage: $0 {start|stop|status|restart}”
exit 1
;;
esac
- #!/bin/sh
- echo ‘looking for old rpms …’
- for rpm in `sudo rpm -qa| grep smapi`
- do
- echo undeploying $rpm …
- sudo rpm -e $rpm
- done
- echo ‘installing akmod …’
- sudo rpm -ivh akmod-tp_smapi-0.40–1.fc11.i686.rpm
- sudo /usr/sbin/akmods –force
- sudo service akmods restart
- echo ‘mod status:’
- sudo modprobe -l | grep smapi
- echo ‘set battery thresholds …’
- sudo service tp_smapi restart
- echo ‘done.’