BadRAM for RedHat Linux Kernels

Introduction

The BadRAM package allows one to use RAM that has bad areas in it, in a Linux-based computer. This is possible with the BadRAM kernel patch released by Rick van Rein.

The idea is to download the badram patch, apply it to the kernel source code, compile and install your own kernel, and then pass a command line parameter to the Linux kernel indicating which parts of your RAM are bad (and hence should be avoided).

I ran Memtest86 on a machine of mine and found a SIMM with one bad byte of RAM. It was a shame, I thought, to replace a 128 Meg SIMM just because of one bad byte. I'm using Redhat Linux (version 9) so I patched my kernel with the badram patch, and now my system just avoids the RAM page with the malfunctioning byte in it.

I downloaded version 2.4.20.1 of the BadRAM patch from here. I found that the patch did not apply cleanly to the kernel source I had. This incompatibility is likely the result of the extra enhancements and patches that Redhat adds to their kernel sources. No worries though, the incompatibilities between the kernel and the patch were pretty easy to fix, and I've released a new version of the patch that applies cleanly to both versions of the kernel released for Redhat version 9, kernel-source-2.4.20-8.i386.rpm and kernel-source-2.4.20-18.9.i386.rpm. The patch is available in the download area.

* New! * A patch is now available for the new 2.4.20-20.9 kernel! See the download area.

Patching the Linux Kernel

First, you have to get a copy of the kernel source. I used the kernel sources provided by Redhat. The kernel source package is called: kernel-source-2.4.20-8.i386.rpm for a default Redhat 9.0 system, and an upgraded version is now available called: kernel-source-2.4.20-18.9.i386.rpm.

You can tell if these packaged are installed by typing:

    rpm -aq | egrep kernel
If the kernel sources are installed, you will see them listed.

The kernel sources are usually kept in /usr/src. I used the following commands to patch the 2.4.20-8 kernel. Note that I also like to keep a backup copy of the unmodified kernel source handy too.

    cd /usr/src
    cp -R linux-2.4.20-8 linux-2.4.20-8.badram
    rm linux-2.4
    ln -s linux-2.4.20-8.badram linux-2.4
    cd linux-2.4
    patch -p1 <{path to the badram patch}/badram-2.4.20-8.patch.txt

Rebuilding the Linux Kernel

There are lots of good online resources with information on how to build the Linux kernel. See:

"Customizing Your Linux Kernel" at Linux Magazine

"Building a Custom Kernel" in the Red Hat Linux Customization Guide

"The Linux Kernel HOWTO" at the Linux Documentation Project

The basic idea is to execute the following commands. First, you have to be in the source directory.

    cd /usr/src/linux-2.4
Next, make any changes you desire to the Makefile. I like to change the EXTRAVERSION (line four) to be something like:
    EXTRAVERSION = -8-badram
You are supposed to start with make mrproper, but be careful! This command deletes the .config file, so back it up first!
    make mrproper
Now, configure the kernel. Be sure to enable "Work around bad spots in RAM" under the "General setup" menu.
    make menuconfig   or make xconfig
Now, build the kernel:
    make dep
    make clean
    make bzImage
    make modules
    make modules_install
