SlideShare ist ein Scribd-Unternehmen logo
1 von 46
Downloaden Sie, um offline zu lesen
1
Kernel, Module and DriverKernel, Module and Driver
ConfigurationConfiguration
AUT LinuxFest 2017AUT LinuxFest 2017
Mahmoud Shiri VaraminiMahmoud Shiri Varamini
shirivaramini@gmail.comshirivaramini@gmail.com
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
3
Introduction to Linux kernelIntroduction to Linux kernel
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
What Dose Kernel?
●
is responsible for memory management, process and task management, and disk
management.
●
connects the system hardware to the application software
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
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
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
9
Compiling Linux kernelCompiling Linux kernel
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.
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.
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.
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.
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.
Let’s Do It!!!
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
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.
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 !!
19
Working with the GRUB 2 BootWorking with the GRUB 2 Boot
LoaderLoader
Boot Process at Glance
System Startup
Runlevel
$ man runlevel
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.
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.
Introduction to GRUB 2 (3)
A sample of GRUB2 bootloader screen!
Introduction to GRUB 2 (3)
less /boot/grub2/grub.cfg
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:
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
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.
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.
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.
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.
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
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.
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.
36
Manually Upgrading the KernelManually Upgrading the Kernel
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.
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`
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.
40
Working with Kernel ModulesWorking with Kernel Modules
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
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
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
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
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/
46
QuestionQuestion

Weitere ähnliche Inhalte

Was ist angesagt?

Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)RuggedBoardGroup
 
linux device driver
linux device driverlinux device driver
linux device driverRahul Batra
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoCMacpaul Lin
 
Linux presentation
Linux presentationLinux presentation
Linux presentationNikhil Jain
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device driversHoucheng Lin
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New HardwareRuggedBoardGroup
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequenceHoucheng Lin
 
Kernel module programming
Kernel module programmingKernel module programming
Kernel module programmingVandana Salve
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/CoreShay Cohen
 
Linux Administration
Linux AdministrationLinux Administration
Linux AdministrationHarish1983
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device DriversNEEVEE Technologies
 
Lesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File SystemLesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File SystemSadia Bashir
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)shimosawa
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal BootloaderSatpal Parmar
 

Was ist angesagt? (20)

Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)
 
linux device driver
linux device driverlinux device driver
linux device driver
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
 
Linux presentation
Linux presentationLinux presentation
Linux presentation
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device drivers
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequence
 
Kernel module in linux os.
Kernel module in linux os.Kernel module in linux os.
Kernel module in linux os.
 
Kernel module programming
Kernel module programmingKernel module programming
Kernel module programming
 
Basic Linux Internals
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Linux file system
Linux file systemLinux file system
Linux file system
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
 
Linux Administration
Linux AdministrationLinux Administration
Linux Administration
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device Drivers
 
Linux Kernel Overview
Linux Kernel OverviewLinux Kernel Overview
Linux Kernel Overview
 
Lesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File SystemLesson 2 Understanding Linux File System
Lesson 2 Understanding Linux File System
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
U Boot or Universal Bootloader
U Boot or Universal BootloaderU Boot or Universal Bootloader
U Boot or Universal Bootloader
 

Ähnlich wie Linux kernel

Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606Eunice Lin
 
linux minimal os tutorial - by shatrix
linux minimal os tutorial - by shatrixlinux minimal os tutorial - by shatrix
linux minimal os tutorial - by shatrixSherif Mousa
 
Building Mini Embedded Linux System for X86 Arch
Building Mini Embedded Linux System for X86 ArchBuilding Mini Embedded Linux System for X86 Arch
Building Mini Embedded Linux System for X86 ArchSherif Mousa
 
Building a linux kernel
Building a linux kernelBuilding a linux kernel
Building a linux kernelRaghu nath
 
7-compiling the Linux kerne pdf type is it
7-compiling the Linux kerne pdf type is it7-compiling the Linux kerne pdf type is it
7-compiling the Linux kerne pdf type is itBehzad Soltaniyan Hemat
 
Part 01 Linux Kernel Compilation (Ubuntu)
Part 01 Linux Kernel Compilation (Ubuntu)Part 01 Linux Kernel Compilation (Ubuntu)
Part 01 Linux Kernel Compilation (Ubuntu)Tushar B Kute
 
Crafting GNU/Linux distributions for Embedded target from Scratch/Source
Crafting GNU/Linux distributions for Embedded target from Scratch/SourceCrafting GNU/Linux distributions for Embedded target from Scratch/Source
Crafting GNU/Linux distributions for Embedded target from Scratch/SourceSourabh Singh Tomar
 
Grub and dracut ii
Grub and dracut iiGrub and dracut ii
Grub and dracut iiplarsen67
 
Linux booting process - Linux System Administration
Linux booting process - Linux System AdministrationLinux booting process - Linux System Administration
Linux booting process - Linux System AdministrationSreenatha Reddy K R
 
6 stages of linux boot process
6 stages of linux boot process6 stages of linux boot process
6 stages of linux boot processHari Shankar
 
Crafting GNU/ linux distributions for embedded target using Builroot
Crafting GNU/ linux distributions for embedded target using BuilrootCrafting GNU/ linux distributions for embedded target using Builroot
Crafting GNU/ linux distributions for embedded target using BuilrootSourabh Singh Tomar
 
Grub2 and troubleshooting_ol7_boot_problems
Grub2 and troubleshooting_ol7_boot_problemsGrub2 and troubleshooting_ol7_boot_problems
Grub2 and troubleshooting_ol7_boot_problemsTommy Lee
 
Lecture 5 Kernel Development
Lecture 5 Kernel DevelopmentLecture 5 Kernel Development
Lecture 5 Kernel DevelopmentMohammed Farrag
 

Ähnlich wie Linux kernel (20)

101 1.2 boot the system
101 1.2 boot the system101 1.2 boot the system
101 1.2 boot the system
 
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606
Ubuntu初體驗:脫離邪惡微軟帝國吧!_150606
 
linux minimal os tutorial - by shatrix
linux minimal os tutorial - by shatrixlinux minimal os tutorial - by shatrix
linux minimal os tutorial - by shatrix
 
RPM (LINUX)
RPM (LINUX)RPM (LINUX)
RPM (LINUX)
 
Building Mini Embedded Linux System for X86 Arch
Building Mini Embedded Linux System for X86 ArchBuilding Mini Embedded Linux System for X86 Arch
Building Mini Embedded Linux System for X86 Arch
 
Building a linux kernel
Building a linux kernelBuilding a linux kernel
Building a linux kernel
 
7-compiling the Linux kerne pdf type is it
7-compiling the Linux kerne pdf type is it7-compiling the Linux kerne pdf type is it
7-compiling the Linux kerne pdf type is it
 
Linux basics
Linux basics Linux basics
Linux basics
 
Part 01 Linux Kernel Compilation (Ubuntu)
Part 01 Linux Kernel Compilation (Ubuntu)Part 01 Linux Kernel Compilation (Ubuntu)
Part 01 Linux Kernel Compilation (Ubuntu)
 
Linux basics
Linux basics Linux basics
Linux basics
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
 
Crafting GNU/Linux distributions for Embedded target from Scratch/Source
Crafting GNU/Linux distributions for Embedded target from Scratch/SourceCrafting GNU/Linux distributions for Embedded target from Scratch/Source
Crafting GNU/Linux distributions for Embedded target from Scratch/Source
 
Grub and dracut ii
Grub and dracut iiGrub and dracut ii
Grub and dracut ii
 
Linux Booting Process
Linux Booting ProcessLinux Booting Process
Linux Booting Process
 
Linux booting process - Linux System Administration
Linux booting process - Linux System AdministrationLinux booting process - Linux System Administration
Linux booting process - Linux System Administration
 
6 stages of linux boot process
6 stages of linux boot process6 stages of linux boot process
6 stages of linux boot process
 
Crafting GNU/ linux distributions for embedded target using Builroot
Crafting GNU/ linux distributions for embedded target using BuilrootCrafting GNU/ linux distributions for embedded target using Builroot
Crafting GNU/ linux distributions for embedded target using Builroot
 
Beagleboard xm-setup
Beagleboard xm-setupBeagleboard xm-setup
Beagleboard xm-setup
 
Grub2 and troubleshooting_ol7_boot_problems
Grub2 and troubleshooting_ol7_boot_problemsGrub2 and troubleshooting_ol7_boot_problems
Grub2 and troubleshooting_ol7_boot_problems
 
Lecture 5 Kernel Development
Lecture 5 Kernel DevelopmentLecture 5 Kernel Development
Lecture 5 Kernel Development
 

Kürzlich hochgeladen

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 

Kürzlich hochgeladen (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
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
  • 3. 3 Introduction to Linux kernelIntroduction to Linux kernel
  • 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 !!
  • 19. 19 Working with the GRUB 2 BootWorking with the GRUB 2 Boot LoaderLoader
  • 20. Boot Process at Glance
  • 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.
  • 25. Introduction to GRUB 2 (3) A sample of GRUB2 bootloader screen!
  • 26. Introduction to GRUB 2 (3) less /boot/grub2/grub.cfg
  • 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.
  • 36. 36 Manually Upgrading the KernelManually Upgrading the Kernel
  • 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.
  • 40. 40 Working with Kernel ModulesWorking with Kernel Modules
  • 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/