http://www.aiview.com/2008/01/gentoo_linux_on_t43_9_hdaps.html

本文参考How to protect the harddisk through APS ,以下内容可直接应用于Gentoo Linux。

Thinkpad HDAPS 依靠笔记本内部的2D 加速度传感器检测笔记本位移, 将数据写入sysfs,系统中有一个demon (守护进程)负责监视这个sysfs interface,必要时执行硬盘磁头parking 动作。此外,有一个applet,可以在任务托盘实时反映当前的保护状态,这个不是必须的。

在Linux 上完整的HDAPS 包括以下几个部分:

  • hdaps 驱动程序,从硬件传感器读取数据(内核内置此驱动,但不要使用,推荐使用tp_smapi 提供的驱动)。
  • 内核 patch,负责向sysfs 写入数据,需要重新编译内核。
  • hdapsd,demon 程序
  • applet,有多种选择:gnome-hdaps-applet, khdapsmonitor 等,可以不安装,并不影响HDAPS 作用。

下面就以上4个部分分别讨论。

内核Patch

这一步需要提前来做。

根据自己的内核版本,找到相应的patch 下载另外一个下载地址),我的内核版本是2.6.23:

$ eselect kernel listAvailable kernel symlink targets:
[1]   linux-2.6.20-gentoo-r8
[2]   linux-2.6.23-gentoo *
[3]   linux-2.6.23-gentoo-r1

网络上没有找到版本完全符合的patch,但在2.6.23-kamikaze4 中找到了thinkpad-2.6.23-1.patch ,它里面包含了我们需要的protection patch,我将其提取出来,做成 hdaps-protect-2.6.23.patch ,可以单独使用。

用以下命令应用patch,并重新编译内核安装modules 。

# cd /usr/src/linux
# patch -p1 < ~/hdaps-protect-2.6.23.patch
# make && make modules_install

重新启动系统之后,会在sysfs 生成文件 /sys/block/xxx/queue/protect,表明patch 成功。

hdaps 驱动程序

首先要禁止内核中的驱动程序,确保以下内核选项没有被设置,否则,将在不同的路径生成两个同名的module hdaps,load 过程会出错。

$ zcat /proc/config.gz |grep -i hdaps
# CONFIG_SENSORS_HDAPS is not set

接下来在/etc/make.conf 的USE flag 中加入hdaps 支持,将会被tp_smapi 用到。

/etc/make.conf

USE="hdaps"

tp_smapi 已经被加入Gentoo package list,可以直接emerge,我目前使用0.31 版本。

# emerge -av app-laptop/tp_smapi

载入hdaps 与tp_smapi

# modprobe tp_smapi hdaps

并将其加入到/etc/modules.autoload.d/kernel-2.6

# Modules for Thinkpad HDAPS
tp_smapi
hdaps
hdapsd

安装demon,直接emerge 即可,我的版本是20060409-r1 。

# emerge -av app-laptop/hdapsd

编辑hdapsd 配置文件,在DISK 中指定需要保护的硬盘设备名称,作为可选,也可以调整保护动作阈值THRESHOLD ,值越小,保护动作越早,但也会更频繁。

/etc/conf.d/hdapsd

# The name of the disk device that hdapsd should monitor.
# Usually this is 'hda' or 'sda' the primary master.
DISK="sda"
# hdapsd sensitivity
# The lower the threshold is the earlier
# the heads are parked when the laptop is shaked
THRESHOLD="15"
# Set any extra options here, like -a for Adaptive mode
OPTIONS="-a"

启动hdaspd 服务

# /etc/init.d/hdapsd start

将hdapsd 设置为跟随系统自动启动

# rc-update add hdapsd boot
applet

如果希望监视硬盘保护状态,则需要安装applet 。我使用gnome 环境,因此选择了gnome-hdaps-applet ,但其还未被加入Gentoo 官方package list,需要下载回来自己编译安装。以下是步骤。

下载:

$ cd
$ wget http://www.zen24593.zen.co.uk/hdaps/gnome-hdaps-applet-20060120.tar.gz
$ mkdir gnome-hdaps-applet
$ tar -zxvf gnome-hdaps-applet-20060120.tar.gz -C gnome-hdaps-applet
$ cd gnome-hdaps-applet

编译:

$ gcc $(pkg-config --cflags --libs libpanelapplet-2.0) -o gnome-hdaps-applet gnome-hdaps-applet.c

安装:

# cp gnome-hdaps-applet /usr/bin
# mkdir /usr/share/pixmaps/gnome-hdaps-applet/
# cp *.png /usr/share/pixmaps/gnome-hdaps-applet/
# cp GNOME_HDAPS_StatusApplet.server /usr/lib/bonobo/servers

重启Xwindow,在applet 列表中可以找到新的项目,加入到panel 即可。

Tips 我在hdapsd 中设置的设备名为sda,但我的第二块硬盘sdb(在硬盘托架内)并没有受到保护,我尝试更改配置文件为sdb,保护动作正常,但无法对2个设备同时进行保护,hdaps project 邮件列表有一条关于此的讨论, 希望未来会支持多个设备
  • 如果没有安装applet,在那里查看硬盘的保护状态呢?可以用以下命令查看历史状态,也可以使用ctrl + alt + F12 查看实时状态。
$ dmesg |tail...
scsi_protect_queue(): head parked..
...
  • 我曾经在kernel-2.6.20-r8 下设置hdaps,但始终无法成功patch 内核,没有sysfs 数据写入,因此,hdapsd服务也无法启动成功。若有相似问题的用户可以尝试升级内核。
下载 hdaps-protect-2.6.23.patch (提取自 2.6.23-kamikaze4thinkpad-2.6.23-1.patch其它内核版本的protection patch另外一个下载地址gnome-hdaps-applet-20060120.tar.gz 延展阅读 How to protect the harddisk through APS Tp smapi HDAPS - IBM Active Protection System Linux Driver 部分版本内核Patch 与gnome-hdaps-applet 下载 Active Protection System hdapsd with multiple drives?(未完)
文章信息
版权声明: 本文可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息。
原文出处: http://www.aiview.com/
写于: 2008-01-30 [ Edit]
作者: Alex (email &msn)
mail.png
标签 Tags: gentoo (16), hdaps (1), linux (18), t43 (11), thinkpad (11)
« Gentoo Linux on T43 (8) X300 显卡的驱动以及3D 加速 | Home | Gentoo Linux on T43 (10) Fingerprint Reader 指纹认证 »