Notice

I would now suggest that instead of trying to patch the Mandrake kernel as outlined below, you instead get the just released (Dec 4) 2.4.20 kernel from the cooker archives. I use ftp://ftp.sunet.se/pub/Linux/distributions/mandrake-devel/cooker/i586/Mandrake/RPMS and look for the kernel-2.4.20.... rpm. It contains a recent (more recent than the patch below for the 2.4.19 kernel) acpi patch.
The 2.4.20 kernel has disappeared from cooker and been replaced by an alpha version (ie probably has lots of bugs) of 2.4.21. You can find a copy of 2.4.20 on ftp.theory.physics.ubc.ca/outgoing/kernel-2.4.20.2mdk-1-1mdk The source file is kernel-2.4.20.2mdk-1-1mdk.src.rpm from cooker.

Also, if you want a little battery symbol on your desktop, the KDE Battery monitor is broken because the newer versions of ACPI changed the location of the battery infomation file in the /proc filesystem. KDE Battery Monitor will tell you that you do not have ACPI installed, even though you do.
Instead you can get the akpi (note the k, rather than c in the name) suite of programs from http://akpi.scmd.at/news.php who also have an rpm for Mandrake 9.0 which also puts a battery monitor on your desktop. You can start it automatically every time you run kde by putting a link to the binary in .kde/Autostart/ directory under your home directory.
cd ~/.kde/Autostart
ln -s /usr/bin/akpi akpi
You will also have to change the permissions on the pic files
chmod -R a+rX /usr/share/apps/akpi


Below is the old page in case you do want to try recompiling your Mandrake kernel.

Mandrake 9.0 and ACPI

Mandrake 9.0 is the latest offering of a Linux distribution from Mandrake and is supposed to be more user friendly than any previous distribution. Unfortunately this does not seem to be true for laptops. The kernel shipped with Mandrake 9.0 has no laptop power management which ships with the system. The kernel contains neither APM (Advanced Power Management), the old standard for managing the power etc on laptops, nor ACPI (Advanced Configuration and Power Interface) the newest offering from Intel/Microsoft to control a much broader range of features (ie it is supposed to combine the roles of both the PNP and APM in one package).

Linux, as expected, is a bit slow in implimenting ACPI but a concerted effort http://sourceforge.net/projects/acpi is being made to impliment it in concert with Intel. Unfortunately many laptop manufacturers as well are still behind the learning curve and have implimentations which are non-compliant, making Linux community's job harder.

However, Mandrake 9.0 impliments no power management whatsoever. They have purposely shut it off in their kernels. The usual advice is to download the standard Linux kernel from say www.kernel.org, download the latest ACPI patch from sourceforge, and then compile the kernel. The problem with this is that this means that all of the patches which Mandrake has made to the kernel (eg supermount) will not be available on that recompiled kernel.

The purpose of this note is to give some instructions for installing it into the Mandrake kernels, while retaining the Mandrake patches, etc. I have tried this on one laptop I have, and it seems to work (although that laptop does not seem to impliment many power saving features), but the amount of testing I have done is very limited.

Instructions.

Download the Mandrake kernel source. At the present this is
kernel-2.4.19.16mdk-1-1mdk.src.rpm
from a site like
ftp-linux.cc.gatech.edu/pub/mandrake/9.0/SRPMS/kernel-2.4.19.16mdk-1-1mdk.src.rpm or from one of the Mandrake mirror sites http://www.mandriva.com/en/ftp.php3

Then do
rpm -Uhv kernel-2.4.19.16mdk-1-1mdk.src.rpm
which will unpack the source into /usr/src/RPM/SOURCES.

Now go to http://prdownloads.sourceforge.net/acpi/acpi-20020918-2.4.19.diff.gz?download to download the latest ACPI patch for the 2.4.19 kernel.
Place the file acpi-20020918-2.4.19.diff.gz into /usr/src/RPM/SOURCES.

Go to the directory
cd /usr/src/RPM/SOURCES
and do
tar -xjf linux-2.4.19-q16.tar.bz2
which will create the directory
2.4.19-q16

