Linux Kernel service learning notes

Source: Internet
Author: User

(I) kernel Introduction
Responsibilities:
① System initialization: Check hardware resources and guide the system
② Process scheduling: determines the process startup and running time
③ Memory management: allocate memory for Running Processes
④ Security: Checks system permissions, SELinux, and iptables policies.
⑤ Provide Cache
Version:
① General: one or more processors, But Ram can only be 4g or less than 4G
② PAE: multi-processor, and supports up to 64 GB RAM
③ Xen: Required for Virtualization
The kernel is always installed in/boot/vmlinuz -*
The kernel source code can be downloaded from www.kernel.org.



(Ii) kernel module
Reasons for using the module:
① Reduce memory usage: Unnecessary drivers do not occupy memory
② Flexibility: modules can be added after system installation. These modules are generally called third-party drivers.
③ Maximum running time: the module can be loaded and unloaded without being restarted.
The dynamic modules required during boot can be loaded into initrd (initialize the memory disk) With grub. Other modules can be loaded as needed later.
These modules are located in the/lib/modules/$ (uname-R)/directory.

Kernel module tools:
-- Modprobe: the module can be loaded or detached.
Load: [root @ think ~] # Modprobe usb_storage
Uninstall: [root @ think ~] # Modprobe-r usb_storage
The module can be deleted only when it is not used.

-- Lsmod: lists the list of all mounted modules, corresponding sizes, and usage.

[root@Think ~]# lsmodModule                  Size  Used bynetloop                10817  0 [permanent]netbk                  80065  0 [permanent]blktap                120485  2 [permanent]blkbk                  24289  0 [permanent]ip6table_filter         6849  0 ip6_tables             18181  1 ip6table_filteript_MASQUERADE          7617  3 iptable_nat            10949  1 

-- Modinfo: displays information about any available modules.

[root@Think ~]# modinfo ext3filename:       /lib/modules/2.6.18-308.el5xen/kernel/fs/ext3/ext3.kolicense:        GPLdescription:    Second Extended Filesystem with journaling extensionsauthor:         Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and otherssrcversion:     26DC008FC415305C5F65313depends:        jbdvermagic:       2.6.18-308.el5xen SMP mod_unload 686 REGPARM 4KSTACKS gcc-4.1module_sig:     883f3504f232fc6dc995cc0b59af121112e44a0a0b5f8ae8f7e90b5a613c37cfc50808c464f9a6d0a0a86a45e9d5fe9b7f9f4ed65957f3ce291b12fd

--/Etc/modprobe. conf: the configuration file contains common module configurations for loading in the system. You can add them separately if necessary.

[root@Think ~]# cat /etc/modprobe.confalias eth0 vmxnetalias scsi_hostadapter mptbasealias scsi_hostadapter1 mptspialias scsi_hostadapter2 ata_piixalias snd-card-0 snd-ens1371options snd-card-0 index=0options snd-ens1371 index=0remove snd-ens1371 { /usr/sbin/alsactl store 0 >/dev/null 2>&1 || : ; }; /sbin/modprobe -r --ignore-remove snd-ens1371

(Iii) Manage initrd Image
Initrd provides modules to be loaded at the initial boot stage
These modules are usually related to storage devices and file systems, but they also support other features and hardware peripherals.
The file is located in/boot/initrd-$ (uname-R). img
Sometimes an additional module is added for some reason:
Mkinitrd -- with = module_name/boot/initrd-$ (uname-R). IMG $ (uname-R)

(Iv) access the driver through/dev
Files in the/dev directory can be used to access the driver.
We can read or write data from these files:
For example:
Read: CAT/dev/ttys0
Write: Echo "message">/dev/ttys0
These files can be divided into two types:
① Block devices: process data storage and use buffering
For example:
/Dev/hda: IDE Hard Disk
/Dev/SDA: SATA hard drive

② Character device: Applicable to data streams and not to buffer
The most common character device is a terminal.

[root@Think ~]# who am iroot     pts/2        2012-12-31 20:42 (:0.0)

/Dev/tty [0-6]: virtual console
/Dev/null
/Dev/random

[root@Think boot]# ll /dev/nullcrw-rw-rw- 1 root root 1, 3 12-31 14:03 /dev/null

"C" indicates a character device.
"B" indicates Block devices.
1, 3: indicates that the primary number is 1, and the secondary number is 3
The main number determines which driver to access
Secondary numbers allow drivers to recognize different physical devices

 

(V) Use udev to manage/dev
Linux has a Culture: A device is a file.
Udev can manage files stored in the/dev/directory.
Udev can generate and delete files at any time when inserting or pulling out the corresponding device.
The system administrator is also allowed to add rules to modify the default name and permissions in/dev. The rules are in the/etc/udev/rules. d/directory.


(6) add files to/dev
Permanent:
① Create a new file in/etc/udev/rules. d/
② Insert the following description:
Kernel = "SDA", name = "USBkey", symlink = "usbstorage"
This will generate a device file named USB key and a symbolic link named USB storage when/dev/SDA is inserted next time.
Temporary:
Mknod/dev/usbdevice B 8 0


(Vii) Use/proc for Kernel configuration
/Proc is a Virtual File System (the file is not saved to the hard disk, and the modification will be reinitialized after the reboot)
Displays process information, memory resources, and hardware devices.
Use the strings command for better browsing
Some interesting/proc entries
Read-only:
/Proc/<pid>: information about the running process
/Proc/cpuinfo: processor Information
/Proc/meminfo: main memory usage
/Proc/SWAPs: used for swap partitions
/Proc/modules: Dynamically Loaded Module
/Proc/mounts: mounted file system
/Proc/NET: network activity and Configuration
/Proc/version: kernel version
Read/write:
/Proc/sys/kernel/hostname
/Proc/sys/NET/IPv4/ip_forward: IP Forwarding (ON or OFF)
/Proc/sys/Vm/drop_caches: forces the kernel to release some memory from the cache
/Proc/sys/Vm/swappiness: displays the positive degree of memory conversion to the conversion device


Sysctl: browse and set Kernel Parameters
Show all parameters and their values
Sysctl-
Temporary settings:
Sysctl-W net. ipv4.tcp _ syncookies = 1
Permanent settings:
/Etc/sysctl. conf add Parameters
After the operation is completed:
Sysctl-P
Allows you to synchronize the new configuration file with the kernel.


Prepare some exercises
① Close Ping

[Root @ think ~] # Cat/proc/sys/NET/IPv4/icmp_echo_ignore_all 0 [root @ think ~] # Echo 1>/proc/sys/NET/IPv4/icmp_echo_ignore_all [root @ think ~] # Cat/proc/sys/NET/IPv4/icmp_echo_ignore_all 1 [root @ think ~] # Ping 192.168.1.20.ping 192.168.1.107 (192.168.1.107) 56 (84) bytes of data.64 bytes from 192.168.1.107: icmp_seq = 1 TTL = 128 time = 0.674 ms64 bytes from 192.168.1.107: icmp_seq = 2 TTL = 128 time = 0.598 ms64 bytes from 192.168.1.107: icmp_seq = 3 TTL = 128 time = 0.659 Ms --- 192.168.1.107 Ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2001 msrtt min/AVG/max/mdev = 0.598/0.643/0.674/0. 044 MS but: C: \ Users \ Asus> Ping 192.168.1.115 is pinging 192.168.1.115 with 32 bytes of data: Request timeout. Request timeout. Request timeout. Request timeout. Ping statistics for 192.168.1.115: Packet: Sent = 4, received = 0, lost = 4 (100% lost). Changes to the/proc Virtual File System are temporary, if you want to be permanent, refer to the above

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.