How to use the Ksplice raw utilities

Disclaimer: I have no affiliation with ksplice, I’m just a guy who knows something about hot-patching the linux kernel and figured out how this ksplice thing works. I strongly agree with the sentiment that the ksplice raw utilities is not for general use. In fact, Ksplice says in the distribution of these tools:

Without the appropriate expertise and safety infrastructure, the raw utilities can create subtly incorrect rebootless updates, which can have serious consequences.

Take this warning very seriously. Whether or not you know what you are doing, expect that you will crash your kernel when you build an update and insert your own ksplice update. Building updates with the ksplice raw utilities is like using a loaded gun; if not aimed correctly, bad things happen.

For those of you who are still reading, welcome fellow tinker. In this post I describe the basic usage of the ksplice raw utilities to build a single ksplice update to your running system. I won’t cover building multiple updates as that has a whole other mess of issues to deal with.

This guide assume that you are running RHEL5 or a clone. At the time of this writing, it does not work on EL6 as Ksplice has not yet released an update to their source code, which is in violation of the GPL, but that’s a different issue.

Installing the raw utilities

Step 1: Get the ksplice raw utilities

$ git clone

If you don’t have git, install it. You’ll need it later on. I use the rpmforge repository and it has git.

Step 2: Build it from source

$ cd ksplice
$ autoconf
$ ./configure
$ make
$ sudo make install

Preparing your kernel source

Step 1: Download your kernel source

Assuming you have the yum-utils package installed on your system and have added the centos sources repository to your yum configuration, do this:

yumdownloader --source kernel-$(uname -r)

It is VERY important that the kernel source you are using matches your current running kernel. I can not stress this point enough. Operator beware, if the above command happened to download a kernel rpm that doesn’t match uname (unlikely, but it could happen) then you’ll want to hunt down the correct source rpm that corresponds to your running kernel.

In this example, we’ll assume you’re at the base 5.6 kernel; kernel-2.6.18-238.el5

Step 2: Extract your kernel source

Prior to 5.7, the kernel came as a mega load of patch files on top of the original 2.6.18 source tarball. For this reason, and because it’s a good idea anyway, we’re going to use the rpmbuild command to prepare the kernel source tree.

Setup your user to build rpms as a non-root user and do the following:

$ rpm -U kernel-2.6.18-238.el5.src.rpm
$ rpmbuild -bp rpmbuild/SPECS/kernel-2.6.spec
$ mv rpmbuild/BUILD/kernel-2.6.18/linux-2.6.18.x86_64 kernel-2.6.18-238.el5
$ cd kernel-2.6.18-238.el5

Step 3: Save the current state of the source

You’re now in your kernel source directory. To make things easier on yourself, use git to create a repository. You can create patch files of changes to the kernel with ease, and revert back to the original state on the fly. Create the repository:

$ git init
$ git add *
$ git commit -m "Initial commit, 2.6.18-238.el5"

Build your ksplice update

Step 1: Apply your patch(es)

This is where you start your editing. Make your changes either by hand, or by applying your patch(es) to the tree. Once you are done with your work, create your patch file and reset the working directory:

$ git diff > ~/my-ksplice-diff.patch
$ git checkout -f .

Step 2: Copy over your kernel symbol mapping files

Make sure you have the correct kernel-devel package installed, and do this:

$ mkdir ksplice
$ cp /boot/ ksplice/
$ cp /usr/src/kernels/2.6.18-238.el5-x86_64/Module.symvers ./

It is VERY important that the kernel symbol files you are copying matches your current running kernel. This is very similar to the above warning about choosing the correct kernel source.

Step 3: Run ksplice-create

The following sets you up to create the update. Replace the “XXX” with your number of CPUs.

$ ksplice-create --prebuild . -j XXX

At this point go grab a cup of coffee, use the restroom, and slack off until it’s all done. It has to do a full kernel build.

Now you’re ready to create the update itself. Remember, replace the XXX with your number of CPUs. Also, change /PATH/TO/ to the path to the patch, as the ksplice tool (currently) doesn’t correctly expand ~ to your home directory:

$ ksplice-create --id=myupdate --patch=/PATH/TO/my-ksplice-diff.patch . -j XXX

Your build should end with:

Ksplice update tarball written to ksplice-myupdate.tar.gz

Apply your ksplice update

Now, su - to the root user, and apply the update:

# ksplice-apply /PATH/TO/kernel-2.6.18-238.el5/ksplice-myupdate.tar.gz

NOTE: If ksplice-apply gives “command not found”, then check your path, it gets put into the /usr/local/sbin directory.

To view currently applied ksplice updates in your running system, run ksplice-view:

# ksplice-view

To remove it, run:

# ksplice-undo myupdate

It’s a simple complicated as that.

Have a good day!

This entry was posted in Fun, ksplice, Linux. Bookmark the permalink.

One Response to How to use the Ksplice raw utilities

  1. Pingback: What some (many?) people don’t understand about the GPL | cormander's blog

Leave a Reply