Compiling your first kernel

These instructions will walk you through the process of getting the kernel source tree, compiling it, and testing out your kernel with VMware. For the sake of simplicity, we have shown how to do it using only command line programs.

Before you start

Compiling and testing the Linux kernel

  1. Log into your account on coredump or spinlock.
  2. Navigate to your project space on the machine.
    cd /cse451/username
  3. Copy the kernel source tree file from /cse451/projects/linux-451-02au.tar.gz to your home directory.
    cp /cse451/projects/linux-451-02au.tar.gz ./
  4. Decompress the kernel source tree.
    tar xfvz linux-451-02au.tar.gz
  5. Go get some fun reading material.
  6. Compile the kernel and generate a bzImage. This will take a long time. This is where the reading material comes in. When nobody else is using the machine, these commands might take 30 seconds and 4 minutes, 11 seconds, respectively.
    cd linux
    make depend
    make bzImage
  7. Open a Windows Command Prompt (aka DOS) session. To do this, do Start->Run and type "cmd".
  8. Transfer the bzImage from coredump/spinlock to the D drive on your local Windows machine. The D drive on your Windows machine will be accessible as /mnt/dos in the Linux you run on VMware.
    z:\pscp username@spinlock:/cse451/username/linux/arch/i386/boot/bzImage d:\bzimage
  9. Start up VMware. To do this, either click the VMware icon on the desktop, or do Start->All Programs->VMware->VMware Workstation.
  10. If you see "Linux" (not "Linux1", "Linux_2" or anything else) on listed in the list on the left, select it. If not, open it. To do this, do File->Open and browse to c:\Program Files\VMware\vms\linux\Linux\Linux.vmx .
  11. Click the "Power On" button in VMware. This will start up Linux on VMware. Note that this will be starting up the Linux kernel that we included in the VMware setup, not the kernel you just compiled. You have to install your kernel. If you see a message about the timing of the keyboard, just click Cancel.
  12. Login with username "root" and password "rootpassword". Note that we are able to post the root password for your Linux installation on the web because networking is disabled for these installations.
  13. Currently, your kernel is in this special directory that is shared with the Windows file system. You need to copy it into the standard directory where kernels are stored. This does not automatically make your kernel ready to run, but it makes the following steps work.
    mv /mnt/dos/bzimage /boot/bzImage-2.4.2-test
  14. The Linux boot loader is called lilo. At boot time, lilo selects an operating system image to run. You need to instruct lilo to select your image in order to test it. Use either vi or emacs to append the lines in this to the /etc/lilo.conf file. We recommend you use a text editor to do this, but if you really want a single command to do the job, the following will work. (printf works similarly to the C printf. For more information, see the printf man page.)
    printf "\n\nimage=/boot/bzImage-2.4.2-test\n\tlabel=test\n\tread-only\n\troot=/dev/hda1" >> /etc/lilo.conf
  15. Install your kernel. This will also tweak the boot sector of the disk to load into it.
    /sbin/lilo
  16. Finally, restart your virtual Linux machine using the following command. (Read the next step before you press enter.
    shutdown -r now
  17. When you see the prompt, "LILO boot:", type...
    test
    ... and press enter. You only have 5 seconds to do this. If you don't type anything or if you just press enter, then it will load the old, default kernel. Lilo allows you to have more than one kernel available on the same machine. This prompt is how you specify which one you want to load.

Making a trivial change to the kernel

Your task for this exercise, now that you are familiar with building a kernel and installing it, is to add some output to the boot sequence. Specifically, you should use the printk function to output a line of text after the kernel has initialized, immediately before the init user-level program is started. (Hint: search for /sbin/init, the file name of the init program.)

You will probably spend most of your time finding the code you need to modify. Cross-Referencing Linux and the Linux Kernel 2.4 Internals may be helpful. The command line tool grep(1) (and its -r flag) will also be handy.

Helpful hints

VMware messages you might see

Last updated 10/8/02 by Alex Quinn