Linux kernel detailed

Source: Internet
Author: User


Kernel design style:

Single Core: Linux

Microkernel: Windows,solaris true Support thread

Redhat,suse

Core: Dynamic load kernel module

Kernel:/lib/modules/"kernel version number command directory"/


How user space accesses and monitors the kernel:/proc,/sys pseudo file system

/proc/sys: Many of the files in the secondary directory are readable and writable

/sys/: Some files can be written

How to set kernel parameter values:

Echo VALUE >/proc/sys/xx

or Stsctl-w Kernar. xx= "XX"

Both of these methods can make the setting effective immediately, but not permanently

Permanently valid: Modify/etc/sysctl.conf

After the modification is complete, execute the SYSCTL-P


Sysctl-a: Displays all kernel parameters and their values


Kernel module Management

LSMOD: List kernel modules

Modprobe mod_name: Loading a module

Modprobe-r mod_name: Uninstalling a module

Modinfo mod_name: View specific information about the module

Insmod: Load Module

Remod Mod_name

Depom:


In addition to core functionality, the kernel has three choices for most functions at compile time:

1, do not use sub-function

2. Compile into kernel module

3. Compile into kernel


How to manually compile the kernel

Make Gconfig:gnome Desktop environment use

Make KCONFIG:KDE desktop environment, need to install graphics development Library

Make Menuconfig: Need to execute in kernel directory

Note: Use make menuconfig to install ncurses

Yum Groupinstall "Development Tools" "Development Libraries"


Menuconfig Compiling kernel steps

Cd/usr/src

Mv/root/linux-3.16.2.tar.xz./

xz-d Linux-3.16.2.tar.xz #解压

Tar xvf Linux-3.16.2.tar #展开

Ln-s linux-3.16.2 Linux #链接

CD Linux

Make Menuconfig

Make

Make Modules_install

Make install


Two compile-time cleanup: It is best to back up the. config file before cleaning up

Make clean

Make Mrproper


Grub-->kernel-->initrd-->rootfs (/sbin/init,/bin/bash)


MKINITRD initrd file path kernel version number

mkinitrd/boot/initrd-' uname-r '. img ' uname-r '


Virtual Machine Implementation compilation system

Add a piece of hard disk, partition it, format it

Mkdir-p/mnt/{boot,sysroot}

mount/dev/sdb1/mnt/boot/

mount/dev/sdb2/mnt/sysroot/

Grub-install--root-directory=/mnt/dev/sdb #装载Grub

[Email protected] ~]# ls/mnt/boot/#grub已经存在

Grub Lost+found

Cp/boot/vmlinuz-2.6.32-220.el6.x86_64/mnt/boot/vmlinuz #复制内核

#创建initrd

mkdir ISO

CD ISO

Zcat/boot/initramfs-2.6.32-220.el6.x86_64.img |cpio-id

VIM Init #修改init的如下行

Mkrootdev-t Ext3-o DEFAULTS,RO/DEV/SDB2

Find. |cpio-h newc--quiet-o |gzip-9 >/mnt/boot/initrd.gz

Vim/mnt/boot/grub/grub.conf

Default=0

Timeout=5

Title My Linux

Root (hd0,0)

Kernel/vmlinux

Initrd/initrd.gz

cd/mnt/sysroot/

MKDIR-PV proc Sys Dev etc/rc.d lib bin sbin boot home var/log usr/{bin,sbin} root tmp

#需要拷贝的两类 1./sbin/* 2./bin/*

cp/sbin/init/mnt/sysroot/sbin/

cp/bin/bash/mnt/sysroot/bin/

Ldd/sbin/init #查看init的依赖库

cp/lib/libsepol.so.1/mnt/sysroot/lib/

cp/lib/libselinux.so.1/mnt/sysroot/lib/

cp/lib/libc.so.6/mnt/sysroot/lib/

cp/lib/libdl.so.2/mnt/sysroot/lib/

Ldd/bin/bash #查看bash的依赖库

cp/lib/libtermcap.so.2/mnt/sysroot/lib/

cp/lib/ld-linux.so.2/mnt/sysroot/lib/

chroot/mnt/sysroot/#测试能否使用, exit

Sync #同步磁盘

Vim/mnt/sysroot/etc/inittab #只需2行, default level and system initialization

Id:3:initdefault:

Si::sysinit:/etc/rc.d/rc.sysinit

Vim/mnt/sysroot/etc/rc.d/rc.sysinit

#!/bin/bash

Echo-e "\twelcome to \033[31mmylinux\033[0m"

/bin/bash

chmod +x/mnt/sysroot/etc/rc.d/rc.sysinit


#需要拷贝的两类 1./sbin/* 2./bin/* Script

dest=/mnt/sysroot/


LIBCP () {

libpath=${1%/*}

[!-D $dest $libpath] && mkdir-p $dest $libpath

[!-e $dest ${1}] && cp $dest $libpath && echo "Copy Lib $ finished."

}


BINCP () {

binpath=${1%/*}

[!-D $dest $binpath] && mkdir-p $dest $binpath

[!-e $dest ${1}] && cp $dest $binpath


For Lib in ' LDd $ | Grep-o "/.*lib\ (64\) \{0,1\}/[^[:space:]]\{1,\}"; Do

LIBCP $lib

Done

}


Read-p "Your command:" cmd

until [$cmd = = ' Q ']; Do

! Which $cmd && echo "wrong command" && read-p "input again:" CMD && continue

Command= ' which $cmd |grep-v "^alias" | Grep-o "[^[:space:]]\{1,\}" '

BINCP $command

echo "Copy $command finished"

Read-p "continue:" cmd

Done


Mount-n do not update/etc/mtab files when mounted

Cat/proc/mounts also has all the file systems mounted


#让这个小系统实现开机, shut down the machine

Cd/mnt/sysroot

Vim Etc/rc.d/init.d/halt

#!/bin/bash

Case $ in

*reboot) command= '/sbin/reboot ';;

*halt) command= '/sbin/halt-p ';;

*) echo "Only call this script by *reboot OR *halt";;

Esac


Case $ in

Start

;;

Stop

;;

Status

;;

*)

echo "Usage: ' basename $ ' {start|stop|status}"

;;

Esac


EXEC $command

CD ETC/RC.D

mkdir RC0.D RC6.D

CD RC0.D

Ln-sv. /init.d/halt S99halt

CD rc6.d/

Ln-sv. /init.d/halt S99reboot

Cd.. /


Vim RC

#!/bin/bash

Run=$1

For I in/etc/rc.d/rc${run}.d/k*; Do

$i Stop

Done


For I in/etc/rc.d/rc${run}.d/s*; Do

$i Start

Done


Vim Etc/inittab

L0:0:WAIT:/ETC/RC.D/RC 0

L6:6:WAIT:/ETC/RC.D/RC 6

This article is from the "ngames" blog, make sure to keep this source http://ngames.blog.51cto.com/3187187/1555246

Linux kernel detailed

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.