Unzip the acpi patch.
gunzip acpi-20020918-2.4.19.diff.gz
Now copy the acpi file to the patches subdirectory of this directory.
cp acpi-20020918-2.4.19.diff 2.4.19-q16/patches/AB10_acpi-20020918-2.4.19.patch
Make sure you remember to put that "patch" extention at the end, and not leave it as .diff or the kernel patching routines will not find it.

Go to the patches subdirectory.
cd 2.4.19-q16/patches

We now need to remove the various Mandrake patches which may be in conflict with this patch. Carry out the following command
rm BA36* BB03* BB07* BB08* DB01* DM03*
These files all seem to conflict with the ACPI patch.
The files HB11* HB01* MC22* MS01* also reference acpi, but these do not seem conflict with the acpi patch. I left them in but do not know if they impliment anything which contradicts the latest acpi.

At this point also remove BA33* patch. This seems to have been a misguided attempt which does not work (at least on the compilers I use) to eliminate a preprocessor warning, but it replaces it with wrong code.

Finally, Mandrake makes Config files for any and all possible kernels, even if you specify (as I do later) that only one kernel be built.
cd ../scripts and edit the create_configs file. Toward the end (line 982), there is a whole list of
CreateConfig i386 up
type lines. Comment out all except for the type of kernel you want to compile (eg the above one). To comment them out, put a # as the first character on the line. Make sure that you do NOT comment out the last line, containing the closing curly bracket of the CreateConfigs() definition (line 1003). Save your changes and exit the editor.

Now you need to recreate the tar file
cd ../..
which should bring you back to the SOURCES subdirectory.
tar -cjf linux-2.4.19-q16.tar.bz2 2.4.19-q16

Now you need to edit the spec file.
cd ../SPECS
Using your favourite editor edit
edit kernel-2.4.spec

Here you need to enable acpi, and optionally only compile one of the kernels instead of wasting a huge amount of time compiling all of the kernel options Mandrake has.
First change the realrelease parameter to remind you that this is your kernel.
%define realrelease 17acpi
Now you want to choose just a single kernel to compile I choose the single processor version. This must be the same one as the line in the create_configs file which you left uncommented. The set of defines in my case looks like

%define build_up 1
%define build_smp 0
%define build_secure 0
%define build_enterprise 0
%define build_BOOT 0
# this is for the embebed folks
%define build_elan 0
%define build_acpi 1
However, Mandrake really really wants the secure and BOOT kernels, so even if you have said no to them, they insist later. So change
%ifarch %{ix86}
%define build_secure 1
%define build_BOOT 1
%endif
to
%ifarch %{ix86}
%define build_secure 0
%define build_BOOT 0
%endif
unless of course you want both the BOOT and the secure kernels. However these you can probably use the ones that ship with Mandrake, since you are unlikely to want to use these except briefly in cases of emergency.

Save the changed file, and do
rpm -ba ./kernel-2.4.spec
and wait. If you get a missing dependency error, you will need to install some additions rpms. One is libbinutils2-devel from CD3. Others are needed to create the kernel-doc rpm.
Huge masses of data will flow by, but at some point it will stop and ask for configuration of the new options which the ACPI patch introduced into the configuration. Say no (n) to the first, the CONFIG_ACPI_HT_ONLY option. Say m (for module) for the rest, except the TOSHIBA options, to which you can say n unless you have a Toshiba laptop.

If you did not edit the create_configs file, you will have to repeat this about 10 times since the rpm insists on making all of the config files, even if you are only compiling one of the kernels. Eventually it will start compiling, and finally, you should have a new kernel in /usr/src/RPM/RPMS/i?86 where the ? refers to the processor level your machine has. (eg, i686 for a PIII).

Now try out your new kernel. Install it with
rpm -ihv /usr/src/RPM/RPMS/i586/kernel-2.4.19.17acpi-1-1mdk.i686.rpm (or whatever architecture your laptop is). Make sure you use the "i" rather than the "U" option, or you can make your laptop totally inoperative, necessitating a complete reinstall. You will have to run
lilo
(assuming you use lilo as your bootloader) to make the new kernel available at boot time. Try booting with that new kernel. You will need to load the acpi modules that you created.
modprobe battery
modprobe fan
modprobe processor
etc. to load the various acpi modules.


Copyright W. G. Unruh. Any comments please send them to . This document may be reproduced as long as the author's name is not removed, and as long as any changes to the document are clearly marked as such and are sent to the author.