VirtFoundry Rotating Header Image

Patch and Rebuild Redhat Kernel for atop enhanced statistics

I recently saw an example of topas running in a colleague’s putty session, and wondered whether a similar advanced utility existed for Linux. While top is good for the quick and dirty view into Linux goings on, there surely must be a utility that gives a more detailed view into Linux resource usage, like topas does for AIX. So I did some looking around and found atop. In order to get the full benefit of additional per-process statistics from atop, kernel patches are needed that provide the necessary counters. I thought this was a good opportunity to do two things then. Patch a Redhat Enterprise kernel to get full benefit of atop and then recompile the newly patched source into an installable kernel RPM. This will also yield a kernel-devel RPM that we will need in order to recompile VMWare guest modules, I need this because this devel environment is a RHEL5.2 VMWare server 2 guest.

Let’s get to it then.

Goals:

  • Illustrate process of patching and rebuilding the RHEL5 kernel into the binary kernel package and the kernel devel package
  • Make atop extended features, per process disk and network I/O stats, available
  • Illustrate building modules against this modified kernel, using the kernel development package
  • Environment:
    VMWare Server 2
    Redhat Enterprise Linux 5.2

    Get kernel src.rpm file
    ftp://ftp.redhat.com/pub/redhat/linux/enterprise/5Server/en/os/SRPMS/

    Install
    rpm -ivh kernel-2.6.18-92.el5.src.rpm

    Extract
    cd /usr/src/redhat/SPECS/
    rpmbuild -bp --target=i686 kernel-2.6.spec

    I’ll take the opportunity here to say that this RHEL5 guest is a development environment, so I don’t care about building the kernel RPM as root. But a more appropriate method can be seen here if you prefer.

    Get and extract atop kernel patches for kernel version 2.6.18
    Download the patch tar file from atop website: http://www.atcomputing.nl/Tools/atop/download-patch.html
    For this, I grabbed atoppatch-kernel-2.6.18.tar.gz and extracted
    cd ~
    tar xvzf atoppatch-kernel-2.6.18.tar.gz
    cd atoppatch-kernel-2.6.18/

    Copy atop patch files into build environment sources directory
    cp 01patch-2.6.18_atopcnt /usr/src/redhat/SOURCES/linux-2.6-atop_atopcnt.patch
    cp 02patch-2.6.18_atopacct /usr/src/redhat/SOURCES/linux-2.6-atop_atopacct.patch

    Edit the source RPM spec file to enable the application of these patches during kernel RPM build
    cd /usr/src/redhat/SPECS
    vim kernel-2.6.spec

    Add references to the atop patch files and add the lines for the actual application of them during the build. Only relevant sections of the spec file are shown
    We should also modify the release name to better distinguish that this is with atop changes. It will result in a kernel named 2.6.18-92.atop.el5

    %define release 92.atop%{?dist}%{?buildid}
    ~
    ~
    Patch22556: linux-2.6-scsi-cciss-allow-kexec-to-work.patch
    Patch22557: linux-2.6-fs-race-condition-in-dnotify.patch
    # locally added atop patches
    Patch55555: linux-2.6-atop_atopcnt.patch
    Patch55556: linux-2.6-atop_atopacct.patch

    # adds rhel version info to version.h
    Patch99990: linux-2.6-rhel-version-h.patch
    # empty final patch file to facilitate testing of kernel patches
    Patch99999: linux-kernel-test.patch
    ~
    ~
    %patch22556 -p1
    %patch22557 -p1
    %patch55555 -p1
    %patch55556 -p1

    Build the base kernel
    time rpmbuild -bb --target=i686 --with baseonly --without kabichk kernel-2.6.spec

    Since we have modified the configuration to accomodate our patches, we need to use the –without kabichk flag to avoid
    *** ERROR – ABI BREAKAGE WAS DETECTED ***
    and the subsequent RPM build error

    Install the new kernel and kernel development packages
    rpm -ivh --force /usr/src/redhat/RPMS/i686/kernel-2.6.18-92.atop.el5.i686.rpm
    rpm -ivh --force /usr/src/redhat/RPMS/i686/kernel-devel-2.6.18-92.atop.el5.i686.rpm

    Edit /boot/grub/grub.conf to default to this new kernel, or select it at the grub boot menu at boot. Reboot and re-run vmware-config-tools to recompile guest OS modules against this new kernel, pointing the installer to the header files directory provided by the kernel-devel package: /usr/src/kernels/2.6.18-92.atop.el5-i686/include

    Now install the atop package
    rpm -ivh atop-1.23-1.i386.rpm

    Now that we patched the kernel with atop changes, rebuilt it and booted from it, we have access to the additional atop features.

    Leave a Reply