RANDOM FORTUNE:

"There are some micro-organisms that exhibit characteristics of both plants and animals. When exposed to light they undergo photosynthesis; and when the lights go out, they turn into animals. But then again, don't we all?"

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.

Building

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'.

make

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 2.6.29.6 kernel with jabberwok as local name. A little bash will copy our modules to it:

LIBSDIR=/tmp/kernel-package/lib/modules/2.6.29.6-jabberwok/kernel
for i in $(sed "s#^kernel/##" modules.order)
do
mkdir -p $LIBSDIR/$(dirname $i)
install -m 644 -v $i $LIBSDIR/$(dirname $i)
done

Now we need the kernel and associated files.

mkdir /tmp/kernel-package/boot
cp arch/x86/boot/bzImage /tmp/kernel-package/boot/vmlinuz-2.6.29.6-jabberwok
cp System.map /tmp/kernel-package/boot/System.map-2.6.29.6-jabberwok
cp .config /tmp/kernel-package/boot/config-2.6.29.6-jabberwok

And then the doinst.sh and slack-desc.

mkdir /tmp/kernel-package/install

doinst.sh:

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

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

slack-desc:

# HOW TO EDIT THIS FILE:
# 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|-----handy-ruler------------------------------------------------------|
kernel-jabberwok: kernel and modules for kernel-jabberwok 2.6.29.6
kernel-jabberwok:
kernel-jabberwok: Jabberwokky type kernel!
kernel-jabberwok:
kernel-jabberwok:
kernel-jabberwok:
kernel-jabberwok:
kernel-jabberwok:
kernel-jabberwok:
kernel-jabberwok:
kernel-jabberwok:

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-2.6.29.6-i686-1_tag.txz

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):

kernel-jabberwok.SlackBuild

Notes:

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.

Conclusion

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 ;)