Вы находитесь на странице: 1из 4

Linux Kernel Compilation

1/4

ZAGAZIG UNIVERSITY COMPUTER & SYSTEMS ENGINEERING DEPT.


FACULTY OF ENGINEERING THIRD YEAR LAB.

LINUX KERNEL COMPILATION


OBJECTIVES

 To acquaint the students with the principles of compiling the kernel of the Linux OS.
 To teach the student how to install new packages in Linux.

EQUIPMENT REQUIRED

1. A PC operated with Linux (Ubuntu 9.10).


2. Linux-source package.
3. Other packages required for kernel compilation (kernel-package, build-essential, fakeroot, gcc, libncurses5, and
libncurses5-dev or libqt3-mt-dev).

INTRODUCTION

Why would someone want to compile a new kernel? It is often not necessary since the default kernel shipped with
Ubuntu handles most configurations. Also, Ubuntu often offers several alternative kernels. So you may want to check
first if there is an alternative kernel image package that better corresponds to your hardware. However, it can be useful
to compile a new kernel in order to:

 Handle special hardware needs, or hardware conflicts with the pre-supplied kernels.
 You have hardware the stock Ubuntu kernel does not support.
 You are attempting to debug a problem in the stock Ubuntu kernel for which you have filed or will file a bug
report.
 Use options of the kernel which are not supported in the pre-supplied kernels (such as high memory support).
 Optimize the kernel by removing useless drivers to speed up boot time.
 Create a monolithic instead of a modularized kernel.
 Run an updated or development kernel.
 Learn more about Linux kernels.
 You are a kernel developer.

PROCEDURES

Before you begin executing the following procedures, you have to:

 Obtain a Linux Ubuntu 9.10 CD or ISO image. You can download the ISO image from
http://mirrors.us.kernel.org/ubuntu-releases/9.10/ubuntu-9.10-desktop-i386.iso.
 Install Linux either in a real PC or in a virtual one. You can use the VirtualBox program to create a virtual PC
inside your existing OS and then install Linux in it. A copy of VirtualBox can be obtained from
Objectives

http://download.virtualbox.org/virtualbox/3.1.6/VirtualBox-3.1.6-59338-Win.exe.
 Run the Linux Ubuntu OS and login to your account.

1
Linux Kernel Compilation
2/4

 Run a Terminal Emulator window by clicking Applications->Accessories->Terminal. Any further commands are
executed in this Terminal window.

PART 1: OBTAINING THE KERNEL SOURCE AND THE REQUIRED PACKAGES

In this part, you will know how to obtain the Linux kernel-source package (version 2.6.31 is used in this lab) and any
other package required during the compilation process. To complete this part, follow the following procedures:

1. Run the following command to obtain the Linux-source package:

sudo apt-get install linux-source

2. Run the following command to install the packages that are required to compile the kernel:

sudo apt-get install kernel-package build-essential fakeroot gcc


libncurses5 libncurses5-dev

3. If you want to configure the kernel using a GUI based configurator, run the following command:

sudo apt-get install libqt3-mt-dev

PART 2: CONFIGURING AND COMPILING THE KERNEL

In this part, you will learn how to configure and compile the Linux kernel. Note that the kernel version used in this lab is
2.6.31. Follow the following procedures to accomplish this part:

1. Go to the directory that contains your kernel-source

cd /usr/src

2. Extaract the kernel-source

sudo tar --bzip2 -xvf linux-source-2.6.31.tar.bz2

3. Create a link (shortcut) to the directory that contains the source files

sudo ln -s /usr/src/linux-source-2.6.31 /usr/src/linux

4. Change to the directory that contains the extracted kernel-source

cd /usr/src/linux

5. Configure the kernel with the old configuration, so as not to compile the entire kernel from scratch. If it makes
you any questions just press Enter

sudo make oldconfig

6. Start the kernel configurator. If you need a menu-based configuration type

sudo make menuconfig

Or if you need a GUI-based configuration type


Procedures

sudo make xconfig

7. Modify the configuration as following and save it

2
Linux Kernel Compilation
3/4

General setup:
Kernel compression mode -> LZMA
Optimize for size -> Y

Processor type and features:


Preemption Model -> Preemptible Kernel (Low-Latency Desktop)
High Memory Support -> 64GB
Timer frequency -> 1000 HZ
Kernel hacking:
Kernel debugging -> N

8. Clean the source tree and reset the kernel-package parameters

sudo make-kpkg clean

9. Compile the kernel to obtain kernel image and headers packages. The version number of “1.0” can be changed
at will; this is just a version number that you will use to track your kernel builds. Likewise, you can put any
word you like in place of “custom” (e.g., a host name). Kernel compilation may take quite a while, depending
on the power of your machine.

sudo fakeroot make-kpkg --initrd --revision=custom.1.0 kernel_image


kernel_headers

PART 3: INSTALLING AND TESTING THE NEW KERNEL

In this part, you will perform the final steps needed to have the new kernel ready to be used. At this, you will have
Debian packages for both the kernel-image and the kernel-headers. These packages can be installed just as any regular
package. The default location for these packages is /usr/src.

1. Change to the directory that contains the generated packages

cd /usr/src

2. Check the existence of the packages. By typing the following command you should see two files ends with
“.deb”

ls

3. Install the kernel-image package

sudo dpkg -i linux-image-2.6.31.9_custom.1.0_i386.deb

4. install the kernel-headers package

sudo dpkg -i linux-headers-2.6.31.9_custom.1.0_i386.deb

5. Reboot the system

sudo reboot

6. Before the system start booting, press the ESC key repeatedly to show a list of bootable kernels (The GRUB
boot loader). You should now see your kernel image listed. Select it and press ENTER key to boot into it. Note
that if you let the system boot without pressing the ESC key, the system will boot using the newly created
Procedures

kernel image.
7. After starting the new kernel, you can check its version using the command

uname –r

3
Linux Kernel Compilation
4/4

8. After finishing your work, shutdown the system.

REPORT

1. Write your comments about the experiment.

BIBLIOGRAPHY

1. [Online] https://help.ubuntu.com/6.10/ubuntu/installation-guide/i386/kernel-baking.html.

2. [Online] https://help.ubuntu.com/community/Kernel/Compile?highlight=%28%28Kernel%7CCompile%29%29.

3. [Online] http://ubuntuforums.org/showthread.php?t=56835.

Report

Вам также может понравиться