How to protect the harddisk through APS

From ThinkWiki
Revision as of 01:00, 12 April 2006 by Wyrfel (Talk | contribs) (Fedora Core)
Jump to: navigation, search

This page tells you how to make the Active Protection System work under Linux to protect your harddrive from damage in case of a notebook drop or other kind of impact while it is running.

How APS works in Linux

APS in Linux consists of four components on the software side:

The HDAPS driver exports a sysfs interface providing the acceleration values.

The hdaps_protect kernel patch exports a sysfs interface that enables an ide or sata disk to be protected by a userspace process.

The hdapsd userspace daemon monitors the acceleration values through the HDAPS interface and automatically initiates disk protection through the hdaps_protect interface - given that the movement exceeds a user specified threshold.

The optional KDE/GNOME applets provide a visual indication of the disk protection status and also a graphical interface for adjusting configuration options for hdapsd.

Installation

As mentioned above, the hdaps kernel driver found in recent kernels is only responsible for reading the accelerometer data and exporting it through the sysfs interface.

NOTE!
If you use tp_smapi, remember to include the option HDAPS=1 when installing tp_smapi.

In order to use this information to protect the disk, some additional steps are required.

  • Download and build the latest hdaps_protect disk protection kernel patches.
  • Enable the drivers in the kernel (requires kernel rebuild).
  • Download, build and configure the hdapsd userspace daemon.
  • Download and build one of the applets to get a real-time representation of the disk protection status.

Getting the files

Latest Sources
Debian
  • hdapsd and hdaps_protect:
# deb http://www.oakcourt.dyndns.org/debian/ ./
# deb-src http://www.oakcourt.dyndns.org/debian/ ./
Fedora see instructions here

Adding kernel support

A kernel patch is required for disk head parking and queue freezing.


Manually patching and compiling a kernel

As root go to /usr/src/linux

# patch -p1 < ~/hdaps_protect.20060409.patch

# make clean

# make

# make modules_install

Problem with unload capabilities check

You may get the following kernel message when the disk is protected (e.g., via # echo 1 > /sys/block/sda/queue/protect):

ata_scsi_issue_protect_fn(): unload support NOT reported..
scsi_protect_queue(): head park not requested, used standby!..

or

idedisk_issue_protect_fn(): unload support NOT reported..
ide_protect_queue(): head park not requested, used standby!..
ATTENTION!
Using HDAPS in the above state may cause frequent drive spin downs, thereby wearing out your hard disk.

If you see this, and you are sure that your drive actually does support unloading (all original drives sold with HDAPS-equipped ThinkPads do), then do the following.

Solution for kernel 2.6.16 or later

The patch for 2.6.16 now accepts a module parameter to override the parking capability detection.

Depending on your machine type, and whether the module is built into the kernel or not, you can use one of the following options:

If disk driver is built into kernel, add the following to your kernel boot parameters (e.g. /boot/grub/menu.lst):

   libata.protect_method=1
   ide-disk.protect_method=1

If disk driver is built as module, the following to your modprobe configuration (e.g., /etc/modprobe.conf):

   options libata protect_method=1
   options ide-disk protect_method=1

In both cases, if you know whether you use ide-disk or libata, you can drop the other line.

The value 1 means "unload the head even if the drive doesn't report it has this capacility". The other values are 2 ("standby even if unload is supported") and 0 (autodetect).

Solution for kernel 2.6.15 and older
diff -u linux-2.6.15.hdaps/drivers/ide/ide-disk.c linux-2.6.15.hdaps/drivers/ide/ide-disk.c
--- linux-2.6.15.hdaps/drivers/ide/ide-disk.c	2006-01-18 07:11:54.000000000 +0000
+++ linux-2.6.15.hdaps/drivers/ide/ide-disk.c	2006-01-18 07:11:54.000000000 +0000
@@ -869,7 +869,7 @@
 	else
 		printk(KERN_DEBUG "idedisk_issue_protect_fn(): unload support NOT reported..\n");
 
-	return ide_protect_queue(q, (drive->id->cfsse & (1 << 13)) ? 1: 0);
+	return ide_protect_queue(q, 1);
 }
 
 int idedisk_issue_unprotect_fn(request_queue_t *q)
