Linux Kernel:
Single kernel system design, but fully learn the advantages of micro-core design system for the kernel to introduce a modular mechanism.
Kernel components:
Kernel: Kernel core, generally bzimage, usually in the/boot directory, the name is vmlinuz-version-release;
Kernel object: Kernel objects, typically placed in/lib/modules/version-release/
[]: N
[m]: M
[*]: Y
Auxiliary files: RAMDisk
Initrd
Initramfs
In-run kernel:
uname command:
Uname-print System Information
uname [OPTION] ...
-N: Displays the node name;
-R: Display version-release;
Module:
Lsmod command:
Displays kernel modules already loaded by the core
The content displayed is from:/proc/modules file
Modinfo command:
Display detailed description of the module
Modinfo [-K kernel] [modulename|filename ...]
-N: Show only module file path
-P: Display module parameters
-a:author
-d:description
-l:license
[Email protected] ~]# Modinfo EXT4
FileName:/lib/modules/2.6.32-504.el6.x86_64/kernel/fs/ext4/ext4.ko
License:gpl
Description:fourth Extended Filesystem
Author:remy Card, Stephen Tweedie, Andrew Morton, Andreas dilger, Theodore Ts ' O and others
Srcversion:2da002aac5b453054c69fb2
Depends:mbcache,jbd2
vermagic:2.6.32-504.el6.x86_64 SMP mod_unload modversions
[[email protected] ~]# Modinfo Ip
ERROR:modinfo:could not find module Ip
[Email protected] ~]# modinfo STP
FileName:/lib/modules/2.6.32-504.el6.x86_64/kernel/net/802/stp.ko
License:gpl
srcversion:ade6c8a333621c77acac02c
Depends:llc
vermagic:2.6.32-504.el6.x86_64 SMP mod_unload modversions
modprobe command:
Loading or unloading kernel modules
modprobe [-C Config-file] [modulename] [module parame-ters ...]
Configuration files:/etc/modprobe.conf,/etc/modprobe.d/*.conf
modprobe [-r] ModuleName ...
[Email protected] ~]# modprobe XFS
[Email protected] ~]# Lsmod | grep XFS
XFS 1124960 0
Exportfs 4236 1 XFS
[Email protected] ~]# modprobe-r XFS
[Email protected] ~]# modinfo-n XFS
/lib/modules/2.6.32-504.el6.x86_64/kernel/fs/xfs/xfs.ko
Depmod command:
Kernel module dependency file and System Information mapping file generation tool;
To mount or unload a kernel module:
Insmod command:
insmod [filename] [module Options ...]
Rmmod
Rmmod [ModuleName]
/proc directory:
The kernel outputs its own internal state information and statistical information, as well as configurable parameters through the proc pseudo-file system.
[Email protected] ~]# Sysctl-a | Wc-l
736
[Email protected] ~]# Cat/proc/sys/kernel/hostname
Slave
Parameters:
Read-only: Output information
Writable: User-specified "new value" can be accepted for configuration of a function or feature of the kernel
/proc/sys
(1) The SYSCTL command is used to view or set many parameters in this directory;
Sysctl-w Path.to.parameter=value
[Email protected] ~]# sysctl-w kernel.hostname=www.magedu.com
Kernel.hostname = www.magedu.com
[Email protected] ~]# hostname
Www.magedu.com
[Email protected] ~]# sysctl-w Kernel.hostname=slave
Kernel.hostname = Slave
[Email protected] ~]# hostname
Slave
~]# sysctl-w kernel.hostname=mail.magedu.com
(2) The echo command can also modify the values of most parameters through redirection;
echo "VALUE" >/proc/sys/path/to/parameter
~]# echo "www.magedu.com" >/proc/sys/kernel/hostname
Sysctl command:
Default configuration file:/etc/sysctl.conf
Permanently valid
/etc/sysctl.conf
(1) Setting a parameter
Sysctl-w Parameter=value
(2) Setting parameters by reading the configuration file
Sysctl-p [/path/to/conf_file]
Route forwarding in the kernel:
/proc/sys/net/ipv4/ip_forward
[Email protected] ~]# Cat/proc/sys/net/ipv4/ip_forward
0
Make the kernel effective
Sysctl-p
Sysctl-w net.ipv4.ip_forward=1
A few common parameters:
Net.ipv4.ip_forward
Vm.drop_caches
Kernel.hostname
/sys directory:
SYSFS: The output kernel identifies the relevant property information of each hardware device, as well as the setting information of the kernel on the hardware characteristics; some parameters can be modified to adjust the hardware operating characteristics.
Udev dynamically creates the required device files for each device through the information output under this path; Udev is a user-space program; special tools: Udevadmin, HotPlug;
When Udev creates a device file for a device, it reads its pre-defined rule file, typically in the/ETC/UDEV/RULES.D and/USR/LIB/UDEV/RULES.D directories;
RAMDisk File creation:
(1) MKINITRD command
Re-authoring the RAMDisk file for the kernel that is currently in use
Mv/boot/initramfs-2.6.32-504.el6.x86_64.img/root
~] # mkinitrd/boot/initramfs-$ (UNAME-R). IMG $ (UNAME-R)
Look what it is.
[Email protected] ~]# file initramfs-2.6.32-504.el6.x86_64.img
Initramfs-2.6.32-504.el6.x86_64.img:gzip compressed data, from Unix, last Modified:tue Jan 14:53:45, Max Compres Sion
[Email protected] ~]# MV Initramfs-2.6.32-504.el6.x86_64.img initramfs-2.6.32-504.el6.x86_64.img.gz
Unzip
[Email protected] ~]# gzip-d initramfs-2.6.32-504.el6.x86_64.img.gz
[[Email protected] ~]# file initramfs-2.6.32-504.el6.x86_64.img
Initramfs-2.6.32-504.el6.x86_64.img:ascii Cpio Archive (SVR4 with no CRC)
(2) Dracut command
Re-authoring the RAMDisk file for the kernel that is currently in use
~] # dracut/boot/initramfs-$ (UNAME-R). IMG $ (UNAME-R)
Compile kernel:
Premise:
(1) Prepare the development environment;
(2) Obtain information about hardware devices on the target host;
(3) Obtain information about the function of the target host system, such as the file system to be enabled;
(4) Obtain the kernel source code package;
www.kernel.org
Prepare the development environment:
Package Group (CentOS 6):
Server Platform Development
Development Tools
Target host hardware Device related information:
Cpu:
~]# Cat/proc/cpuinfo
~]# X86info-a
~]# LSCPU
PCI Device:
~]# Lspci
-V
-vv
~]# Lsusb
-V
-vv
~]# lsblk
See all Hardware Device information
~]# Hal-device
Simple basis for template file making process:
~]# Tar XF linux-3.10.67.tar.xz-c/usr/src
~]# CD/USR/SRC
~]# LN-SV linux-3.10.67 Linux
~]# CD Linux
~]# cp/boot/config-$ (uname-r)./.config
~]# make Menuconfig
~]# screen
~]# Make-j #
Make-j 4 #4表示开4个线程编译
~]# make Modules_install
~]# make Install
Reboot the system and test the use of the new kernel;
This article is from the "Liang blog" blog, make sure to keep this source http://7038006.blog.51cto.com/7028006/1839376
Linux Kernel Introduction and compilation