cis 191 - lesson 13 linux kernel. architecture dependent kernel code kernel space process management...
TRANSCRIPT
CIS 191 - Lesson 13
LinuxKernel
Architecture DependentKernel Code
KernelSpace
ProcessManagement
MemoryManagement
Network Stack
Virtual File System
UserSpace
Device Drivers
Kernel1
Hardware
System Call Interface
Users
Commands & Utilities
Shell
X / Desktops
(multi-user)
GNU C Library (glibc)
Programs (multi-tasking)
Add-ons
1See “Anatomy of the Linux kernel” by M. Tim Jones at http://www-128.ibm.com/developerworks/linux/library/l-linux-kernel/
GNU/Linux Operating System Architecture
Richard Stallman started the GNU project in 1983 to create a free UNIX-like OS. He Founded the Free Software Foundation in 1985. In 1989 he wrote the first version of the GNU General Public License
Linus Torvalds, as a student, initially conceived and assembled the Linux kernel in 1991. The kernel was later re-licensed under the GNU General Public License in 1992.
CIS 191 - Lesson 13
The Linux Kernel (in /boot)Major Subsystems:
• System Call Interface • mechanism for user space programs to request kernel services.
• Process Management • handles fork, exec, exit, kill, signals, CPU scheduling, etc.
• Memory Management • allocation, usage tracking, paging, etc.
• Virtual File System• open, close, read, write, caching, etc.
• Architecture Dependent Kernel Code• Drivers (in /lib)
Design• Linux kernel is “monolithic”, not a “microkernel”• Dynamic – can load and unload modules on the fly• Overtime has become efficient, stable and portable
CIS 191 – Lesson 13
CIS 191 - Lesson 13
The Linux KernelBuilding a New Kernel
Obtain and verify kernel source tarball Extract source code Install development tools Configure the kernel options
make config or make menuconfig or make xconfig or make gconfig or make oldconfig
make clean make bzImage make modules make modules_install make install
Steps for building a new kernel
CIS 191 - Lesson 13
The Linux KernelBuilding a New Kernel
Obtain and verify kernel source tarball Extract source code Install development tools Configure the kernel options
make config or make menuconfig or make xconfig or make gconfig or make oldconfig
make clean make bzImage make modules make modules_install make install must be done as
root user
CIS 191 - Lesson 13
The Linux KernelBuilding a New Kernel
Obtain and verify kernel source tarball Extract source code Install development tools Configure the kernel options
make config or make menuconfig or make xconfig or make gconfig or make oldconfig
make clean make bzImage make modules make modules_install make install
cleans up object files created from previous compiles
CIS 191 - Lesson 13
The Linux KernelBuilding a New Kernel
Obtain and verify kernel source tarball Extract source code Install development tools Configure the kernel options
make config or make menuconfig or make xconfig or make gconfig or make oldconfig
make clean make bzImage make modules make modules_install make install
Compile the kernel
CIS 191 - Lesson 13
The Linux KernelKernel Background
Obtain and kernel source code
‒ http://www.kernel.org
‒ Download either: *.tar.bz2 or *.tar.gz files
bzip2 or gzip tarballs
CIS 191 - Lesson 13
The Linux KernelBuilding a New Kernel
Obtain and verify kernel source tarball Extract source code Install development tools Configure the kernel options
make config or make menuconfig or make xconfig or make gconfig or make oldconfig
make clean make bzImage make modules make modules_install make install
Compile the loadable kernel modules
CIS 191 - Lesson 13
The Linux KernelBuilding a New Kernel
Obtain and verify kernel source tarball Extract source code Install development tools Configure the kernel options
make config or make menuconfig or make xconfig or make gconfig or make oldconfig
make clean make bzImage make modules make modules_install make install
Install the loadable kernel modules in /lib
CIS 191 - Lesson 13
The Linux KernelBuilding a New Kernel
Obtain and verify kernel source tarball Extract source code Install development tools Configure the kernel options
make config or make menuconfig or make xconfig or make gconfig or make oldconfig
make clean make bzImage make modules make modules_install make install Copy files to /boot
CIS 191 - Lesson 13
http://kernel.org/
Click here
CIS 191 - Lesson 13
http://www.kernel.org/pub/
Click here
CIS 191 - Lesson 13
http://www.kernel.org/pub/linux/
Click here
CIS 191 - Lesson 13
http://www.kernel.org/pub/linux/kernel/
Click here
CIS 191 - Lesson 13
Change logs show fixed bugs and any enhancements
http://www.kernel.org/pub/linux/kernel/v2.6/
CIS 191 - Lesson 13
Completekernels
http://www.kernel.org/pub/linux/kernel/v2.6/
CIS 191 - Lesson 13
http://www.kernel.org/pub/linux/kernel/v2.6/
Patches
CIS 191 - Lesson 13
http://kernel.org/
The latest (as of the date making this slide)
http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.27.8
CIS 191 - Lesson 13
http://kernel.org/
Create a tarballs directory in /depot
Obtain kernel tarballs and place in this directory
CIS 191 - Lesson 13
http://kernel.org/
Many ways to get the tarballs• wget command• Run level 5, run firefox, and download• Download on another system and use Filezilla to
transfer to Benji VM
CIS 191 - Lesson 13
http://kernel.org/
Using wget to get files from kernel.org
CIS 191 - Lesson 13
Getting kernel files to VM
Download files to windows and transfer to VM with FileZilla
CIS 191 - Lesson 13
http://kernel.org/
[root@benji tarballs]# ls -ltotal 49408-rw-r--r-- 1 root root 50384960 Dec 6 13:59 linux-2.6.27.8.tar.bz2-rw-r--r-- 1 root root 248 Dec 6 13:58 linux-2.6.27.8.tar.bz2.sign-rw-r--r-- 1 root root 125174 Dec 5 14:16 patch-2.6.27.8.bz2[root@benji tarballs]#
Latest kernel source, patch and signature file
CIS 191 - Lesson 13
http://kernel.org/
Verify the downloaded source code• Obtain the public key from
http://www.kernel.org/signature.html• And copy it into a new file kernel.pubkey• Import the key
gpg --import kernel.pubkey• View the new key
gpg --list-keys• Verify
gpg --verify linux-2.6.27.8.tar.bz2.sign linux-2.6.27.8.tar.bz2
Linux Kernel Archive files are signed using OpenPGP. This signature can be used to prove downloaded files originated at the Linux Kernel Archives.
CIS 191 - Lesson 13
http://kernel.org/
Lets check we didn't get malicious code
CIS 191 - Lesson 13
http://kernel.org/
Public and private keys are used to verify source code is authentic
CIS 191 - Lesson 13
http://kernel.org/
Copy the public key to the clipboard
CIS 191 - Lesson 13
http://kernel.org/
[root@benji tarballs]# vi kernel.pubkey
Edit a new file to place the public key
CIS 191 - Lesson 13
http://kernel.org/
Go to Insert mode and paste the key with a right click
CIS 191 - Lesson 13
http://kernel.org/
Scroll back to the top and make sure you got the whole public keythen save it.
CIS 191 - Lesson 13
http://kernel.org/
Import the public key to your key collection
CIS 191 - Lesson 13
http://kernel.org/
List your set of keys and verify it was added
CIS 191 - Lesson 13
http://kernel.org/
You will get a warning unless you have built a trust path to the Linux Kernel Archives Verification Key
The first section shows the verification
CIS 191 - Lesson 13
The Linux KernelBuilding a New Kernel
Obtain and verify kernel source tarball Extract source code Install development tools Configure the kernel options
make config or make menuconfig or make xconfig or make gconfig or make oldconfig
make clean make bzImage make modules make modules_install make install
CIS 191 - Lesson 13
Extract source code
Extract the source code from the archivetar -xvjf linux-2.6.27.8.tar.bz2
Use j option for bzip2 compression
CIS 191 - Lesson 13
Extracting the kernel source code
Extract source code
CIS 191 - Lesson 13
Note the new linux-2.6.27.8 directory
cd into it
Extract source code
CIS 191 - Lesson 13
Building the kernel
Listing of the new linux-2.6.27.8 directory
CIS 191 - Lesson 13
Building the kernel
Peek at some C code written by Linus
CIS 191 - Lesson 13
The Linux KernelBuilding a New Kernel
Obtain and verify kernel source tarball Extract source code Install development tools Configure the kernel options
make config or make menuconfig or make xconfig or make gconfig or make oldconfig
make dep make clean make bzImage make modules make modules_install make install
CIS 191 - Lesson 13
http://kernel.org/
Install development toolsyum install gccyum install ncurses-devel
GNU C compiler and curses (line drawing characters) library
CIS 191 - Lesson 13
Install build tools
Install the C compiler
CIS 191 - Lesson 13
--> Processing Dependency: libgomp.so.1 for package: gcc--> Processing Dependency: libgcc >= 4.1.2-42.el5 for package: gcc--> Restarting Dependency Resolution with new changes.--> Populating transaction set with selected packages. Please wait.---> Downloading header for cpp to pack into transaction set.cpp-4.1.2-42.el5.i386.rpm 100% |=========================| 64 kB 00:00---> Package cpp.i386 0:4.1.2-42.el5 set to be updated---> Downloading header for libgcc to pack into transaction set.libgcc-4.1.2-42.el5.i386. 100% |=========================| 60 kB 00:00---> Package libgcc.i386 0:4.1.2-42.el5 set to be updated---> Downloading header for glibc-devel to pack into transaction set.glibc-devel-2.5-24.el5_2. 100% |=========================| 111 kB 00:02---> Package glibc-devel.i386 0:2.5-24.el5_2.2 set to be updated---> Downloading header for libgomp to pack into transaction set.libgomp-4.1.2-42.el5.i386 100% |=========================| 60 kB 00:00---> Package libgomp.i386 0:4.1.2-42.el5 set to be updated--> Running transaction check--> Processing Dependency: glibc-headers for package: glibc-devel--> Processing Dependency: glibc = 2.5-24.el5_2.2 for package: glibc-devel--> Processing Dependency: glibc-headers = 2.5-24.el5_2.2 for package: glibc-develRestarting Dependency Resolution with new changes.--> Populating transaction set with selected packages. Please wait.
Install the C compiler (continued)
Install build tools
CIS 191 - Lesson 13
--> Populating transaction set with selected packages. Please wait.---> Downloading header for glibc-headers to pack into transaction set.glibc-headers-2.5-24.el5_ 100% |=========================| 144 kB 00:01---> Package glibc-headers.i386 0:2.5-24.el5_2.2 set to be updated---> Downloading header for glibc to pack into transaction set.glibc-2.5-24.el5_2.2.i686 100% |=========================| 146 kB 00:01---> Package glibc.i686 0:2.5-24.el5_2.2 set to be updated--> Running transaction check--> Processing Dependency: glibc-common = 2.5-24.el5_2.2 for package: glibc--> Restarting Dependency Resolution with new changes.--> Populating transaction set with selected packages. Please wait.---> Downloading header for glibc-common to pack into transaction set.glibc-common-2.5-24.el5_2 100% |=========================| 725 kB 00:09---> Package glibc-common.i386 0:2.5-24.el5_2.2 set to be updated--> Running transaction check
Dependencies Resolved
Install the C compiler (continued)
Install build tools
CIS 191 - Lesson 13
Building the kernel
============================================================================= Package Arch Version Repository Size=============================================================================Installing: gcc i386 4.1.2-42.el5 base 5.2 MInstalling for dependencies: glibc-devel i386 2.5-24.el5_2.2 updates 2.0 M glibc-headers i386 2.5-24.el5_2.2 updates 611 k libgomp i386 4.1.2-42.el5 base 82 kUpdating for dependencies: cpp i386 4.1.2-42.el5 base 2.7 M glibc i686 2.5-24.el5_2.2 updates 5.2 M glibc-common i386 2.5-24.el5_2.2 updates 16 M libgcc i386 4.1.2-42.el5 base 93 k
Transaction Summary=============================================================================Install 4 Package(s)Update 4 Package(s)Remove 0 Package(s)
Total download size: 32 MIs this ok [y/N]: y
Install the C compiler (continued)
CIS 191 - Lesson 13
Building the kernelIs this ok [y/N]: yDownloading Packages:(1/8): libgcc-4.1.2-42.el 100% |=========================| 93 kB 00:01(2/8): glibc-devel-2.5-24 100% |=========================| 2.0 MB 00:20(3/8): glibc-headers-2.5- 100% |=========================| 611 kB 00:07(4/8): gcc-4.1.2-42.el5.i 100% |=========================| 5.2 MB 00:51(5/8): cpp-4.1.2-42.el5.i 100% |=========================| 2.7 MB 00:21(6/8): glibc-2.5-24.el5_2 100% |=========================| 5.2 MB 01:07(7/8): glibc-common-2.5-2 100% |=========================| 16 MB 04:40(8/8): libgomp-4.1.2-42.e 100% |=========================| 82 kB 00:01Running Transaction TestFinished Transaction TestTransaction Test Succeeded
Install the C compiler (continued)
CIS 191 - Lesson 13
Building the kernelRunning Transaction Updating : libgcc ####################### [ 1/12] Updating : glibc-common ####################### [ 2/12] Updating : glibc ####################### [ 3/12] Installing: glibc-headers ####################### [ 4/12] Installing: glibc-devel ####################### [ 5/12] Updating : cpp ####################### [ 6/12] Installing: libgomp ####################### [ 7/12] Installing: gcc ####################### [ 8/12] Cleanup : libgcc ####################### [ 9/12] Cleanup : cpp ####################### [10/12] Cleanup : glibc ####################### [11/12] Cleanup : glibc-common ####################### [12/12]
Installed: gcc.i386 0:4.1.2-42.el5Dependency Installed: glibc-devel.i386 0:2.5-24.el5_2.2 glibc-headers.i386 0:2.5-24.el5_2.2 libgomp.i386 0:4.1.2-42.el5Dependency Updated: cpp.i386 0:4.1.2-42.el5 glibc.i686 0:2.5-24.el5_2.2 glibc-common.i386 0:2.5-24.el5_2.2 libgcc.i386 0:4.1.2-42.el5Complete![root@benji tarballs]#
Install the C compiler (continued)
CIS 191 - Lesson 13
Building the kernel
Install ncurses-devel for make menu-config tool
CIS 191 - Lesson 13
Building the kernel
Transaction Summary=============================================================================Install 1 Package(s)Update 0 Package(s)Remove 0 Package(s)
Total download size: 1.6 MIs this ok [y/N]: yDownloading Packages:(1/1): ncurses-devel-5.5- 100% |=========================| 1.6 MB 00:11Running Transaction TestFinished Transaction TestTransaction Test SucceededRunning Transaction Installing: ncurses-devel ######################### [1/1]
Installed: ncurses-devel.i386 0:5.5-24.20060715Complete![root@benji linux-2.6.27.8]#
install ncurses-devel (continued)
CIS 191 - Lesson 13
The Linux KernelBuilding a New Kernel
Obtain and verify kernel source tarball Extract source code Install development tools Configure the kernel options
make config or make menuconfig or make xconfig or make gconfig or make oldconfig
make dep make clean make bzImage make modules make modules_install make install
CIS 191 - Lesson 13
The Linux KernelKernel Configuration Option Categories
• Code maturity level options • Loadable module support • Processor type and features • General setup • Memory Technology Devices • Plug n Play configuration • Block devices • Networking options • Telephony support • ATA/IDE/MFM/RLL support • SCSI support • I2O device support • Network device support
• Amateur radio support • IrDA (infrared) support • ISDN subsystem • Old CD-ROM drivers (not SCSI,
not IDE) • Character devices • Multimedia devices • File systems • Console drivers • Sound • USB support • Kernel hacking
There are bazillions of options for building the kernel
CIS 191 - Lesson 13
The Linux KernelKernel Configuration Options
make config
or make menuconfig or make xconfig
or make gconfig
or make oldconfig
CIS 191 - Lesson 13
make config (and holding down the enter key)
Configuring the kernel build
CIS 191 - Lesson 13
Configuring the kernel buildmake config method
[root@benji linux-2.6.27.8]# make config HOSTCC scripts/basic/fixdep HOSTCC scripts/basic/docproc HOSTCC scripts/kconfig/conf.o HOSTCC scripts/kconfig/kxgettext.o SHIPPED scripts/kconfig/zconf.tab.c SHIPPED scripts/kconfig/lex.zconf.c SHIPPED scripts/kconfig/zconf.hash.c HOSTCC scripts/kconfig/zconf.tab.o HOSTLD scripts/kconfig/confscripts/kconfig/conf arch/x86/Kconfig## using defaults found in /boot/config-2.6.18-8.el5#/boot/config-2.6.18-8.el5:1280:warning: symbol value 'm' invalid for FIXED_PHY/boot/config-2.6.18-8.el5:1532:warning: symbol value 'm' invalid for ISDN/boot/config-2.6.18-8.el5:2612:warning: symbol value 'm' invalid for RTC_INTF_SYSFS/boot/config-2.6.18-8.el5:2613:warning: symbol value 'm' invalid for
CIS 191 - Lesson 13
make config (continued)
Configuring the kernel build
http://simms-teach.com/docs/cis191/cis191esson13-make-config.pdf
(and holding down the Enter key to take all the defaults)
CIS 191 - Lesson 13
After running make config
[root@benji linux-2.6.27.8]# ls -latotal 616drwxrwxr-x 22 root root 4096 Dec 6 18:06 .drwxr-xr-x 3 root root 4096 Dec 6 18:01 ..drwxrwxr-x 24 root root 4096 Dec 5 12:03 archdrwxrwxr-x 2 root root 4096 Dec 5 12:03 block-rw-r--r-- 1 root root 72417 Dec 6 18:06 .config-rw-rw-r-- 1 root root 18693 Dec 5 12:03 COPYING-rw-rw-r-- 1 root root 92899 Dec 5 12:03 CREDITSdrwxrwxr-x 3 root root 4096 Dec 5 12:03 cryptodrwxrwxr-x 78 root root 12288 Dec 5 12:03 Documentationdrwxrwxr-x 80 root root 4096 Dec 5 12:03 driversdrwxrwxr-x 17 root root 4096 Dec 5 12:03 firmwaredrwxrwxr-x 64 root root 4096 Dec 5 12:03 fs-rw-rw-r-- 1 root root 867 Dec 5 12:03 .gitignoredrwxrwxr-x 31 root root 4096 Dec 6 18:05 includedrwxrwxr-x 2 root root 4096 Dec 5 12:03 initdrwxrwxr-x 2 root root 4096 Dec 5 12:03 ipc
Configuring the kernel build
http://simms-teach.com/docs/cis191/cis191esson13-dot-config.pdf
CIS 191 - Lesson 13
-rw-rw-r-- 1 root root 2430 Dec 5 12:03 Kbuilddrwxrwxr-x 6 root root 4096 Dec 5 12:03 kerneldrwxrwxr-x 6 root root 4096 Dec 5 12:03 libdrwxrwxr-x 6 root root 4096 Dec 5 12:03 lib-rw-rw-r-- 1 root root 3799 Dec 5 12:03 .mailmap-rw-rw-r-- 1 root root 101926 Dec 5 12:03 MAINTAINERS-rw-rw-r-- 1 root root 56768 Dec 5 12:03 Makefiledrwxrwxr-x 2 root root 4096 Dec 5 12:03 mmdrwxrwxr-x 43 root root 4096 Dec 5 12:03 net-rw-rw-r-- 1 root root 16930 Dec 5 12:03 README-rw-rw-r-- 1 root root 3172 Dec 5 12:03 REPORTING-BUGSdrwxrwxr-x 6 root root 4096 Dec 5 12:03 samplesdrwxrwxr-x 9 root root 4096 Dec 5 12:03 scriptsdrwxrwxr-x 5 root root 4096 Dec 5 12:03 securitydrwxrwxr-x 20 root root 4096 Dec 5 12:03 sounddrwxrwxr-x 2 root root 4096 Dec 5 12:03 usrdrwxrwxr-x 3 root root 4096 Dec 5 12:03 virt[root@benji linux-2.6.27.8]#
After running make config
Configuring the kernel build
skip this for now
CIS 191 - Lesson 13
make menuconfig
Configuring the kernel build
needs ncurses package for line drawing set
CIS 191 - Lesson 13
make menuconfig
Configuring the kernel build
CIS 191 - Lesson 13
make oldconfig
and hold down the enter key
Configuring the kernel build
CIS 191 - Lesson 13
Note make config and make oldconfig yielded the same configuration file
Configuring the kernel build
CIS 191 - Lesson 13
The hidden .config file
[root@benji linux-2.6.27.8]# ls -a. .config.old drivers init .mailmap README sound.. COPYING firmware ipc MAINTAINERS REPORTING-BUGS usrarch CREDITS fs Kbuild Makefile samples virtblock crypto .gitignore kernel mm scripts.config Documentation include lib net security[root@benji linux-2.6.27.8]#
Configuring the kernel build
http://simms-teach.com/docs/cis191/cis191esson13-dot-config.pdf
CIS 191 - Lesson 13
.config file
Configuring the kernel build
http://simms-teach.com/docs/cis191/cis191esson13-make-config.pdf
CIS 191 - Lesson 13
The Linux KernelBuilding a New Kernel
Obtain and verify kernel source tarball Extract source code Install development tools Configure the kernel options
make config or make menuconfig or make xconfig or make gconfig or make oldconfig
make dep (not required for v2.6 and higher) make clean make bzImage make modules make modules_install make install
We are building a v2.6 kernel
CIS 191 - Lesson 13
Building the kernel
Clean up miscellaneous object files
CIS 191 - Lesson 13
The Linux KernelBuilding a New Kernel
Obtain and verify kernel source tarball Extract source code Install development tools Configure the kernel options
make config or make menuconfig or make xconfig or make gconfig or make oldconfig
make dep (not required for v2.6 and higher) make clean make bzImage make modules make modules_install make install
CIS 191 - Lesson 13
Building the kernel
Start compiling
11:42 pm – 11:52 pm
http://simms-teach.com/docs/cis191/cis191esson13-make-bzImage.pdf
CIS 191 - Lesson 13
The Linux KernelBuilding a New Kernel
Obtain and verify kernel source tarball Extract source code Install development tools Configure the kernel options
make config or make menuconfig or make xconfig or make gconfig or make oldconfig
make dep (not required for v2.6 and higher) make clean make bzImage make modules make modules_install make install
CIS 191 - Lesson 13
Building the kernel
Start compiling modules
11:59 -12:20
http://simms-teach.com/docs/cis191/cis191esson13-make-modules.pdf
CIS 191 - Lesson 13
Building the kernel
Post compile
[root@benji linux-2.6.27.8]# ls -aF./ ipc/ scripts/ .tmp_vmlinux1*../ Kbuild security/ ..tmp_vmlinux1.cmdarch/ kernel/ sound/ .tmp_vmlinux2*block/ lib/ System.map ..tmp_vmlinux2.cmd.config .mailmap .tmp_kallsyms1.o .tmp_vmlinux3*COPYING MAINTAINERS ..tmp_kallsyms1.o.cmd ..tmp_vmlinux3.cmdCREDITS Makefile .tmp_kallsyms1.S usr/crypto/ .missing-syscalls.d .tmp_kallsyms2.o .versionDocumentation/ mm/ ..tmp_kallsyms2.o.cmd virt/drivers/ modules.order .tmp_kallsyms2.S vmlinux*firmware/ Module.symvers .tmp_kallsyms3.o .vmlinux.cmdfs/ net/ ..tmp_kallsyms3.o.cmd vmlinux.o.gitignore README .tmp_kallsyms3.S .vmlinux.o.cmdinclude/ REPORTING-BUGS .tmp_System.mapinit/ samples/ .tmp_versions/[root@benji linux-2.6.27.8]#
CIS 191 - Lesson 13
Building the kernel
Post compile
[root@benji linux-2.6.27.8]# ls -ltotal 153100drwxrwxr-x 25 root root 4096 Dec 6 18:25 archdrwxrwxr-x 2 root root 4096 Dec 6 18:37 block-rw-rw-r-- 1 root root 18693 Dec 5 12:03 COPYING-rw-rw-r-- 1 root root 92899 Dec 5 12:03 CREDITSdrwxrwxr-x 3 root root 12288 Dec 6 18:53 cryptodrwxrwxr-x 78 root root 12288 Dec 5 12:03 Documentationdrwxrwxr-x 80 root root 4096 Dec 6 18:46 driversdrwxrwxr-x 17 root root 4096 Dec 6 18:56 firmwaredrwxrwxr-x 64 root root 12288 Dec 6 18:37 fsdrwxrwxr-x 31 root root 4096 Dec 6 18:16 includedrwxrwxr-x 2 root root 4096 Dec 6 18:34 initdrwxrwxr-x 2 root root 4096 Dec 6 18:37 ipc-rw-rw-r-- 1 root root 2430 Dec 5 12:03 Kbuilddrwxrwxr-x 6 root root 12288 Dec 6 18:34 kerneldrwxrwxr-x 6 root root 12288 Dec 6 18:55 lib-rw-rw-r-- 1 root root 101926 Dec 5 12:03 MAINTAINERS-rw-rw-r-- 1 root root 56768 Dec 5 12:03 Makefiledrwxrwxr-x 2 root root 4096 Dec 6 18:34 mm
CIS 191 - Lesson 13
Building the kernel
Post compile
drwxrwxr-x 2 root root 4096 Dec 6 18:34 mm-rw-r--r-- 1 root root 33750 Dec 6 18:52 modules.order-rw-r--r-- 1 root root 337836 Dec 6 18:52 Module.symversdrwxrwxr-x 43 root root 4096 Dec 6 18:52 net-rw-rw-r-- 1 root root 16930 Dec 5 12:03 README-rw-rw-r-- 1 root root 3172 Dec 5 12:03 REPORTING-BUGSdrwxrwxr-x 6 root root 4096 Dec 5 12:03 samplesdrwxrwxr-x 9 root root 4096 Dec 6 18:34 scriptsdrwxrwxr-x 5 root root 4096 Dec 6 18:37 securitydrwxrwxr-x 20 root root 4096 Dec 6 18:56 sound-rw-r--r-- 1 root root 1076204 Dec 6 18:25 System.mapdrwxrwxr-x 2 root root 4096 Dec 6 18:34 usrdrwxrwxr-x 3 root root 4096 Dec 5 12:03 virt-rwxr-xr-x 1 root root 69534188 Dec 6 18:25 vmlinux-rw-r--r-- 1 root root 85037854 Dec 6 18:24 vmlinux.o[root@benji linux-2.6.27.8]#
vmlinux is the uncompressed kernel
CIS 191 - Lesson 13
Building the kernel
text segment: the instructions that will be executed by the CPU
data segment: initialized program variables
bss: uninitialized or zero-initialized data segment
CIS 191 - Lesson 13
Building the kernel
Post compile
bxImage is the compressed version of the new kernel
CIS 191 - Lesson 13
The Linux KernelBuilding a New Kernel
Obtain and verify kernel source tarball Extract source code Install development tools Configure the kernel options
make config or make menuconfig or make xconfig or make gconfig or make oldconfig
make dep (not required for v2.6 and higher) make clean make bzImage make modules make modules_install make install
CIS 191 - Lesson 13
Building the kernel
Check disk space before make modules_install
The kernel modules will be placed in /lib using up more of /dev/sda1
CIS 191 - Lesson 13
Building the kernel
make modules_install
http://simms-teach.com/docs/cis191/cis191esson13-make-modules_install.pdf
CIS 191 - Lesson 13
Building the kernel
After make modules_install
CIS 191 - Lesson 13
Building the kernelAfter make modules_install
Increased / partition usage from 69% to 77%
CIS 191 - Lesson 13
The Linux KernelBuilding a New Kernel
Obtain and verify kernel source tarball Extract source code Install development tools Configure the kernel options
make config or make menuconfig or make xconfig or make gconfig or make oldconfig
make dep (not required for v2.6 and higher) make clean make bzImage make modules make modules_install make install
CIS 191 - Lesson 13
Building the kernelBefore make install
CIS 191 - Lesson 13
Building the kernelBefore make install
[root@benji linux-2.6.27.8]# ls /bootconfig-2.6.18-8.el5 symvers-2.6.18-8.el5.gzconfig-2.6.18-92.1.13.el5 symvers-2.6.18-92.1.13.el5.gzgrub System.map-2.6.18-8.el5initrd-2.6.18-8.el5.img System.map-2.6.18-92.1.13.el5initrd-2.6.18-92.1.13.el5.img vmlinuz-2.6.18-8.el5message vmlinuz-2.6.18-92.1.13.el5[root@benji linux-2.6.27.8]#
Note that we do not see 2.6.27.8 files
CIS 191 - Lesson 13
Building the kernelmake install
CIS 191 - Lesson 13
Building the kernelAfter make install
[root@benji linux-2.6.27.8]# cat /boot/grub/grub.conf# grub.conf generated by anaconda## Note that you do not have to rerun grub after making changes to this file# NOTICE: You do not have a /boot partition. This means that# all kernel and initrd paths are relative to /, eg.# root (hd0,0)# kernel /boot/vmlinuz-version ro root=/dev/sda1# initrd /boot/initrd-version.img
#boot=/dev/sda1default=2timeout=60splashimage=(hd0,0)/boot/grub/splash.xpm.gz#hiddenmenutitle CentOS (2.6.27.8) root (hd0,0) kernel /boot/vmlinuz-2.6.27.8 ro root=LABEL=/1 rhgb quiet initrd /boot/initrd-2.6.27.8.imgtitle CentOS (2.6.18-92.1.13.el5) root (hd0,0) kernel /boot/vmlinuz-2.6.18-92.1.13.el5 ro root=LABEL=/1 rhgb quiet initrd /boot/initrd-2.6.18-92.1.13.el5.imgtitle CentOS (2.6.18-8.el5) root (hd0,0) kernel /boot/vmlinuz-2.6.18-8.el5 ro root=LABEL=/1 rhgb quiet initrd /boot/initrd-2.6.18-8.el5.imgtitle My Distro root (hd0,0) kernel /boot/vmlinuz-2.6.18-8.el5 ro root=/dev/sda6 init=/bin/bash initrd /boot/initrd-2.6.18-8.el5.img[root@benji linux-2.6.27.8]#
CIS 191 - Lesson 13
Building the kernelAfter make install the kernel is copied to the /boot directory
copy of bzImage (compressed kernel)
Initial ram disk
kernel symbol table
bzImage = vmlinuz
CIS 191 - Lesson 13
The Linux KernelBuilding a New Kernel
Obtain and verify kernel source tarball Extract source code Install development tools Configure the kernel options
make config or make menuconfig or make xconfig or make gconfig or make oldconfig
make dep (not required for v2.6 and higher) make clean make bzImage make modules make modules_install make install
CIS 191 - Lesson 13
Building the kernelAfter make install
CIS 191 - Lesson 13
Building the kernelAfter make install
CIS 191 - Lesson 13
Patches
CIS 191 - Lesson 13
The Linux KernelPatches
• Applying a Kernel Patch
‒ copy the patch file to /depot
‒ uncompress it with bunzip2 or gunzip as
appropriate
‒ cd to your kernel build directory (named using
the version number of the full kernel built
previously)
‒ patch -p1 < ../patch-2.6.27.n
‒ Apply patches in order
‒ Rebuild everything again
CIS 191 - Lesson 13
Kernel RPM Updates
CIS 191 - Lesson 13
Updating a kernel RPMBe careful
CIS 191 - Lesson 13
Updating a kernel RPMCentOS 5 kernel "update" using install
[root@star ~]# cat /boot/grub/grub.conf# grub.conf generated by anaconda## Note that you do not have to rerun grub after making changes to this file# NOTICE: You have a /boot partition. This means that# all kernel and initrd paths are relative to /boot/, eg.# root (hd0,1)# kernel /vmlinuz-version ro root=/dev/sda3# initrd /initrd-version.img#boot=/dev/sda2default=0timeout=35splashimage=(hd0,1)/grub/splash.xpm.gz#hiddenmenutitle CentOS (2.6.18-8.el5) root (hd0,1) kernel /vmlinuz-2.6.18-8.el5 ro root=LABEL=/ rhgb initrd /initrd-2.6.18-8.el5.imgtitle FreeDOS rootnoverify (hd0,0) chainloader +1[root@star ~]#
Note: This is on the star VM
CIS 191 - Lesson 13
Updating a kernel RPMCentOS 5 kernel "update" using install
[root@star ~]# yum install kernelLoading "installonlyn" pluginSetting up Install ProcessSetting up repositoriesReading repository metadata in from local filesParsing package install argumentsResolving Dependencies--> Populating transaction set with selected packages. Please wait.---> Downloading header for kernel to pack into transaction set.kernel-2.6.18-92.1.13.el5 100% |=========================| 319 kB 00:01---> Package kernel.i686 0:2.6.18-92.1.13.el5 set to be installed--> Running transaction check
Dependencies Resolved
============================================================================= Package Arch Version Repository Size=============================================================================Installing: kernel i686 2.6.18-92.1.13.el5 updates 14 M
Transaction Summary=============================================================================Install 1 Package(s)Update 0 Package(s)Remove 0 Package(s)
Total download size: 14 MIs this ok [y/N]: y
New kernel version available
User confirms here
CIS 191 - Lesson 13
Updating a kernel RPMCentOS 5 kernel "update" using install
Downloading Packages:(1/1): kernel-2.6.18-92.1 100% |=========================| 14 MB 01:15warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing Key) <[email protected]>" from http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
Is this ok [y/N]: yRunning Transaction TestFinished Transaction TestTransaction Test SucceededRunning Transaction Installing: kernel ######################### [1/1]
Installed: kernel.i686 0:2.6.18-92.1.13.el5Complete![root@star ~]#
New kernel is installed …
CIS 191 - Lesson 13
Updating a kernel RPMCentOS 5 kernel "update" using install
[root@star ~]# cat /boot/grub/grub.conf# grub.conf generated by anaconda## Note that you do not have to rerun grub after making changes to this file# NOTICE: You have a /boot partition. This means that# all kernel and initrd paths are relative to /boot/, eg.# root (hd0,1)# kernel /vmlinuz-version ro root=/dev/sda3# initrd /initrd-version.img#boot=/dev/sda2default=0timeout=35splashimage=(hd0,1)/grub/splash.xpm.gz#hiddenmenutitle CentOS (2.6.18-92.1.13.el5) root (hd0,1) kernel /vmlinuz-2.6.18-92.1.13.el5 ro root=LABEL=/ rhgb initrd /initrd-2.6.18-92.1.13.el5.imgtitle CentOS (2.6.18-8.el5) root (hd0,1) kernel /vmlinuz-2.6.18-8.el5 ro root=LABEL=/ rhgb initrd /initrd-2.6.18-8.el5.imgtitle FreeDOS rootnoverify (hd0,0) chainloader +1[root@star ~]#
… and grub.conf is modified to show the new kernel boot option