Fall 2011 CS380L 

Download and build the Linux kernel

Download

You can download a tarball from www.kernel.org. It is nicer to clone a git repository with the kernel in it if you know how (this makes it easy to track changes you may want to make to the kernel later).

Extract the source into <kernel dir>. (I am assuming that <kernel dir> is an absolute path, that is, one that starts with "/".)

Build

Setup build directory

It is much easier to manipulate the kernel if you have a separate source directory than build directory. Create a build directory outside the source tree called <kbuild>.

Generate configuration file

In <kbuild>, run

yes "" | make -C <kernel dir> O=`pwd` config

This makes a configuration file with the default option selected.

Build the kernel

In <kbuild>, run

make

(consider use of "-j" switch with make if you have more processors on the machine)

Prepare modules for installation

We will do this a somewhat crufty way - we will tar up our modules and copy them into our image. Here's how:
Install modules locally
This puts them in the correct directory structure. In <kbuild> execute:

make INSTALL_MOD_PATH=<install_mod_dir> modules_install

For <install_mod_dir> a directory of your choice. This will collect all your built kernel modules into one place.

Tar up your modules
cd <install_mod_dir>

You should see one directory: "lib"

tar czf modules.tar.gz lib

This could take a while (perhaps order of a few minutes), you're zipping up a lot of modules.

Run

Now we'll need a different set of options to QEMU - remove the CD-related options, and add options for booting the new kernel:

-kernel /arch/x86/boot/bzImage

also probably helpful is

-append console=ttyS0,115200n8

which adds a serial console at boot so you can view boot messages.

One final potentially helpful option is to preface your image name with "--snapshot". This ensures that no changes are made to your image during an execution (so you can do something dangerous and have the original image file preserved). You may want to investigate qemu-img and qcow2 format images for how you can "do something potentially dangerous, and preserve changes if it goes right", because "--snapshot" will ALWAYS revert your changes.

Copy modules into your image

But you want to be able to use modules, right? Let's use your old kernel (which has the ability to use a network card) to copy modules over to your image. Boot without the "-kernel" and "-append" options.

Now we'll copy your modules over:

scp <username>@<cs host>:<path to modules tarfile> .

Sorry, line wrapping on a terminal is ugly. You also won't see any boot info now because we're lacking the "-append" option.

This could also take a little while (but you'll have an ETA).

Extract modules

sudo tar xzf -C /

This will put the modules in /lib/modules/<kernel version> . This could also take a little while.

You do know what sudo does, right? (If not, look it up with man.)

Reboot

Halt the system (with halt). Now when you boot your kernel with the -kernel and -append options, you can load modules for that kernel. This will let you do things like load a network card (it should automatically happen when you boot).

Use modules

Load modules with modprobe. Cause modules to load automatically at boot by putting them in /etc/modules.

Additional issues

You might find the lspci and lsmod commands useful.

You might need a root= parameter to qemu.