Syscall Project

You are to create a modifed Linux kernel which has a new system call, the helloworld call. This call takes no arguments and returns normal status. It writes the string "hello world" into the kernel system log.

To complete this project, you will need to:

Installing Linux

There are many places that describe how to install linux. I suggest the Fedora distro, which we use in the lab. Go to the Fedora web site, to downloads, and get the ISO image of disk 1 for Fedora Core 4 (FC4-i386-disk1.iso). Burn this to a CDROM.

This has been already done and burned to a CDROM. It is in the lab beside the computer usable for this class.

Boot to the CDROM. You might have to enter the BIOS to control Boot Order. Once booted on the CDROM, take all defaults, except choose a custom kernel, and later, minimal install. This choice of install requires only the one CDROM.

Choose a root password. Do not leave a machine on the net without a password for root.

Building a Kernel

You will need a compiler:

yum install gcc.i386
will get you one from the net, and install it.

You will need kernel sources. Use wget to this URL:

http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.13.tar.gz{bz2}
Use gunzip or bunzip2 to decompress. Move the tarball to /usr/src and extract.

Read on the net how to build a linux kernel. In short:

make config
make dep
make clean
make bzImage
make modules
make modules_install
make install
The result will be:
  1. A configuration file for building the kernel, a file such as config-2.6.11-1.1369_FC4.
  2. A kernel, such as /boot/vmlinuz-2.6.11-1.1369_FC4.
  3. A temporary root directory for booting, such as /boot/initrd-2.6.11-1.1369_FC4.img.
  4. A set of modules, populating the tree under /lib/modules/2.6.11-1.1369_FC4.
  5. A modification of the grub boot configuation file, /boot/grub/grub.conf, so that you can choose to boot this kernel from the grub menu.

A Word About Booting

The BIOS identifies all attached disks and numbers them as hd0, hd1, and so forth. Each disk is an array of sectors. Sector zero of each disk is called the Boot Sector, of the MBR, Master Boot Record. A disk is partitioned, is if acts as several disks, one for each partition. The partitioning information is stored on the Boot Sector, at the end of the Boot Sector. This is called the partition table, and you are advised not the damage it.

To see the boot sector of a disk of a live Linux system, be root, identify the device, such as /dev/hda, for the first IDE disk, and type:

dd if=/dev/hda count=1 | hexdump -C
You will note the words GRUB mixed into the bytes of the sector, if this is an MBR containing the GRUB boot loader. The last 4 lines of the listing is the partition table, and you can try to learn to read it right from the dump. The last two bytes are hex 0x55, 0xaa. This is the signature of an MBR, or at least of a partition table.

A boot sector contains a partition table and it may contain code to read an operating system off of a disk. This code is called the boot loader. Since a sector is small, this code is just enough of the boot loader to read the rest of the boot loader. So the path is: the BIOS reads the MBR, the MBR code reads a boot loader and runs it, the boot loader reads the operating system (the kernel) and runs it.

We use the GRUB boot loader. It wants itself, its configuration files, and the kernels it can load, to live on its own little partition which will be mounted as /boot (by convention) once the system is running. On clean, default Linux installs, this partition is usually the first, located in the lowest block numbers of the disk.

Hacking the Kernel

Modify /usr/src/linux*/Makefile so that EXTRAVERSION reflects that this is hacked kernel. Else you will be sorry. Modify arch/i386/kernel/entry.S or some such file to subsitute sys_helloworld for some "ni" entry. Find an appropriate file and add the function sys_helloworld following the pattern of the othere syscall bodies. Recompile the kernel, and so on.

Booting to the hacked kernel, in the root home directory, write a program to test the new system call.