Kernel Compile and SysCall Add (Ubuntu 8.04)
Kernel Compile and SysCall Add (Ubuntu 8.04)
NOTE: Accessing some parts of the system, installing system wide programs, such as a kernel, requires
root privileges. Do not forget to add sudo to the beginning of most commands mentioned in the
instructions below, which will grant you root priviledges during the execution of the next command.
aptitude update
cd /usr/src
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.20.15.tar.bz2
cd /usr/src/linux
4) Configure the kernel by copying configuration file from the host system
cp /boot/config-2.6.24-19-generic ./.config
make menuconfig
- .config shall appear, as the name of the configuration file you wish to load, in the dialog
box that appears next. Press <Ok>.
- (Optional) Make your configuration choices browsing through the configuration options.
- When you are finished, select Exit and answer the question “Do you wish to save
your new kernel configuration ?” with Yes.
Note: If you are planning to add a new system call to the kernel, you will need to compile the kernel
again. To avoid compiling the kernel two times, see section II for additional steps and start the
compilation after performing those steps.
make-kpkg clean
After –-append-to-version= you can write any string that helps you identify the kernel, but it
must begin with a minus (-) and must not contain whitespace.
After having entered the last command, the kernel compilation starts. Depending on your kernel
configuration and your processor speed, kernel compilation may take some hours.
cd /usr/src
ls –l
dpkg –i linux-image-2.6.20.15-custom_2.6.20.15-custom-10.00.Custom_i386.deb
dpkg –i linux-headers-2.6.20.15-custom_2.6.20.15-custom-10.00.Custom_i386.deb
After having built the kernel successfully, you shall find two .deb packages in the /usr/src
directory The .deb package linux-image-2.6.20.15-custom_2.6.20.15-
custom-10.00.Custom _i386.deb contains the actual kernel and the .deb package linux-
headers-2.6.20.15-custom_2.6.20.15-custom-10.00.Custom_i386.deb contains
files needed if you want to compile additional kernel modules later on.
NOTE: Even after installation of the .deb packages under /usr/src .deb packages linux-
image-2.6.20.15-custom_2.6.20.15-custom-10.00.Custom _i386.deb and
linux-headers-2.6.20.15-custom_2.6.20.15-custom-10.00.Custom _i386.deb
shall remain. Thus, you can now even transfer the two .deb files to other Ubuntu systems and install
them there exactly the same way, which means you do not have to compile the kernel there again.
7) Check /boot/grub/menu.lst to find the new two stanzas for your new kernel:
sudo reboot
uname -r
It should display:
2.6.20.15-custom
II. How to Add a System Call
(for 2.6.x Kernels and i386 Type Architecture Machines)
Assume we’d like add a system call calles “mycall” that takes two integers as input and return their sum.
1) Add “.long sys_mycall” at the end of the list in the file syscall_table.S.
NOTE: You can use the command sudo gedit syscall_table.S to edit the file
syscall_table.S. Beware that if you do not have the root privileges, system will not allow you to edit
any of the kernel files.
2) In file unistd.h
- Increment NR_syscalls by one (e.g. If before adding your system call total number of
system calls is 320, then this will be #define NR_syscalls 321.).
/*----------Start of mycall.c----------*/
#include <linux/linkage.h>
return(i+j);
/*-----------End of mycall.c-----------*/
obj-y := mycall.o
8) Create the following userspace program to test your system call and name it testmycall.c. The
contents of this file shall be:
#include <unistd.h>
#include <stdio.h>
};
int main() {
return 0;
REFERENCES:
[2] Amit Choudhary, “Implementing a System Call on Linux 2.6 for i386”,
http://tldp.org/HOWTO/html_single/Implement-Sys-Call-Linux-2.6-i386/
*** Internet is the ultimate resource for the solution of the problems you come across to during system
call implementation and kernel compile procedures.