diff -u linux-2.6.15.hdaps/drivers/scsi/libata-scsi.c linux-2.6.15.hdaps/drivers/scsi/libata-scsi.c
--- linux-2.6.15.hdaps/drivers/scsi/libata-scsi.c	2006-01-18 07:15:31.000000000 +0000
+++ linux-2.6.15.hdaps/drivers/scsi/libata-scsi.c	2006-01-18 07:15:31.000000000 +0000
@@ -661,7 +661,7 @@
 		printk(KERN_DEBUG "ata_scsi_issue_protect_fn(): unload support NOT reported..\n");
 
 	/* call scsi_protect_queue, requesting either unload or standby */
-	return scsi_protect_queue(q, ata_id_has_unload(dev->id) ? 1 : 0);
+	return scsi_protect_queue(q, 1);
 }
 
 static int ata_scsi_issue_unprotect_fn(request_queue_t *q)
Drives which have this problem
  • Hitachi HTS726060M9AT00 (7K60) on ThinkPad T43

Installing hdapsd

Manual compilation from source

  • Download the hdapsd sourcecode (see above)
  • Compile using # gcc -o hdapsd hdapsd-*.c
  • Run # ./hdapsd -d sda -s 12 -a (replace sda with your hard disk device; run # ./hdapsd without arguments for help)

Fedora Core

Fedora users can try the instructions here

Gentoo

Gentoo users can try this ebuild: http://bugs.gentoo.org/show_bug.cgi?id=119845

For Gentoo: (works fine with IBM X41 25254CG)

0.) Add hdapsd support in your kernel, as far as I can remember: device drivers -> hardware monitoring -> ... (you need it as modul if you want to use tp_smapi and hdaps, see tp_smapi topic)

1.) Download the ebuild, use same ebuild date as the kernel-patch

2.) Makes known the portage an extern ebuild path and add the following line to /etc/make.conf:

PORTDIR_OVERLAY="/usr/local/portage/" (or any other location)

3.) Creates directory /usr/local/portage and /usr/local/portage/app-laptop/

4.) Copy downloaded ebuild to /usr/local/portage/app-laptop (/usr/local/portage/app-laptop/hdapsd should now exists)

5.) Makes portage known the new ebuild and creat digist with:

ebuild /usr/local/portage/app-laptop/hdapsd/hdapsd-20060326.ebuild digest

6.) Optional: Copy source file to portage distfiles (if no internet connection is available):

cp hdapsd-20060326.c /usr/portage/distfiles

7.) Accept the x86 keyword for this package: echo "app-laptop/hdapsd ~x86" >> /etc/portage/package.keywords

8.) Install hdapsd with: emerge hdapsd

9.) Edit the /etc/conf.d/hdapsd file (change your harddrive if neccessary: my is sda, and change the value from 5, 5 is to sensitive, 12 is a good value in my opinion)

10.) start deamon with: /etc/init.d/hdapsd start

11.) Optional: add to default runlevel: rc-update add hdapsd default, rc-update add hdapsd battery


Write me an e-mail (abartel[äd]htwm.de), if you want to get my hdapsd-20060326.ebuild and please upload it (It's illagal from work)

Building an applet

Fedora users can try the instructions here

0.) Make sure you have installed hdaps [and loaded] and ?opengl?

1.) Download hdaps-gl-0.0.5 from the www

2.) Extract files to /opt/hdaps-gl

3.) # make

4.) Start applett # ./hdaps-gl

Building khdapsmon

Where is Gentoo ebuild http://bugs.gentoo.org/show_bug.cgi?id=124175.

Building gnome-hdaps-applet

Fedora users can try the instructions here


TODO
tell people what to do

Further Information

  • Additonal information and support is available through the hdaps-devel mailinglist and its archive.