"What do you give a man who has everything?" the pretty teenager asked her mother. "Encouragement, dear," she replied.
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
(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 126.96.36.199 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.
cp arch/x86/boot/bzImage /tmp/kernel-package/boot/vmlinuz-188.8.131.52-jabberwok
cp System.map /tmp/kernel-package/boot/System.map-184.108.40.206-jabberwok
cp .config /tmp/kernel-package/boot/config-220.127.116.11-jabberwok
And then the doinst.sh and slack-desc.
## Taken from stock modules package
if [ -x sbin/depmod ]; then
chroot . /sbin/depmod -a 18.104.22.168-jabberwok > /dev/null 2> /dev/null
(cd lib/modules/22.214.171.124-jabberwok ; rm -rf build)
(cd lib/modules/126.96.36.199-jabberwok ; ln -sf /usr/src/linux-188.8.131.52-jabberwok build)
(cd lib/modules/184.108.40.206-jabberwok ; rm -rf source)
(cd lib/modules/220.127.116.11-jabberwok ; ln -sf /usr/src/linux-18.104.22.168-jabberwok source)
# 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: kernel and modules for kernel-jabberwok 22.214.171.124
kernel-jabberwok: Jabberwokky type kernel!
They should both be copied to the install directory.
Making the Package
/sbin/makepkg -l y -c n /tmp/kernel-jabberwok-126.96.36.199-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):
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 ;)