(Dr.R.K.) HOWTO - Compiling the Linux Kernel


Go to Bottom blank blank Go up one level To frames R.K.'s Home Page Keyword Index Site Map Help Linux
Linux is one of the fastest growing operating systems now with millions of followers around world. Some of it's many features are:
  1. It's fully POSIX compliant at the system call level
  2. It looks and acts exactly like UN*X without the pesky USL or UNIVELL or whomever-owns-the-UNIX license fees that add hundreds or thousands of dollars to an otherwise open operating system
  3. Sources are freely available (in fact it's demanded by the GNU copyright which is generally accepted for most of the software pieces and for the kernel)
  4. Hundreds of people are upgrading and bug-fixing the code
  5. Several newsgroups cover various aspects of Linux
  6. Supports X11 windows
  7. What I like about it ... it's all FREE!
Its sources are freely available and bootable distributions can be purchased on CD-ROM's or downloaded from many sites. I got my initial distribution ( slackware at sunsite or the slackware home) from sunsite.unc.edu.
Requires a 386 machine or better with standard non-proprietary bus (almost anything except IBM MCA). (There are also versions for the DEC alpha and the Sun sparc.)

The following is a check-list that I use to install a new kernel version. This information can be gleaned from the Makefile, Configure script, several Linux HOWTO's, trial-&-error. In other words, I had to hunt around alot to compile my first kernel (back with version 1.1.45). I keep a journal of what I do when I modify my computer configuration and have standardize on this simple procedure. In the following xx.xx.xx refers to the version & patch level of the kernel to be installed (e.g. 1.3.71). The commands will be in this style

  1. Print out the old kernel configuration file for future reference
    lpr /usr/src/linux/.config (or whatever command you use to print out files)
  2. Remove old /usr/src/linux symbolic link
    rm /usr/src/linux
  3. Make a new directory for the new sources
    mkdir /usr/src/linux-xx.xx.xx
  4. Make a symbolic link from this new directory to /usr/src/linux
    ln -s /usr/src/linux-xx.xx.xx /usr/src/linux
  5. Untar the sources (I assume the gzipped tar file is in /tmp
    cd /usr/src
    tar -xzf /tmp/linux-xx.xx.xx.tar.gz
  6. Install any kernel patches that may be desired. I have a special directory (/usr/src/kpatches) where I run it all from a single script (KERNEL.PATCH).
    cd /usr/src/kpatches
    KERNEL.PATCH
  7. In the new kernel source directory run the `Makefile'
    1. make mrproper (optional if starting from scratch with this distribution)
    2. make config (refer to the .config file from the older version).
      Can specify menuconfig or xconfig instead for a menu driven configuration.
    3. make dep (establishes the dependencies between header files and sources)
    4. make zImage (this creates the actual kernel image, this will take some time)
    5. make modules (creates the loadable modules)
    6. make modules_install (places the loadable modules at /lib/modules/xx.xx.xx)
  8. Remove the old /vmlinuz, which should be a hard link to something else. (You don't want to entirely remove your old kernel image ... if for some reason the new one doesn't run at all, you're not stranded without a bootable Linux system.)
    rm /vmlinuz
  9. Copy the new kernel into place
    cp /usr/src/linux/arch/i386/boot/zImage /vmlinuz
  10. Make a hard link to something else for safe keeping of the kernel image
    ln /vmlinuz /vmlinuz.xx.xx.xx
  11. Make the kernel permissions restrictive to non-root
    chmod 700 /vmlinuz /vmlinuz.xx.xx.xx
  12. Have the kernel set the boot filesystem to read-only when starting up
    rdev -R /vmlinuz 1
  13. Make a bootable floppy
    dd if=/vmlinuz of=/dev/fd0 (copies kernel image to the 1st floppy device)
    rdev /dev/fd0 /dev/hda2 (tells boot floppy kernel which file system is the root (/) file system. You need to set this for your own configuration).
  14. Be sure the source directories are readable since a lot of software depends on access to the Linux kernel header files
    cd /usr/src
    chmod -R a+rX linux
  15. Configure lilo to see the new kernel (and keep access to the old one ... just in case). I've got the lilo configuration file under revision control so that I can ``back-out'' any of my screw ups.
    cd /etc
    co -l lilo.conf
    (edit lilo.conf to point to the new kernel image and to the old. See the lilo documentation for further details)
    co -l lilo.conf
    lilo
    ci lilo.conf
You should now have a bootable Linux system from the new kernel. Congratulations!

Last Modified:
Go to Top blank blank Go up one level To frames R.K.'s Home Page Keyword Index Site Map Help Linux
Brought to you by: R.K. Owen,Ph.D.
This page is http://owen.sj.ca.us/rkowen/howto/linux.kernel.html