CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
Linux kernel
1. 1
Kernel, Module and DriverKernel, Module and Driver
ConfigurationConfiguration
AUT LinuxFest 2017AUT LinuxFest 2017
Mahmoud Shiri VaraminiMahmoud Shiri Varamini
shirivaramini@gmail.comshirivaramini@gmail.com
2. Agenda
• Introduction to Linux kernel
• Compiling Linux kernelCompiling Linux kernel
• Working with grub2 boot loaderWorking with grub2 boot loader
• Manually updating the kernelManually updating the kernel
• Working with kernel modulesWorking with kernel modules
• referencereference
• QuestionsQuestions
4. What Is Kernel?
●
central module of an operating system (OS)
●
the part of the operating system that loads first, and it remains in main memory.
●
can be contrasted with a shell, the outermost part of an operating system that interacts
with user commands.
●
Manage your hardware and system resources
5. What Dose Kernel?
●
is responsible for memory management, process and task management, and disk
management.
●
connects the system hardware to the application software
6. Main Parts (1)
System call interface (SCI)
●
A thin layer that provides a method to interact from
●
user space to kernel space
Process Management (PM)
●
Create, destroy processes
●
Communication between different processes (kernel threads)
●
CPU scheduling
Memory Management (MM)
●
Physical to virtual memory management
●
Memory allocation
●
Swapping, from memory to hard disk
7. Main Parts (2)
Network Stack
●
Implement the network protocols
●
Deliver packets across programs and network interfaces
Device Drivers (DD)
●
Interact with the hardware
●
Extract an abstraction of the device functionalities
Arch
●
Architecture dependent code
8. Main Parts (I/O PATH)
Virtual File System (VFS)
●
Eports the common file interface
●
Abstract file system functionality from implementation
File Systems
●
Implementation of FS functionality
Buffer Cache
●
A set of functions to manipulate main memory designed for FS
Device Driver
●
Physical Device
●
Where data live
10. Kernel.org
The Linux Kernel Organization is a California Public Benefit Corporation established in
2002 to distribute the Linux kernel and other Open Source software to the public without
charge.
11. Should We Compile Kernel?
you don’t need to compile the kernel, as it is installed by default when you install the OS.
Also, when there is a critical update done to the kernel, you can use yum, or apt-get to
update the kernel on your Linux system.
●
To enable experimental features that are not part of the default kernel.
●
To enable support for a new hardware that is not currently supported by the default
kernel.
●
To debug the kernel
●
Or, just to learn how kernel works, you might want to explore the kernel source code, and
compile it on your own.
12. Let’s Do It!!!
The first step is to download the latest stable kernel from kernel.org.
# cd /opt/
# wget “https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.10.14.tar.xz”
# tar -xvf linux-4.10.14.tar.xz
The kernel contains nearly 3000 configuration options. To make the kernel used by most
people on most hardware, the Linux distro like Ubuntu, Fedora, Debian, RedHat, CentOS,
etc, will generally include support for most common hardware. You can take any one of
configuration from the distro, and on top of that you can add your own configuration, or you
can configure the kernel from scratch, or you can use the default config provided by the
kernel.
13. Let’s Do It!!!
The first step is to download the latest stable kernel from kernel.org.
# cd ./linux-4.10.14
# make menuconfig
The kernel contains nearly 3000 configuration options. To make the kernel used by most
people on most hardware, the Linux distro like Ubuntu, Fedora, Debian, RedHat, CentOS,
etc, will generally include support for most common hardware. You can take any one of
configuration from the distro, and on top of that you can add your own configuration, or you
can configure the kernel from scratch, or you can use the default config provided by the
kernel.
The make menuconfig, will launch a text-based user interface with default configuration
options as shown in the figure. You should have installed “libncurses and libncurses-devel”
packages for this command to work.
14. Let’s Do It!!!
The first step is to download the latest stable kernel from kernel.org.
# cd ./linux-4.10.14
# make menuconfig
The kernel contains nearly 3000 configuration options. To make the kernel used by most
people on most hardware, the Linux distro like Ubuntu, Fedora, Debian, RedHat, CentOS,
etc, will generally include support for most common hardware. You can take any one of
configuration from the distro, and on top of that you can add your own configuration, or you
can configure the kernel from scratch, or you can use the default config provided by the
kernel.
The make menuconfig, will launch a text-based user interface with default configuration
options as shown in the figure. You should have installed “libncurses and libncurses-devel”
packages for this command to work.
16. Let’s Do It!!!
We will use the default config provided by the kernel. So select “Save” and save the config
in the file name “.config”.
Compile the main kernel:
# make
Compile the kernel modules:
# make modules
Install the kernel modules:
# make modules_install
17. Let’s Do It!!!
Install the new kernel on the system:
# make install
The make install command will create the following files in the /boot directory.
Vmlinuz-4.10.14 – The actual kernel
System.map-4.10.14 – The symbols exported by the kernel
initrd.img-4.10.14 – initrd image is temporary root file system used during boot process
Config-4.10.14 – The kernel configuration file
The command “make install” will also update the grub.cfg by default. So we don’t need to
manually edit the grub.cfg file.
18. Let’s Do It!!!
To use the new kernel that you just compiled, reboot the system.
# reboot
Since, in grub.cfg, the new kernel is added as default boot, the system will boot from the
new kernel. Just in case if you have problems with the new kernel, you can select the old
kernel from the grub menu during boot and you can use your system as usual.
Once the system is up, use uname command to verify that the new version of Linux kernel
is installed.
Finally We Did It !!
23. Introduction to GRUB 2 (1)
●
RHEL7,CentOS7,OEL7: GNU GRand Unified Boot loader (GRUB)
version 2 boot loader.
●
GRUB2 allows select an operating system or kernel to be loaded at
system boot time.
●
Also allows the user to pass arguments to the kernel.
24. Introduction to GRUB 2 (2)
●
reads its configuration /boot/grub2/grub.cfg file on traditional BIOS-basedmachines and
from the /boot/efi/EFI/redhat/grub.cfg file on UEFI machines.
$ less /boot/grub2/grub.cfg
$ chattr +i /boot/grub2/grub.cfg
$ lsattr /boot/grub2/grub.cfg
$ rm /boot/grub2/grub.cfg
Q: Dose work last command ?
●
file contains menu information.
●
grub.cfg generated during installation, or by invoking the /usr/sbin/grub2-mkconfig
utility, and is automatically updated by grubby each time a new kernel is installed.
●
When regenerated manually using grub2-mkconfig, the file is generated according to
the template files located in /etc/grub.d/, and custom settings in the /etc/default/grub
file.
●
Edits of grub.cfg will be lost any time grub2-mkconfig is used to regenerate the file, so
care must be taken to reflect any manual changes in /etc/default/grub as well.
27. Making Temporary Changes to a GRUB 2
Menu
To change kernel parameters only during a single boot process:
●
Start the system and, on the GRUB 2 boot screen, move the cursor to the menu entry
you want to edit, and press the e key for edit.
●
Move the cursor down to find the kernel command line. The kernel command line starts
with linux on 64-Bit IBM Power Series, linux16 on x86-64 BIOS-based systems, or
linuxefi on UEFI systems.
●
Edit the kernel parameters as required. For example, to run the system in emergency
mode,add the emergency parameter at the end of the linux16 line:
28. Making Persistent Changes to a GRUB 2
Menu Using the grubby Tool
To find out the file name of the default kernel, enter a command as follows:
To make a persistent change in the kernel designated as the default kernel:
To list all the kernel menu entries:
# grubby –info=ALL
To view the GRUB menu entry for a specific kerne:
$ grubby --info /boot/vmlinuz-3.10.0-229.el7.x86_64
29. Making Persistent Changes to a GRUB 2
Menu Using the grubby Tool
To add and remove arguments from a kernel's GRUB menu entry:
# grubby --add-args="rhgb quiet" --args=console=ttyS0,115200 --update-kernel
/boot/vmlinuz-3.10.0-229.4.2.el7.x86_64
To change a value in an existing kernel argument, specify the argument again, changing the
value as required. For example, to change the virtual console font size, use a command as
follows:
# grubby --args=vconsole.font=latarcyrheb-sun32 --update-kernel /boot/vmlinuz-3.10.0-
229.4.2.el7.x86_64
See the grubby(8) manual page for more command options.
30. Customizing the GRUB 2 Configuration File
GRUB 2 allows basic customization of the boot menu to give users control of what actually
appears on the screen.GRUB 2 uses a series of scripts to build the menu; these are located in
the /etc/grub.d/ directory:
header, which loads GRUB 2 settings from the /etc/default/grub file.
users, which reads the superuser password from the user.cfg file. In Red Hat Enterprise Linux
7.0 and 7.1, this file was only created when boot password was defined in the kickstart file
during installation, and it included the defined password in plain text.
linux, which locates kernels in the default partition of Red Hat Enterprise Linux.
os-prober, which builds entries for operating systems found on other partitions.
custom, a template, which can be used to create additional menu entries.
31. Protecting GRUB 2 with a Password
GRUB 2 offers two types of password protection:
●
Password is required for modifying menu entries but not for booting existing menu entries;
●
Password is required for modifying menu entries and for booting one, several, or all menu
entries.
1.To require password authentication for modifying GRUB 2 entries:
# grub2-setpassword
Following this procedure creates a /boot/grub2/user.cfg file that contains the hash of the
password. The user for this password, root, is defined in the /boot/grub2/grub.cfg file. With
this change, modifying a boot entry during booting requires you to specify the root user name
and your password.
32. Protecting GRUB 2 with a Password
Setting a password using the grub2-setpassword prevents menu entries from unauthorized
modification but not from unauthorized booting. To also require password for booting an entry,
follow these steps after setting the password with grub2-setpassword:
1. Open the /boot/grub2/grub.cfg file.
2. Find the boot entry that you want to protect with password by searching for lines beginning
with menuentry.
3. Delete the --unrestricted parameter from the menu entry block.
N
●
Note:
If you delete the --unrestricted parameter from every menu entry in the /boot/grub2/grub.cfg
file, all newly installed kernels will have menu entry created without --unrestricted and hence
automatically inherit the password protection.
33. Reinstalling GRUB 2
Reinstalling GRUB 2 is a convenient way to fix certain problems usually caused by an incorrect
installation of GRUB 2, missing files, or a broken system. Other reasons to reinstall GRUB 2
include the following:
●
Upgrading from the previous version of GRUB.
●
The user requires the GRUB 2 boot loader to control installed operating systems. However,
some operating systems are installed with their own boot loaders. Reinstalling GRUB 2
returns control to the desired operating system.
●
Adding the boot information to another drive.
Use the grub2-install device command to reinstall GRUB 2 if the system is operating normally.
# grub2-install /dev/sda
34. Terminal Menu Editing During Boot
Menu entries can be modified and arguments passed to the kernel on boot. This is done using
the menu entry editor interface:
●
Booting to Rescue Mode
●
Booting to Emergency Mode
●
Booting to the Debug Shell
Booting to Rescue Mode:Rescue mode provides a convenient single-user environment and
allows you to repair your system in situations when it is unable to complete a normal booting
process. In rescue mode, the system attempts to mount all local file systems and start some
important system services, but it does not activate network interfaces or allow more users to be
logged into the system at the same time. In Red Hat Enterprise Linux 7, rescue mode is
equivalent to single user mode and requires the root password.
35. Terminal Menu Editing During Boot
Booting to Emergency Mode:Emergency mode provides the most minimal environment
possible and allows you to repair your system even in situations when the system is unable to
enter rescue mode. In emergency mode, the system mounts the root file system only for
reading, does not attempt to mount any other local file systems, does not activate network
interfaces, and only starts few essential services. In Red Hat Enterprise Linux 7, emergency
mode requires the root password.
Booting to the Debug Shell:The systemd debug shell provides a shell very early in the startup
process that can be used to diagnose systemd related boot-up problems. Once in the debug
shell, systemctl commands such as systemctl list-jobs, and systemctl list-units can be
used to look for the cause of boot problems. In addition, the debug option can be added to the
kernel command line to increase the number of log messages. For systemd, the kernel
command-line option debug is now a shortcut for systemd.log_level=debug.
37. Overview of Kernel Packages(1)
Linux contains the following kernel packages:
Kernel: Contains the kernel for single-core, multi-core, and multi-processor systems.
Kernel-debug: Contains a kernel with numerous debugging options enabled for kernel
diagnosis, at the expense of reduced performance.
Kernel-devel: Contains the kernel headers and makefiles sufficient to build modules
against the kernel package.
Kernel-debug-devel: Contains the development version of the kernel with numerous
debugging options enabled for kernel diagnosis, at the expense of reduced performance.
Kernel-doc: Documentation files from the kernel source. Various portions of the Linux
kernel and the device drivers shipped with it are documented in these files. Installation of
this package provides a reference to the options that can be passed to Linux kernel
modules at load time.
38. Overview of Kernel Packages(2)
Kernel-headers: Includes the C header files that specify the interface between the Linux
kernel and user-space libraries and programs. The header files define structures and
constants that are needed for building most standard programs.
Linux-firmware: Contains all of the firmware files that are required by various devices to
operate.
Perf: This package contains the perf tool, which enables performance monitoring of the
Linux kernel.
Kernel-abi-whitelists: Contains information pertaining to the Red Hat Enterprise Linux
kernel ABI, including a lists of kernel symbols that are needed by external Linux kernel
modules and a yum plug-in to aid enforcement.
Kernel-tools: Contains tools for manipulating the Linux kernel and supporting
documentation.
$ rpm -qa | grep kernel-*
$ rpm -qf `which pref`
39. Verifying the Initial RAM Disk Image
The job of the initial RAM disk image: is to preload the block device modules, such as for
IDE, SCSI orRAID, so that the root file system, on which those modules normally reside,
can then be accessed and mounted.
$ ls -li /dev | less
On Red Hat Enterprise Linux 7 systems, whenever a new kernel is installed using either
the Yum, PackageKit, or RPM package manager, the Dracut utility is always called by the
installation scripts to create an initramfs (initial RAM disk image).
$ man dracut
If you make changes to the kernel attributes by modifying the /etc/sysctl.conf file or
another sysctl configuration file, and if the changed settings are used early in the boot
process, then rebuilding the Initial RAM Disk Image by running the dracut -f command
might be necessary. An example is if you have made changes related to networking and
are booting from network-attached storage.
$ ls -li /boot
Important :in the /boot directory you might find several initramfs-
kernel_versionkdump.img files. These are special files created by the Kdump
mechanism for kernel debugging purposes, are not used to boot the system, and can safely
be ignored.
41. dynamically-loaded kernel modules
Linux kernel is modular, which means it can extend its capabilities through the use of
dynamically-loaded kernel modules. A kernel module can provide:
●
a device driver which adds support for new hardware; or,
●
support for a file system such as btrfs or NFS.
Like the kernel itself, modules can take parameters that customize their behavior, though
the default parameters work well in most cases.
“kmod” provides:
●
list the modules currently loaded into a running kernel
●
query all available modules for available parameters and module-specific information;
●
load or unload (remove) modules dynamically into or from a running kernel.
# yum install kmod
# rpm -qi kmod
42. Listing Currently-Loaded Modules
You can list all kernel modules that are currently loaded into the kernel by running the
lsmod command :
$ lsmod | less
$ man lsmod
Each row of lsmod output specifies:
●
the name of a kernel module currently loaded in memory
●
the amount of memory it uses
●
the sum total of processes that are using the module and other modules which depend
on it,followed by a list of the names of those modules, if there are any.
note that lsmod output is less verbose and considerably easier to read than the content of
the /proc/modules pseudo-file.
$ lsmod | grep nfs
43. Displaying Information About a Module
You can display detailed information about a kernel module using the modinfo
module_name command
$ modinfo vmnet | less
Note:When entering the name of a kernel module as an argument to one of the kmod
utilities, do not append a .ko extension to the end of the name. Kernel module names do
not have extensions; their corresponding files do
$ man modinfo
# systemctl start firewalld
# lsmod | grep iptable_nat
44. Loading a Module
To load a kernel module, run modprobe module_name as root.
$ man modprobe
By default, modprobe attempts to load the module from
/lib/modules/kernel_version/kernel/drivers/. In this directory, each type of module has
its own subdirectory, such as net/ and scsi/, for network and SCSI interface drivers
respectively.
You can use the -v (or --verbose) option to cause modprobe to display detailed information
about what it is doing, which can include loading module dependencies.
Important: Although the insmod command can also be used to load kernel modules, it does
not resolve dependencies. Because of this, you should always load modules using
modprobe instead
45. Unloading a Module
You can unload a kernel module by running modprobe -r module_name as root.
command will fail if a process is using:
●
Module
●
A module that directly depends
●
any module that through the dependency tree, depends on indirectly
modprobe -r -v
Although the rmmod command can be used to unload kernel modules, it is recommended
to use modprobe -r instead.
$ ls -R /lib/modules/`uname -r`/kernel/