Linux系统启动流程之kernel
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux系统启动流程之kernel相关的知识,希望对你有一定的参考价值。
Linux系统启动流程之kernel
1、内核参数修改方法:
2、内核内核模块管理:
3、内核编译
用户空间访问、监控内核的方式:/proc, /sys
伪文件系统
/proc/sys: 此目录中的文件很多是可读写的
/sys/: 某些文件可写
1、内核参数修改方法:
echo VALUE > /proc/sys/TO/SOMEFILE
sysctl -w kernel.hostname=
[[email protected] vm]# free -m
total used free shared buffers cached
Mem: 7983 541 7442 0 149 269
-/+ buffers/cache: 123 7860
Swap: 4094 0 4094
[[email protected] vm]# echo 1 > /proc/sys/vm/drop_caches
[[email protected] vm]# free -m
total used free shared buffers cached
Mem: 7983 125 7857 0 0 9
-/+ buffers/cache: 115 7867
Swap: 4094 0 4094
[[email protected] kernel]# sysctl -w vm.drop_caches=1
vm.drop_caches = 1
[[email protected] kernel]# free -m
total used free shared buffers cached
Mem: 7983 125 7857 0 0 9
-/+ buffers/cache: 115 7868
Swap: 4094 0 4094
[[email protected] kernel]# cat /proc/sys/kernel/hostname
localhost.localdomain
[[email protected] kernel]# echo wfx >/proc/sys/kernel/hostname
[[email protected] kernel]# hostname
wfx
[[email protected] kernel]# sysctl -w kernel.hostname="local.com"
kernel.hostname = local.com
[[email protected] kernel]# hostname
local.com
[[email protected] kernel]# cat /proc/sys/net/ipv4/ip_forward
0
[[email protected] kernel]# vim /etc/sysctl.conf #修改文件永久有效,但不能立即生效
# Kernel sysctl configuration file for Red Hat Linux
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
# Controls IP packet forwarding
net.ipv4.ip_forward = 1 # 0修改为1
...
[[email protected] kernel]# sysctl -p #立即生效
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
[[email protected] kernel]# cat /proc/sys/net/ipv4/ip_forward #验证
1
[[email protected] kernel]# sysctl -a |wc -l #显示所有内核参数及其值
635
2、内核内核模块管理:
lsmod: 查看
modprobe MOD_NAME:装载某模块
modprobe -r MOD_NAME: 卸载某模块
modinfo MOD_NAME: 查看模块的具体信息
insmod /PATH/TO/MODULE_FILE: 装载模块
rmmod MOD_NAME: 卸载某模块
depmod /PATH/TO/MODILES_DIR 安装驱动时内核模块必须同一版本
[[email protected] kernel]# lsmod |grep floppy
floppy 95465 0
[[email protected] kernel]# modprobe -r floppy #删除模块floppy
[[email protected] kernel]# lsmod |grep floppy
[[email protected] kernel]# modprobe floppy #加载模块floppy
[[email protected] kernel]# lsmod |grep floppy
floppy 95465 0
[[email protected] kernel]# modinfo floppy
filename:/lib/modules/2.6.18-164.el5/kernel/drivers/block/floppy.ko #文件路径
alias: block-major-2-*
license:GPL #许可证
author: Alain L. Knaff
srcversion:F532F52860888E835BB857C
depends: #无依赖模块
vermagic:2.6.18-164.el5 SMP mod_unload gcc-4.1
parm: floppy:charp
parm: FLOPPY_IRQ:int
parm: FLOPPY_DMA:int
module_sig:883f3504a8b7cf4bd273d74512bb1123df09e372bd75c92d020dd4b4fc61c617dd1534e826ec209f4bf9199f6f44b9471d2683a52c2b99aead71e
[[email protected] kernel]# modprobe -r floppy #删除模块floppy
[[email protected] kernel]# insmod floppy #装载模块,不是指定名称,而是指定文件名路径
insmod: can‘t read ‘floppy‘: No such file or directory
[[email protected] kernel]# insmod /lib/modules/2.6.18-164.el5/kernel/drivers/block/floppy.ko
[[email protected] kernel]# lsmod |grep floppy #验证加载模块floppy成功
floppy 95465 0
[[email protected] kernel]# rmmod floppy #删除模块floppy方法二
[[email protected] kernel]# lsmod |grep floppy
[[email protected] kernel]#
3、内核编译
内核中的功能除了核心功能之外,在编译时,大多功能都有三种选择:
1、不使用此功能;
2、编译成内核模块;
3、编译进内核;
如何手动编译内核:
make gconfig: Gnome桌面环境使用,需要安装图形开发库组:GNOME SoftwareDevelopment
make kconfig: KDE桌面环境使用,需要安装图形开发库
[[email protected] yum.repos.d]# yum grouplist
Loaded plugins: rhnplugin, security
Repository CD-ROM is listed more than once in the configuration
This system is not registered with RHN.
RHN support will be disabled.
Setting up Group Process
CD-ROM/group | 1.0 MB 00:00
Installed Groups:
...
Available Groups:
Authoring and Publishing
Development Libraries
Development Tools
...
[[email protected] linux]# yum groupinstall "Development Tools" "Development Libraries" -y
运行时间:10-100min
[[email protected] yum.repos.d]# yum grouplist
Installed Groups:
Development Libraries
Development Tools
...
Available Groups:
Authoring and Publishing
...
内核包下载地址:https://www.kernel.org/pub/linux/kernel/v2.6/
14-Aug-2004 11:13 43M
[[email protected] ~]# tar xf linux-2.6.8.1.tar.gz -C /usr/src/
[[email protected] ~]# cd /usr/src/
[[email protected] src]# ls
kernels linux linux-2.6.8.1 redhat
[[email protected] src]# ln -sv linux-2.6.8.1 linux
`linux/linux-2.6.8.1‘ -> `linux-2.6.8.1‘
[[email protected] src]# ls
kernels linux linux-2.6.8.1 redhat
[[email protected] src]# cd linux
[[email protected] linux]# ls -al
...
-rw-r--r-- 1 root root 79210 2007-10-31 02:01 .config
...
[[email protected] linux]# cp /boot/config-2.6.23.1-42.fc8 /usr/src/linux/.config
cp: overwrite `/usr/src/linux/.config‘? y
[[email protected] linux]# ls -al #使用本机正常使用的内核版本文件做二次编辑,降低出错率
...
...
[[email protected] linux]# make menuconfig #必须在linux目录下执行后进入文本模式
30MIN--5H 编辑后的设置存到.config中
第1步、make menuconfig: 打开文本下的图形窗口
第2步、make
第3步、make modules_install
第4步、make install
screen命令: 连接断开也能再次打开
screen: 直接打开一个新的屏幕
Ctrl+a, d: 拆除屏幕,可还原回来
screen -r ID: 还原回某屏幕
exit: 退出
[[email protected] linux]# yum install screen
[[email protected] ~]# screen -ls
There are screens on:
8231.pts-4.fox (Detached)
8200.pts-0.fox (Detached)
2 Sockets in /var/run/screen/S-root.
[[email protected] ~]# screen -r 8231
二次编译时清理,清理前,如果有需要,请备份配置文件.config:
make clean 清理配制好的二进制模块
make mrproper 清除所有残留的文件,包括.config文件
---end---
以上是关于Linux系统启动流程之kernel的主要内容,如果未能解决你的问题,请参考以下文章