码迷,mamicode.com
首页 > 系统相关 > 详细

Linux系统启动流程之kernel

时间:2016-11-20 00:27:51      阅读:323      评论:0      收藏:0      [点我收藏+]

标签:kernel

Linux系统启动流程之kernel

 

1、内核参数修改方法:

2、内核内核模块管理:

3、内核编译

用户空间访问、监控内核的方式:/proc, /sys

 伪文件系统

/proc/sys: 此目录中的文件很多是可读写的

/sys/: 某些文件可写

 

  1、内核参数修改方法:

echo VALUE > /proc/sys/TO/SOMEFILE

sysctl -w kernel.hostname=

   

[root@localhost vm]# free -m
  total   used   free   shared    buffers     cached
Mem:    7983  541  7442  0  149  269
-/+ buffers/cache:  123   7860
Swap:    4094    0 4094
[root@localhost vm]# echo 1 > /proc/sys/vm/drop_caches
[root@localhost vm]# free -m
 total  used   free  shared  buffers  cached
Mem:  7983  125  7857   0  0  9
-/+ buffers/cache: 115  7867
Swap: 4094  0  4094

[root@localhost kernel]# sysctl -w vm.drop_caches=1
vm.drop_caches = 1
[root@localhost kernel]# free -m
 total  used   free  shared  buffers  cached
Mem:  7983  125  7857   0  0  9
-/+ buffers/cache: 115  7868
Swap: 4094  0  4094


[root@localhost kernel]# cat /proc/sys/kernel/hostname
localhost.localdomain
[root@localhost kernel]# echo wfx >/proc/sys/kernel/hostname
[root@localhost kernel]# hostname
wfx

[root@localhost kernel]# sysctl -w kernel.hostname="local.com"
kernel.hostname = local.com
[root@localhost kernel]# hostname
local.com


[root@localhost kernel]# cat /proc/sys/net/ipv4/ip_forward
0

[root@localhost 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
...

[root@localhost 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

[root@localhost kernel]# cat /proc/sys/net/ipv4/ip_forward   #验证
1

[root@localhost 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 安装驱动时内核模块必须同一版本

 

[root@localhost kernel]# lsmod |grep floppy
floppy                 95465  0
[root@localhost kernel]# modprobe -r floppy   #删除模块floppy
[root@localhost kernel]# lsmod |grep floppy
[root@localhost kernel]# modprobe floppy   #加载模块floppy
[root@localhost kernel]# lsmod |grep floppy
floppy                 95465  0
[root@localhost 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


[root@localhost kernel]# modprobe -r floppy  #删除模块floppy
[root@localhost kernel]# insmod floppy     #装载模块,不是指定名称,而是指定文件名路径
insmod: can‘t read ‘floppy‘: No such file or directory
[root@localhost kernel]# insmod /lib/modules/2.6.18-164.el5/kernel/drivers/block/floppy.ko
[root@localhost kernel]# lsmod |grep floppy  #验证加载模块floppy成功
floppy    95465  0
[root@localhost kernel]# rmmod floppy   #删除模块floppy方法二
[root@localhost kernel]# lsmod |grep floppy
[root@localhost kernel]#

 

  3、内核编译

内核中的功能除了核心功能之外,在编译时,大多功能都有三种选择:

1、不使用此功能;

2、编译成内核模块;

3、编译进内核;

 

如何手动编译内核:

make gconfig: Gnome桌面环境使用,需要安装图形开发库组:GNOME SoftwareDevelopment

make kconfig: KDE桌面环境使用,需要安装图形开发库

 

[root@localhost 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
...

[root@local linux]# yum groupinstall "Development Tools" "Development Libraries" -y

运行时间:10-100min

[root@localhost 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

[root@JackTest ~]# tar xf linux-2.6.8.1.tar.gz -C /usr/src/
[root@JackTest ~]# cd /usr/src/
[root@JackTest src]# ls
kernels  linux  linux-2.6.8.1  redhat
[root@JackTest src]# ln -sv linux-2.6.8.1 linux
`linux/linux-2.6.8.1‘ -> `linux-2.6.8.1‘
[root@JackTest src]# ls
kernels  linux  linux-2.6.8.1  redhat
[root@JackTest src]# cd linux

[root@JackTest linux]# ls -al
...
-rw-r--r--  1 root root  79210 2007-10-31 02:01 .config

...

[root@JackTest linux]#  cp /boot/config-2.6.23.1-42.fc8 /usr/src/linux/.config
cp: overwrite `/usr/src/linux/.config‘? y

[root@JackTest linux]# ls -al  #使用本机正常使用的内核版本文件做二次编辑,降低出错率

... 

-rw-r--r--  1 root root  79210 2016-11-19 15:49 .config  

...

[root@JackTest linux]# make menuconfig  #必须在linux目录下执行后进入文本模式

30MIN--5H      编辑后的设置存到.config中

技术分享

 第1步、make menuconfig: 打开文本下的图形窗口

第2步、make

第3步、make modules_install

第4步、make install


   screen命令:  连接断开也能再次打开

screen -ls:  显示已经建立的屏幕

screen:     直接打开一个新的屏幕

    Ctrl+a, d:  拆除屏幕,可还原回来

screen -r ID:  还原回某屏幕

exit: 退出

 [root@fox linux]# yum install screen

[root@fox ~]# screen -ls
There are screens on:
    8231.pts-4.fox    (Detached)
    8200.pts-0.fox    (Detached)
2 Sockets in /var/run/screen/S-root.
[root@fox ~]# screen -r 8231

 

二次编译时清理,清理前,如果有需要,请备份配置文件.config:

make clean   清理配制好的二进制模块

make mrproper    清除所有残留的文件,包括.config文件

 

---end---

Linux系统启动流程之kernel

标签:kernel

原文地址:http://wangfx.blog.51cto.com/1697877/1874621

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!