Jump to Navigation

Separate Kernel Trees mini-HOWTO v1.1

Separate Kernel Trees
Frodo Looijaard, frodol@dds.nl
v1.1, 12 July 1998

1. Introduction

This document describes a setup which allows the installation and use
of several distinct kernel trees, even when they have the same release

When you are working on some kernel-related development, trying out
a new compiler version or installing pre-versions, this document might
be useful to you.

Note that some distributions may already have something comparable
to the setup described below. If the directory trees in /lib/modules
are named 2.0.34 for kernel versions 2.0.34, this is probably not the
case. If they are named 2.0.34-something, you will probably not need
this document.

Note that I have only tested this for 2.0.x kernels. I would appreciate
to hear whether it works out for 2.1.x kernels too.

2. Setup

To allow the use of several kernels with the same release number, we
will refer to kernel versions as a concatenation of release number and
compilation number, separated by a dash.

  Kernel version 2.0.32, third compilation, would be called 2.0.32-3

During execution of /etc/rc (at system start-up), several steps must be
taken to ensure this will work (VERSION is a version number as explained 
  * /usr/src/linux must be linked to /usr/src/VERSION
  * /lib/modules/current must be linked to /lib/modules/VERSION

You can determine VERSION with the following code snippet:

---Cut Here---
kernel_version ()
  local IFS_safe="$IFS"
  set -- `uname -v`
  echo `uname -r`-$2
---Cut Here---

Using this function, you can add something like this to your rc-files
(this code is a bit paranoid, but better be safe than sorry):

---Cut Here---
echo "Selecting the current modules..."
if [ -d "/lib/modules/$VERSION" ] ; then
  if [ -L /lib/modules/current ] ; then
    rm -f /lib/modules/current
  if [ ! -e /lib/modules/current ] ; then
    ln -s "$VERSION" /lib/modules/current
    echo "ERROR: /lib/modules/current exists and is not a symbolic link."
    echo "       Module loading may produce unexpected results, perhaps even"
    echo "       resulting in data loss. We will not load kerneld. Expect"
    echo "       many errors below."
  echo "ERROR: /lib/modules/$VERSION not found."
  echo "       Kerneld can not be started, modules will not be loaded"
  echo "       automatically. Expect many errors below."
---Cut Here---

---Cut Here---
echo "Selecting the current kernel..."
if [ -d /usr/src/linux-"$VERSION" ] ; then
  if [ -L /usr/src/linux ] ; then
    rm -f /usr/src/linux
  if [ ! -e /usr/src/linux ] ; then
    ln -s linux-"$VERSION" /usr/src/linux
    echo "WARNING: /usr/src/linux may be linked to another kernel than the one"
    echo "         we booted from. This may give some slight surprises, but"
    echo "         should be no real problem."
  echo "WARNING: /usr/src/linux-$VERSION not found. /usr/src/linux might not"
  echo "         be linked to the current kernel. This may give some slight"
  echo "         surprises, but should be no real problem."
---Cut Here---

Moreover, the file /etc/conf.modules must be present and contain at least the 
following information (sometimes this file is called modules.conf):

---Cut Here---
# Where to find the dependency file

# These are the paths to the kernel version-specific modules

# These are the paths to additional modules which are kernel independent

# These are the paths to modules which are inserted at boot-time for all
# kernel versions. Note that by making symbolic links to ../current/...
# you can still load different modules for different kernels.

# These are the paths to modules which are inserted at boot-time for
# specific kernels
---Cut Here---

To ensure this scheme works, you have to be careful when compiling a
new kernel:
  * Make sure the combination of release and compilation numbers is
    unique. You can set the compilation number by entering the number
    _minus one_ in <Kernel-base>/.version (delete this file to use
    number 1).
  * Put each kernel tree in the directory /usr/src/VERSION. Be careful
    when you unpack a new kernel tree from a tarball, as it unpacks
    into the directory linux, and may overwrite an old kernel tree!
    This generally works for me:

---Cut Here---
# Make sure nobody is compiling anything!
cd /usr/src
rm linux
tar zxfv /tmp/linux-2.0.34.tar.gz
mv linux linux-2.0.34-1
ln -s linux-2.0.34-1 linux
echo 0 > linux/.version
# Always echo one less than the compile number to .version!
---Cut Here---
    Or, if the tree is already available:

---Cut Here---
cd /usr/src
cp -a linux-2.0.34-1 linux-2.0.34-2
ln -sn linux-2.0.34-2 linux
cd linux
make mrproper
# .version should contain the right number after the last compile; better
# make sure!
echo 1 > .version
---Cut Here---
  * After calling module_install, rename /lib/modules/RELEASE to
    /lib/modules/VERSION (where RELEASE is the kernel release number),
    or use the small patch below:

---Cut Here---
*** /tmp/linux/Makefile Wed Feb  4 19:41:45 1998
--- linux/Makefile      Wed Feb  4 20:04:45 1998
*** 275,279 ****
        @( \
!       MODLIB=/lib/modules/$(VERSION).$(PATCHLEVEL).$(SUBLEVEL); \
        cd modules; \
        MODULES=""; \
--- 275,279 ----
        @( \
!       MODLIB=/lib/modules/$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)-`cat .version`; \
        cd modules; \
        MODULES=""; \
---Cut Here---

3. Copyright and disclaimer

This document is copyright (c) 1998 by Frodo Looijaard (frodol@dds.nl).
You may freely copy and distribute it, as long as you recognize me as the 
author, and mark any changes you make as being your own, and distribute this 
notice with it.

This document is distributed in the hope it is useful, but without any 
warranty. If following the guidelines herein blows up your system, I will 
not be held responsible.

Historic_content | by Dr. Radut