The Linux Kernel1LIN-21]The-Linux-kernel.pdf · 2014-08-06 · The Linux Kernel . Course objectives...
Transcript of The Linux Kernel1LIN-21]The-Linux-kernel.pdf · 2014-08-06 · The Linux Kernel . Course objectives...
System’s core Campus-Booster ID : **XXXXX
www.supinfo.com Copyright © SUPINFO. All rights reserved
The Linux Kernel
Your trainer…
Title: **Enter title or job role. Accomplishments: **What makes the presenter qualified to present this course.
Education: **List degrees if important. Publications: **Writings by the presenter on the subject of the course or presentation.
Contact: **Campus-Booster ID: [email protected]
Presenter’s Name
The Linux Kernel
Course objectives
n Talk about kernel types and Linux architecture. Tanenbaum’s delight.
n Manage modules and parameters. Make your devices to work.
n Apply patches. Add third-party features, or even your own !
n Configure, compile, and install a new kernel. Dive into menuconfig.
By completing this course, you will:
The Linux Kernel
Course topics
n About kernels. One concept, different implementations.
n Linux. A focus on your favorite operating system.
n Module management. Work with modules and parameters.
n Patching. Apply patches to the kernel sources.
n Configure and compile. Your very own kernel.
Course’s plan:
The Linux Kernel
About Kernels
One concept, different implementations
The Linux Kernel
What’s a kernel ? About Kernels
n Provide abstractions
n files / filesystem
n Network sockets
n …
n Manage hardware
n Allocate CPU time
§ Multitasking
n Manage memory
§ Process isolation
§ Virtual memory
Turn expensive paperweight into a computer.
Kernel families About Kernels
n Monolithic kernels
n everything run in kernel mode (ring 0 on x86)
§ Crash on fault
n Faster
n Easier to implement
n Micro kernel
n Most services as userland processes
§ No crash on fault, just restart faulty “server”
n Slower (context switches)
n Hard to keep in sync
Different implementations to provide the same services.
Monolithic kernel About Kernels
Hardware Drivers
Network stack
Virtual Memory Management
Micro kernel About Kernels
Hardware Drivers
Network stack
Filesystem Micro kernel
Stop-and-think About Kernels
Do you have any questions ?
Stop-and-think About Kernels
Micro kernel
Monolithic
Something else
Both
What do you think about Linux ?
Stop-and-think About Kernels
Micro kernel
Monolithic
Something else
Both
What do you think about Linux ?
Linux
A focus on your favorite operating system
The Linux Kernel
History Linux
n Started as a hobby
n Minix-like
n Monolithic
n Released in (19)91
n To run GNU tools on x86
n “Never gonna be professional like Hurd”
n Joined by
n Individuals
n Companies
Linus Torvalds’ “Toy OS”.
Linux or GNU/Linux ? Linux
n Running controversy
n Considered trivial
n “Linux” systems
n GNU Userland
n Linux kernel
n Stallman insists on GNU/Linux
n Getting old
n FSF “Newspeak”
n “Linux” more widespread
Vi or Emacs ?
Linux system stack Linux
Development and versioning Linux
n Sources available from kernel.org
n Patches
n Full versions
n Versioning
n Version.major.minor-rev
n Main trunk: 2.6.x
n Old trunk: 2.4.x
§ Still used for embedded devices
Where is the latest kernel ?
What’s the running kernel version ? Linux
The uname command
Options Definitions
-a
-s
-r
All information
Kernel name
Kernel release (version no)
[user@linux ~]$ uname [options]
[user@linux ~]$ uname –r 2.6.38.2
Example:
Architecture Linux
n Monolithic
n Everything in kernel land
n Privileged mode
n Modular
n Load code at runtime
§ Dynamic linking
n No difference between loaded and core code
n Reduce memory footprint
Modules doesn’t mean microkernel
Architecture Linux
n Modules
n Functional units
n Provide features
n Hardware drivers
n Wide range
n Gigantic footprint
n Load only what’s needed
§ Connected hardware
Modules ?
Stop-and-think Linux
Do you have any questions ?
Stop-and-think Linux
True
False
Linux kernel modules are running in userland.
Stop-and-think Linux
True
False
Linux kernel modules are running in userland.
Modules management
Work with modules and parameters
The Linux Kernel
Module files Modules management
n Modules are stored as
n .ko (kernel objects)
n .ko.gz (compressed)
n Per kernel
n /lib/modules/kernel-version n Per category
n /lib/modules/2.6.18/kernel/drivers/char/drm/radeon.ko
n Tools work
n Files
n Names
Where are they stored ?
List currently loaded modules Modules management
With the lsmod command
n Get a list of currently loaded modules and deps:
root@localhost # lsmod Module Size Used by radeon 108832 1 drm 72852 2 radeon ...
List currently loaded modules Modules management
With the lsmod command
n Get a list of currently loaded modules and deps:
root@localhost # lsmod Module Size Used by radeon 108832 1 drm 72852 2 radeon ...
Loading modules Modules management
The modprobe command
Arguments Definitions
options
module
params
man 8 modprobe
module name
Module parameters (see modinfo)
[root@linux ~]# modprobe [options] module [params]
[root@linux ~]# modprobe snd-had-intel model=7c
Example:
Loading modules Modules management
The insmod command
Arguments Definitions
module-file
params
Path to the kernel object
module parameters (see modinfo)
[root@linux ~]# insmod module-file [params]
[root@linux ~]# insmod ./testmod.ko idx=2
Example:
Information about modules Modules management
The modinfo command
[user@linux ~]$ modinfo [options] module|module-file
[user@linux ~]$ modinfo snd-had-intel […]
Example:
Arguments Definitions
options
module
module-file
man 8 modinfo
module name
Module file to read from
Modules dependencies Modules management
The depmod command
[root@linux ~]# depmod [options] [version] [filenames]
[root@linux ~]# depmod
Example:
Arguments Definitions
-a
version
filenames
Probe all modules. Default
Kernel version to work with. Defaults to $(uname -r)
Specific modules to work on
Module unloading Modules management
The rmmod command
[root@linux ~]# rmmod [options] module-name
[root@linux ~]# rmmod pcnet32
Example:
Arguments Definitions
-f
-w
Force module unload. Use with caution.
Prevent new usage of the in-use module. When usage count == 0 proceed with unloading
Stop-and-think Modules management
Do you have any questions ?
Stop-and-think Modules management
You want to insert a module in the running kernel to support your wireless card. You need to set a custom value for the “prefix” parameter. Which command will you use ?
insmod
modprobe
depmod
rmmod
modinfo
Stop-and-think Modules management
You want to insert a module in the running kernel to support your wireless card. You need to set a custom value for the “prefix” parameter. Which command will you use ?
insmod
modprobe
depmod
rmmod
modinfo
Patching
Apply patches to the kernel sources
The Linux Kernel
Kernel flavors Patching
n Vanilla
n Official version from kernel.org
n Distro
n Customized vanilla
§ Distro patches
n Your flavor
n Vanilla/Distro
§ Your patches
§ Third-party patches
Kernels in the wild
Why patching ? Patching
n New features
n Not in Vanilla
n Not in your distro
n Bugfixes
n Kernel panics solved
n Enhancements
§ Performance
n Supported hardware
n Various hacks
Customized kernels
About patches Patching
Patches are released in ”diff" format: text file composed of code to add or to remove
diff command generate diff’s file:
# diff –Nur original modified > diff_file
--- soft-orig/src/amazing.c 2008-01-13 22:27:33.000000000 +0100
+++ soft/src/amazingV2.c 2008-01-13 22:16:32.000000000 +0100
@@ -3,5 +3,6 @@
int main(int argc, char **argv)
{
int result = 0;
+ result =+ 1;
return result;
}
Patch level Patching
n Patches are creating and applied in different contexts
n --- soft-orig/src/main.c n +++ soft-modified/src/main.c
n Will be applied to
n soft/src/main.c § Need to rebase
§ Strip X path components
n Rebase 1 level
§ src/main.c
§ Apply from soft “root” dir
Rebasing paths.
Working with patches Patching
Apply patch
In the parent directory :
Remove patch :
[user@linux soft-1.2.3]$ patch -p1 < mypatch.diff
[user@linux soft-1.2.3]$ patch -R < mypatch.diff
Stop-and-think Patching
Do you have any questions ?
Stop-and-think Patching
1
2
3
4
5
The kernel source is in /usr/src/linux. You are in this directory. You want to apply a (poorly written) patch. The patch begins with “--- usr/src/linux/fs/aio.c”. Which patch level are you going to use ?
Stop-and-think Patching
1
2
3
4
5
The kernel source is in /usr/src/linux. You are in this directory. You want to apply a (poorly written) patch. The patch begins with “--- usr/src/linux/fs/aio.c”. Which patch level are you going to use ?
Configure and compile
Your very own kernel
The Linux Kernel
Why ? Configure and compile
n Optimize
n Only needed features
n Smaller binary
n Faster kernel
n Compile for your arch
n New features
n Patched version
n New version not in your distro repositories
n The geek touch
Two good reasons and the real one.
How ? Configure and compile
n Download the sources
n kernel.org
n Be sure to select the ‘F’ull version
n Unpack in /usr/src
n You get /usr/src/linux-x.y.z
n Create /usr/src/linux symlink
n Configure
n Compile
n Install
n You may need to manually update your bootloader
Quick howto.
Tools Configure and compile
n Working toolchain
n Compiler (gcc)
n Assembler (gas)
n Linker (ld)
n The make tool
n libncurses to do menuconfig
n development headers
n Various graphic libs for other *config targets
What you’ll need.
Configure Configure and compile
n make menuconfig
n Navigate with arrows
n Select with enter
n Read help
n Search with ‘/’
n Feature status with space
n ‘*’ Builtin/enabled
n ‘M’ Module
n ‘ ‘ Not build/disabled
n Use ‘exit’ button to save
Most important step.
Guided tour Configure and compile
Compile and install Configure and compile
n You may now have to configure the bootloader
n Many distros have hooks for “make install” stage
# make # make install
# make modules_install
n Kernel compilation and installation
Stop-and-think Configure and compile
Do you have any questions ?
Stop-and-think Configure and compile
True
False
The “make install” command copies the kernel image to /boot and the modules to /lib/modules/kernel-version.
Stop-and-think Configure and compile
True
False
The “make install” command copies the kernel image to /boot and the modules to /lib/modules/kernel-version.
Applying patches
Kernel configuration
dialog Kernel types
Compile and install
Course summary
Linux kernel architecture &
modules management
The Linux Kernel
For more The Linux Kernel
If you want to go into these subjects more deeply, …
Courses Publications
Web sites
www.labo-linux.com
www.blackbeltfactory.com
Linux Technologies: Edge Computing
Conferences
FOSDEM
RMLL
Solutions Linux
If you want to go into these subjects more deeply, …
www.supinfo.com
Understanding the Linux kernel
Congratulations
You have successfully completed the SUPINFO course module n°22
The Linux kernel
The end
n Read all config items help text and don’t hesitate to try n Always keep a working kernel to boot your system
The Linux Kernel