Kernel Packaging

Note: This tutorial assumes that you know how to compile a kernel already. It only looks at a way of creating a package and doesn't aim to show kernel config options.

Note 2: We won't be using the stock Slackware kernel SlackBuilds.

Kernel Output Target Option

The usual way to make any sort of package is via the $DESTDIR variable. The kernel doesn't use this however, but it does have an O switch which does almost the same thing, although the output might not be exactly what you expect. I will not be using that option here.


Copy your .config into the source directory and do

make menuconfig

(or whichever method you prefer.)

You may need to do 'make mrproper' first, and perhaps 'make oldconfig'.


Note: Do not use 'make install' or 'make modules_install', even with O switch, as this *will* install to /boot and /lib/modules.

At this point everything we need is in the source directory. The file modules.order lists the modules to be installed and we can use that to help us make a package.

Installing Modules and Kernel to our Package Directory

Ok let's use /tmp/kernel-package for our package directory. Also let's assume a kernel with jabberwok as local name. A little bash will copy our modules to it:

for i in $(sed "s#^kernel/##" modules.order)
mkdir -p $LIBSDIR/$(dirname $i)
install -m 644 -v $i $LIBSDIR/$(dirname $i)

Now we need the kernel and associated files.

mkdir /tmp/kernel-package/boot
cp arch/x86/boot/bzImage /tmp/kernel-package/boot/vmlinuz-
cp /tmp/kernel-package/boot/
cp .config /tmp/kernel-package/boot/config-

And then the and slack-desc.

mkdir /tmp/kernel-package/install

## Taken from stock modules package
if [ -x sbin/depmod ]; then
chroot . /sbin/depmod -a > /dev/null 2> /dev/null

(cd lib/modules/ ; rm -rf build)
(cd lib/modules/ ; ln -sf /usr/src/linux- build)
(cd lib/modules/ ; rm -rf source)
(cd lib/modules/ ; ln -sf /usr/src/linux- source)


# The "handy ruler" below makes it easier to edit a package description. Line
# up the first '|' above the ':' following the base package name, and the '|'
# on the right side marks the last column you can put a character in. You must
# make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':'.
kernel-jabberwok: kernel and modules for kernel-jabberwok
kernel-jabberwok: Jabberwokky type kernel!

They should both be copied to the install directory.

Making the Package
cd /tmp/kernel-package
/sbin/makepkg -l y -c n /tmp/kernel-jabberwok-

Change '_tag' to your usual moniker. Hopefully we now have a package in /tmp. Copy it to a temporary directory somewhere, explodepkg it and check the contents. We don't want to install something with messed up paths etc. If all is well we can installpkg it.

As usual, edit your /etc/lilo.conf and add an option for the new kernel, keeping the old kernel entry in place for safety, then run lilo.

A Little Automation

Of course this would be easier to control with a script rather than typing in these commands manually and trying not to make typos. Here is the script that I've been using (run make menuconfig first):



You should have a /usr/src/linux-$VERSION-$LOCALNAME on your target box or you may have problems later if compiling anything that needs that source.

Do not omit setting localname in .config.


The aim for doing this was to be able to build a kernel for my old T42 on my desktop box using the T42's .config. It could be possible to split up kernel and modules into separate packages (howto for that coming soon). Note that this does not include the firmware so you should keep the relevant kernel-firmware package installed.

At the end of the day, this helped me to compile a kernel without my laptop getting even warm, which was the point of the project.

NoteĀ³: If you are packaging kernel 3.0 you will need to change $VERSION to 3.0.0 (and source trees). This is because depmod will not work with 3.0, but there is an update to module-init-tools that fixes this, which IMHO is an arse-about-face way of fixing it. If the source was named 3.0.0 we would know where we stand right? Right ;)