This Presentation Speaks about Compiling Linux Kernel from source, How Device Drivers are implemented in Linux,Udev,Loading and Unloading of Kernel modules.
Shreyas MM
www.shreyasmm.com
2. Introduction
• A new Kernel comes out every 2 - 3 months
Current – 4.3
Next Release – 4.4 LTS ( Jan – Feb 2016 )
• What do you think there is so much to work on Kernel ?
3. Introduction
Here are what goes on each new Kernel release
ReworkThings
Improve performance
Fix a Problem
Add Support for New Device
Add New Feature
5. Kernel Modules
• Kernel supports most of the Devices
• Devices Drivers are implemented as Kernel modules
• Kernel modules are not part of Core Kernel
6. Kernel Modules
• Kernel modules are loaded only when they are required
• Eg – Kernel module usbhid is loaded when USB Mouse is
Attached
• Kernel Modules have .ko extension
7. Compiling Kernel From Source
~sudo su
# cd /usr/src
# curl https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-
4.3.tar.xz
# tar –xvJf linux-4.3.tar.xz
# cd linux-4.3
# apt-get update
# apt-get install build-essentials openssh-server libssl
libncurses libncurses-devel
# make menuconfig
8. Compiling Kernel From Source
Here we have option to support Devices based on Vendor, products
Eg – we can completely Disable support for usb devices itself
9. Compiling Kernel From Source
# make
# make modules
# make modules_install
# make install
# reboot
# uname –r
4.3
Compile main Kernel
Compile Kernel Modules
Install Kernel Modules - /lib/modules/4.3/
Install New Kernel - /boot
|->vmlinuz-4.3
|->System.map-4.3
|->vmlinuz-4.3
|->initrd.img-4.3
|->config-4.3
New Grub Entries are
automatically created
10. Kernel
• Kernel sends uevent when new device is plugged
• We can load Kernel modules with modprobe
# modprobe hid-generic
11. Udev
• Udev is daemon
• Udev is Device Manager for Linux Kernel
• Udev Operates in User Space
• Udev listens to Kernel uevents via netlink socket
• Primarily Manages Device Nodes in /dev
Device nodes are special files that allow
application to interface device drivers
12. What happens when USB Mouse or device is Plugged ?
udevd
USB mouse
is hotpluged
New uevent
Load usbhid
module
Create
New device node
/dev/input/mouse1
Application
Application &
Hardware interact
via device file &
module
1 5
4
3
2
13. Some Commands for Module Management
# lsmod
# modinfo
# modprobe
# insmod
# rmmod
# depmod
# udevadm
# dmesg
List of modules loaded in kernel
Get module info
Load a new module
Insert module from file
Remove a module
Check Dependency of module
Udev daemon Control
Prints Message buffer of Kernel