Assuming everything goes well, the kernel and modules will be built. Note that there are lots of things that can go wrong during the kernel build, and I have found it very difficult to find information or help when things go awry. Basically, there's thousands of config options for the kernel, and some of them conflict in subtle ways. You've just got to keep trying until it works, and then keep a copy of that .config file for future reference. (It doesn't help that the first command of the kernel build process (make mrproper) deletes the current .config file.) If you run into trouble, start with a known working sample .config file, like the ones supplied by RedHat (see the configs subdirectory in the kernel source code.) The .config file I used is available for download in the download section.

Now, do whatever you have to, to install and reboot with your new kernel. How you do this depends upon which boot loader you are using. See Chapter 30 "Upgrading the Kernel" in the Red Hat Linux Customization Guide. Probably, though, you want to do a make install to copy the new kernel image and associated files to the /boot directory. This command also runs /sbin/new-kernel-pkg, which creates the initial RAM disk image. (More information on make install is available in Appendix 2 "Building the Kernel" in the Red Hat Linux Customization Guide.)

Check your boot loader config file. If you use GRUB, it's /boot/grub/grub.conf. There's no need to run GRUB after you change the GRUB config file. If you use LILO, see /boot/lilo.conf. For LILO, after you make changes to the config file, you have to run the LILO command (/sbin/lilo).

Don't forget, when you reboot, you're going to have to specify the correct badram parameter to the kernel. It is possible to specify the badram parameter in your LILO or GRUB config file (so you don't have to specify it every time you reboot the machine). For an example, see the example config files in the Appendix.

How you find the badram parameter is discussed next.

Memtest86

How do you know if you have bad RAM? How do you find-out what parts of your RAM are bad? For this, use the Memtest86 program. The Memtest86 program uses a series of complicated tests to scan your computer's RAM, and identify problems.

Memtest86 is a great memory testing program. Whenever you buy a new machine or start experiencing strange behaviour from your computer, you should download and run Memtest86 to check your RAM. Even if your computer runs fine you should occasionally run Memtest86 as it does a very thorough test of your computer's RAM.

Anyway, download it, install it, run it, and change the error reporting mode (when Memtest86 is running, press 'c' and then choose option 6, "Error Report mode"). This will provide you with the kernel parameter (badram=0xXXXXXXXX,0xXXXXXXXX, where 'X' is a hex digit) you need to specify to the BadRAM-patched kernel when it boots.

Appendices

Downloads

2.4.20-20.9       * New! *
The latest version of the RedHat kernel (version 2.4.20-20.9) is now out. I have created a new version of the BadRAM patch for this new kernel version: badram-2.4.20-20.9.patch.txt.
2.4.20-8 and 2.4.20-18.9
My version of the BadRAM patch for Redhat versions 2.4.20-8 and 2.4.20-18.9 of the kernel is here: badram-2.4.20-8.patch.txt.

.config

As noted earlier, if you experience difficulties building the kernel, it's likely to be caused by conflicting kernel options. Start with a .config file known to work, and modify only what you have to. The .config file I provide here has almost everything disabled producing a small, light-weight kernel (for example, USB, SCSI, and sound support has all been disabled).

This .config file was used for compiling the 2.4.20-20-9 version of the kernel: .config. Note that initially I had some trouble building the kernel, receiving error messages like this:

 .../include/linux/kernel.h:108 parse error before numeric constant
These errors were caused by enabling APIC and not SMP. Once I disabled APIC the errors went away. This .config file has the correct settings.

grub.conf

An example grub.conf file is available here: grub.conf. This file demonstrates how to specify the badram=... parameter to the kernel.

Applying the 2.4.20-8 patch to version 2.4.20-18.9

I have verified that this patch does apply and work on Redhat Linux kernel version 2.4.20-18.9. It does give a couple of warnings during the patch process, but the patch is correctly performed. I've transcribed the session when I applied the patch below. I had the upgraded kernel source (kernel-source-2.4.20-18.9.i386.rpm) and the BadRAM patch (badram-2.4.20-8.patch.txt) in my home directory.
[root@shannon root]# rpm -iv kernel-source-2.4.20-18.9.i386.rpm
Preparing packages for installation...
kernel-source-2.4.20-18.9
[root@shannon root]# cp badram-2.4.20-8.patch.txt /usr/src
[root@shannon root]# cd /usr/src
[root@shannon src]# cp -R linux-2.4.20-18.9/ linux-2.4.20-18.9.original
[root@shannon src]# cd linux-2.4.20-18.9
[root@shannon linux-2.4.20-18.9]# patch -p1 <../badram-2.4.20-8.patch.txt
patching file CREDITS
patching file Documentation/Configure.help
patching file Documentation/badram.txt
patching file Documentation/kernel-parameters.txt
patching file Documentation/memory.txt
patching file arch/i386/config.in
patching file arch/i386/defconfig
patching file arch/i386/mm/init.c
Hunk #3 succeeded at 470 with fuzz 2.
Hunk #4 succeeded at 532 (offset 8 lines).
patching file arch/i386/mm/pgtable.c
patching file include/asm-i386/page.h
patching file include/linux/mm.h
patching file mm/bootmem.c
patching file mm/page_alloc.c
[root@shannon linux-2.4.20-18.9]# exit

Author information

The Linux kernel was written by Linus Torvalds and many others.

The modified version of the Linux kernel used in RedHat Linux is from the good people at RedHat.

The BadRAM patch was originally written by Rick van Rein.

Memtest86 was written by Chris Brady.

This page, and the kernel patches modified to work with RedHat Linux kernels was done by William Soukoreff. Getting BadRAM working on my Redhat Linux machine was enough of a pain that I thought I'd put the patch and this little bit of text on-line, hoping it'll be useful to somebody else out there.