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
- This assumes you have an account on coredump and/or spinlock.
- Download a copy of PSCP. PCSP is part of the same project that
produces PuTTY, a popular SSH client which allows you to work in
color, full-screen mode. You might want to download both, while you're
there.
- These instructions assume you have the PSCP program, pscp.exe, located
right in your Z drive, accessible as z:\pscp.exe. If you want to know
how pscp works in general, take a look at its
documentation.
- These instructions assume you are working in Sieg 232 or Sieg 329 on one of the new
Dell Optiplex machines with the Pentium 4 processors and the low
profile cases. These are the only machines
that have VMware.
- If VMware gives you any messages you don't understand, take a look at
the section on VMware messages at the bottom of this page.
- Commands in
blue type
are to be entered from
coredump or spinlock. For more information about UNIX commands, you
might take a look at the
ACM
tutorials or the
Geek Girl UNIX
Reference Desk.
- Commands in
maroon type
are to be entered
from the command line in Windows. For more information on Windows
command line commands, you might take a look at
this
guide.
- Commands in
dark green type
are to be entered
from your Linux prompt within VMware. For more information about VMware,
take a look the VMware help files or the
VMware web site.
Compiling and testing the Linux kernel
- Log into your account on coredump or spinlock.
- Navigate to your project space on the machine.
cd /cse451/username
- 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 ./
- Decompress the kernel source tree.
tar xfvz linux-451-02au.tar.gz
- Go get some
fun
reading material.
- 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
- Open a Windows Command Prompt (aka DOS) session. To do this, do
Start->Run and type "
cmd
".
- 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
- Start up VMware. To do this, either click the VMware icon on the
desktop, or do Start->All Programs->VMware->VMware Workstation.
- 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
.
- 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.
- 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.
- 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
- 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
- Install your kernel. This will also tweak the boot sector of the
disk to load into it.
/sbin/lilo
- Finally, restart your virtual Linux machine using the following
command. (Read the next step before you press enter.
shutdown -r now
- 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
- Adding new files to the kernel source tree: If you need
to add a new file to the Linux source tree, do it in the following
manner:
- Determine which existing directory the file(s) will live in
- Edit the Makefile in that directory, and add the name(s) of
the .or file(s) that will be created to the definition of O_OBJS.
- To build the kernel, you must be in the top-level source
directory (the one containing the file named REPORTING-BUGS).
VMware messages you might see
- If you see something about a keyboard hook timer, click OK.
- If you see, "You do not have write access to 'Partition 1' of host....," click Allow All.
- If you see, "Host-only support does not seem to be installed," you
are probably not using the right VMware configuration file. A few
machines
may have an old configuration hanging around. The configuration you
want will be called "Linux" — NOT "Linux1",
"Linux_2" or anything else.
- If you see, "Do not forget to install the VMware Tools package inside this virtual machine...," just click OK to dismiss the message. You do not need
the VMware tools package.
Last updated 10/8/02 by Alex Quinn