James Joyce -- an essentially private man who wished his total indifference to public notice to be universally recognized.
          -- Tom Stoppard

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: This will create a single package for the kernel and modules. It is fine for custom kernels, but do not upgrade the stock kernels with this method. Use the stock SlackBuilds for that.

Note 3: This will build a 'huge' style kernel package, not a 'generic' one to use with an initrd. Hopefully you may find the info still relevant though.

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. We will not be using that option here. We will use $INSTALL_MOD_PATH to install the modules though.


See my other howto on kernel compiling to configure and build the kernel: kernel-compiling

Note: Do not use make install even with O switch, as this will install to /boot we don't want that.

Installing The Kernel and Modules to our Package Directory

This asssumes that you have already run 'make bzImage' or some other flavour of 'make'.

We'll use /tmp/kernel-package for our package directory, and assume a 4.18.5 kernel with jabberwok as local name.

We need the kernel and associated files.

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

To install the modules in our package directory we will use $INSTALL_MOD_PATH.

export INSTALL_MOD_PATH=/tmp/kernel-package
make modules_install

We need to create a couple of supporting files:

slack-desc is a file that prints a short description of the package when it is installed, and the information is copied to a file in /var/log/packages. This file is used by pkgtools when upgrading or removing packages.

You can put anything you like in slack-desc, but it's important to keep to the format. Don't go over 70 characters wide for the description, and keep the number of lines the same as the template below. The text preceding the colon should be the basename of the package. Keep all the comments and 'handy ruler' intact.

Usually a short description is put on the first line, then one blank line, followed by a brief description and homepage if appropriate.

doinst.sh is run at the end of the package install to perform post-install tasks, in this case the 'depmod' command that builds the list of module dependencies.

For a better look at the way package files are made you can look in the various directories of the Slackware source tree or look at the templates directory at slackbuilds.org.



# 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 4.18.5
kernel-jabberwok: Jabberwokky type kernel!


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

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

Create the install directory and cat the files there:

mkdir /tmp/kernel-package/install
cat doint.sh > /tmp/kernel-package/install/doinst.sh
cat slack-desc > /tmp/kernel-package/install/slack-desc

Making the Package

Change '_tag' to your usual moniker or initials. The '1' here is the build number. Update is as necessary when you rebuild the package.

cd /tmp/kernel-package
/sbin/makepkg -l y -c n /tmp/kernel-jabberwok-4.18.5-i686-1_tag.tgz

Hopefully we now have a package in /tmp. It's possible to check the contents with tar:

tar tfv /tmp/kernel-jabberwok-4.18.5-i686-1_tag.tgz | less

Install the package using installpkg, or upgradepkg to upgrade your old kernel.

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

A Little Automation

Of course this would be easier to control with a script rather than typing in these commands manually. Here is the SlackBuild that I've been using:


Important Notes:

* You should have a /usr/src/linux-4.18.5-jabberwok on your target box or you may have problems later if compiling anything that needs the source or headers.

* Do not omit setting localname in .config because the SlackBuild uses it.