kernel build exercise
The source code for the linux operating system comes from www.kernel.org in a the form of a single consolidated, compressed archive file. For example, linux-2.6.14.tar.bz2. Get a copy of that file from www.kernel.org, or perhaps a later version or nearer source per your instructor:
cd
ftp <address of ftp server per instructor>
[supply user name "anonymous" and no password when prompted]
ftp> cd pub
ftp> get linux-2.6.14.tar.bz2
ftp> quit
Change the working directory to /usr/src then untar the archive:
cd /usr/src
tar -xjvf ~/linux-2.6.14.tar.bz2
The result is to create a subtree /usr/src/linux-2.6.14/ full of many files. These are ingredients for building the 2.6.14 kernel. Change into the new directory:
cd linux-2.6.14
and browse through the README file there (originally written, till recently maintained, by Linus Torvalds). Express and record your particular desires for building this kernel and what features it should include. If you do not have a GUI:
make menuconfig
If you have a GUI ( startx & generally launches it) then better:
make xconfig
Within the xconfig program you can select or deselect many (hundreds of) components. Let's choose a few features different from default. Then, after creating and booting our new kernel, exercising those features will convince us that it worked.
Find and select these features:
General setup / Kernel .config support, and Enable access to .config
through /proc/config.gz
File systems/ DOS/FAT/NT filesystems / NTFS file system support
processor type / preemptible kernel
Find and disable:
Code maturity level options / Prompt for development and/or incomplete code/drivers
From within the xconfig application save then exit. Your selections are recorded in a file named .config. Examine its contents. The kernel build process uses that file and implements its selections. Under the new kernel, you will have support for the ntfs file system. You'll prove that by mounting and accessing the existing ntfs partition on your hard disk. Under the current version of your operating system, ntfs is not included so you can't mount that partition. Prove now that you can't by trying:
mount -t ntfs /dev/hda1 /mnt
You should get an error message to the effect that the system doesn't know about ntfs. If you can overcome this after the recompile/reboot, it'll constitute proof that you've replaced one kernel with another.
The instructions for the kernel build process are in the delivered file Makefile. There, make one editorial change. Very near the top, find the line:
EXTRAVERSION =
and give it value -1 (hyphen one):
EXTRAVERSION =-1
The Makefile gets involved automatically when you run the make command, as you did in order to get the xconfig application and will do again now for several further purposes. Execute these commands in succession:
make clean
make bzImage [ took 45 min on a slow machine ]
make modules [ took 2.5 hr ]
make modules_install
"make clean" deletes leftover files from any previous builds to give a fresh starting point for this one. Then make bzImage creates the central piece of the operating system in a single large file, and make modules creates the outboard, dynamically-loadable-module pieces of the operating system in numerous smaller ones. Then make modules_install copies the modules to the place where they need to be at runtime. Copying the main file to its runtime spot on the other hand is a manual task. Do it as follows:
cp /usr/src/linux-2.6.14/arch/i386/boot/bzImage /boot/vmlinuz-2.6.14-1
Two other files need to be co-located with the main kernel file. You make one in place, and copy the other which has been made already:
mkinitrd /boot/initrd-2.6.14-1.img 2.6.14-1
cp System.map /boot/System.map-2.6.14-1
All the pieces of the new operating system are ready to go. All you have to do is call them on the next reboot. That's the job of your bootloader. So now you have to adjust the bootloader to know about the new kernel and invoke it. For the GRUB bootloader, see its configuration file /boot/grub/grub.conf. Add to it a stanza like (you'll see a similar one already in place):
title New-compiled 2.6.14
root (hd0,1)
kernel /boot/vmlinuz-2.6.14-1 ro root=LABEL=/ rhgb quiet
initrd /boot/initrd-2.6.14-1.imgNow reboot the machine:
reboot
An additional option should appear on the bootloader menu under your chosen name "New-compiled 2.6.14," offering the new kernel. Select it and let the system boot up fully. It will probably declare its name on screen along the way, otherwise try:
uname -r
to see it assert the claim that it's new. To really verify it though, use one of the previously absent features you instructed to be built in. Try to access a local NTFS partition. Assuming you have one holding a copy of Windows in /dev/hda1:
mount -t ntfs /dev/hda1 /mnt
ls /mnt
umount /dev/hda1
The above ls command should reveal signature Widows root directory files (e.g., boot.ini, pagefile.sys, ntldr). Congratulations. Enjoy your new kernel.
Here is the README that comes with the
kernel source.
Here is a
howto guide about building the kernel.
Another howto by Rick
Stevens. Rick gives copious and detailed support on RedHat mail lists (https://www.redhat.com/mailman/listinfo/)