-
Linux kernel
单内核体系设计、但充分借鉴了微内核设计体系的优点,为内核引入模块化机制。
-
内核组成部分:
-
kernel: 内核核心,一般为bzImage,通常在/boot目录下,名称为vmlinuz-VERSION-RELEASE;
-
kernel object: 内核对象,一般放置于/lib/modules/VERSION-RELEASE/,内核启动并不会加载所有的内核文件,而且模块之间有相互依赖关系,这个目录下通常维护多个模块,模块名称到文件路径映射以及多个模块之间的依赖关系等等。
-
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# ls -l /lib/modules/2.6.32-642.el6.x86_64/
total 3860
lrwxrwxrwx. 1 root root 46 Jan 29 09:35 build -> ../../../usr/src/kernels/2.6.32-642.el6.x86_64
drwxr-xr-x. 2 root root 4096 May 10 2016 extra
drwxr-xr-x. 11 root root 4096 Jan 29 09:35 kernel
-rw-r–r–. 1 root root 651373 Jan 29 09:36 modules.alias
-rw-r–r–. 1 root root 618220 Jan 29 09:36 modules.alias.bin
-rw-r–r–. 1 root root 1413 May 10 2016 modules.block
-rw-r–r–. 1 root root 69 Jan 29 09:36 modules.ccwmap
-rw-r–r–. 1 root root 211745 Jan 29 09:36 modules.dep
-rw-r–r–. 1 root root 305708 Jan 29 09:36 modules.dep.bin
-rw-r–r–. 1 root root 78 May 10 2016 modules.drm
-rw-r–r–. 1 root root 665 Jan 29 09:36 modules.ieee1394map
-rw-r–r–. 1 root root 218 Jan 29 09:36 modules.inputmap
-rw-r–r–. 1 root root 1313 Jan 29 09:36 modules.isapnpmap
-rw-r–r–. 1 root root 31 May 10 2016 modules.modesetting
-rw-r–r–. 1 root root 2052 May 10 2016 modules.networking
-rw-r–r–. 1 root root 74 Jan 29 09:36 modules.ofmap
-rw-r–r–. 1 root root 78070 May 10 2016 modules.order
-rw-r–r–. 1 root root 514249 Jan 29 09:36 modules.pcimap
-rw-r–r–. 1 root root 6259 Jan 29 09:36 modules.seriomap
-rw-r–r–. 1 root root 165 Jan 29 09:36 modules.softdep
-rw-r–r–. 1 root root 267597 Jan 29 09:36 modules.symbols
-rw-r–r–. 1 root root 335219 Jan 29 09:36 modules.symbols.bin
-rw-r–r–. 1 root root 881297 Jan 29 09:36 modules.usbmap
lrwxrwxrwx. 1 root root 5 Jan 29 09:35 source -> build
drwxr-xr-x. 2 root root 4096 May 10 2016 updates
drwxr-xr-x. 2 root root 4096 Jan 29 09:35 vdso
drwxr-xr-x. 2 root root 4096 May 10 2016 weak-updates
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
[ ]: N 不编译这个功能,不支持
-
[M]: M 编译成模块,需要时动态加载,需要的时候可以加载,不需要可以卸载,节约内存资源。
-
[*]: Y 编译核心组成部分,需要直接有不需要加载等待时间。
-
辅助文件:ramdisk
- CentOS 6: initramfs, 工具程序:mkinitrd, dracut
-
CentOS 5: initrd, 工具程序:mkinitrd
上面是静态视角。
-
运行中的内核:
-
uname命令:uname – print system information
-
uname [OPTION]…
-
-n: 显示节点名称;
[root@centos68 ~]# uname -n
centos68.zmjchina.cn
-
-r: 显示VERSION-RELEASE;
[root@centos68 ~]# uname -r
2.6.32-642.el6.x86_64
-
–s:显示操作系统名称
[root@centos68 ~]# uname -s
Linux
-
–v:版本号
[root@centos68 ~]# uname -v
#1 SMP Tue May 10 17:27:01 UTC 2016
-
–m:硬件平台 –p:处理器 –i :硬件平台 他们都是统一的。
[root@centos68 ~]# uname -m
x86_64
-
模块:
-
lsmod命令:
-
显示由核心已经装载的内核模块
显示的内容来自于: /proc/modules文件
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# lsmod
Module Size Used by
ipt_REJECT 2351 2
nf_conntrack_ipv4 9186 2
nf_defrag_ipv4 1483 1 nf_conntrack_ipv4
iptable_filter 2793 1
ip_tables 17831 1 iptable_filter
ip6t_REJECT 4340 2
nf_conntrack_ipv6 7985 3
nf_defrag_ipv6 26468 1 nf_conntrack_ipv6
xt_state 1492 5
nf_conntrack 79537 3 nf_conntrack_ipv4,nf_conntrack_ipv6,xt_state
ip6table_filter 2889 1
ip6_tables 18732 1 ip6table_filter
ipv6 336282 141 ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6
ppdev 8217 0
parport_pc 22658 0
parport 36209 2 ppdev,parport_pc
snd_seq_midi 6423 0
snd_seq_midi_event 7205 1 snd_seq_midi
snd_ens1371 21523 0
snd_rawmidi 24633 2 snd_seq_midi,snd_ens1371
snd_ac97_codec 124967 1 snd_ens1371
ac97_bus 1452 1 snd_ac97_codec
snd_seq 60769 2 snd_seq_midi,snd_seq_midi_event
snd_seq_device 7277 3 snd_seq_midi,snd_rawmidi,snd_seq
snd_pcm 93697 2 snd_ens1371,snd_ac97_codec
snd_timer 22747 2 snd_seq,snd_pcm
snd 73783 7 snd_ens1371,snd_rawmidi,snd_ac97_codec,snd_seq,snd_seq_device,snd_pcm,snd_timer
soundcore 7958 1 snd
snd_page_alloc 8856 1 snd_pcm
e1000 134863 0
vmware_balloon 7199 0
i2c_piix4 11232 0
sg 29318 0
shpchp 29130 0
ext4 379655 2
jbd2 93252 1 ext4
mbcache 8193 1 ext4
sd_mod 37158 3
crc_t10dif 1209 1 sd_mod
sr_mod 15049 0
cdrom 39085 1 sr_mod
mptspi 16411 2
mptscsih 36638 1 mptspi
mptbase 93615 2 mptspi,mptscsih
scsi_transport_spi 25447 1 mptspi
pata_acpi 3701 0
ata_generic 3837 0
ata_piix 24409 0
vmwgfx 226420 1
ttm 89408 1 vmwgfx
drm_kms_helper 127219 1 vmwgfx
drm 362893 4 vmwgfx,ttm,drm_kms_helper
i2c_core 29132 3 i2c_piix4,drm_kms_helper,drm
dm_mirror 14864 0
dm_region_hash 12085 1 dm_mirror
dm_log 9930 2 dm_mirror,dm_region_hash
dm_mod 102467 8 dm_mirror,dm_log
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
modinfo命令:
显示模块的详细描述信息
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# modinfo xfs
filename: /lib/modules/2.6.32-642.el6.x86_64/kernel/fs/xfs/xfs.ko
license: GPL
description: SGI XFS with ACLs, security attributes, large block/inode numbers, no debug enabled
author: Silicon Graphics, Inc.
srcversion: 67725EF8353DC29370566C8
depends: exportfs
vermagic: 2.6.32-642.el6.x86_64 SMP mod_unload modversions
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# modinfo xfs -k 2.6.32-642.el6.x86_64
filename: /lib/modules/2.6.32-642.el6.x86_64/kernel/fs/xfs/xfs.ko
license: GPL
description: SGI XFS with ACLs, security attributes, large block/inode numbers, no debug enabled
author: Silicon Graphics, Inc.
srcversion: 67725EF8353DC29370566C8
depends: exportfs
vermagic: 2.6.32-642.el6.x86_64 SMP mod_unload modversions
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
modinfo [ -k kernel ] [ modulename|filename… ]
-n: 只显示模块文件路径
-p: 显示模块参数
-a: author
-d: description
-l: license
lsmod 只想显示当前装载的模块,modinfo是查询数据库来获取模块信息的。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# lsmod | grep xfs
[root@centos68 ~]# modinfo xfs
filename: /lib/modules/2.6.32-642.el6.x86_64/kernel/fs/xfs/xfs.ko
license: GPL
description: SGI XFS with ACLs, security attributes, large block/inode numbers, no debug enabled
author: Silicon Graphics, Inc.
srcversion: 67725EF8353DC29370566C8
depends: exportfs
vermagic: 2.6.32-642.el6.x86_64 SMP mod_unload modversions
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
modprobe命令:
装载或卸载内核模块
modprobe [ -C config-file ] [ modulename ] [ module parame-ters… ]
配置文件:/etc/modprobe.conf, /etc/modprobe.d/*.conf
modprobe [ -r ] modulename..
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# modinfo xfs
filename: /lib/modules/2.6.32-642.el6.x86_64/kernel/fs/xfs/xfs.ko
license: GPL
description: SGI XFS with ACLs, security attributes, large block/inode numbers, no debug enabled
author: Silicon Graphics, Inc.
srcversion: 67725EF8353DC29370566C8
depends: exportfs
vermagic: 2.6.32-642.el6.x86_64 SMP mod_unload modversions
[root@centos68 ~]# lsmod | grep xfs
[root@centos68 ~]# modprobe xfs
[root@centos68 ~]# lsmod | grep xfs
xfs 1135329 0
exportfs 4236 1 xfs
[root@centos68 ~]# modprobe -r xfs
[root@centos68 ~]# lsmod | grep xfs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
-
depmod命令:
内核模块依赖关系文件及系统信息映射文件的生成工具;
depmod – program to generate modules.dep and map files.
modules.dep—–>编译成二进制文件——-à modules.dep.bin
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# ls /lib/modules/2.6.32-642.el6.x86_64/modules.dep* -l
-rw-r–r–. 1 root root 211745 Jan 29 09:36 /lib/modules/2.6.32-642.el6.x86_64/modules.dep
-rw-r–r–. 1 root root 305708 Jan 29 09:36 /lib/modules/2.6.32-642.el6.x86_64/modules.dep.bin
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
内核所用到的每个库文件彼此间的映射关系。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# ls -l /boot/System.map-2.6.32-642.el6.x86_64
-rw-r–r–. 1 root root 2615003 May 10 2016 /boot/System.map-2.6.32-642.el6.x86_64
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
装载或卸载内核模块:
-
insmod命令:
insmod [ filename ] [ module options… ] 跟modprobe不同的是指定哪个模块装载哪个模块不会解决依赖关系。必须指明路径。
-
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# insmod xfs
insmod: can’t read ‘xfs’: No such file or directory
[root@centos68 ~]# modprobe xfs
[root@centos68 ~]# lsmod | grep xfs
xfs 1135329 0
exportfs 4236 1 xfs
[root@centos68 ~]# lsmod | grep xfs
[root@centos68 ~]# modinfo xfs
filename: /lib/modules/2.6.32-642.el6.x86_64/kernel/fs/xfs/xfs.ko
license: GPL
description: SGI XFS with ACLs, security attributes, large block/inode numbers, no debug enabled
author: Silicon Graphics, Inc.
srcversion: 67725EF8353DC29370566C8
depends: exportfs
vermagic: 2.6.32-642.el6.x86_64 SMP mod_unload modversions
[root@centos68 ~]# insmod /lib/modules/2.6.32-642.el6.x86_64/kernel/fs/xfs/xfs.ko
[root@centos68 ~]# lsmod | grep xfs
xfs 1135329 0
exportfs 4236 1 xfs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
手动加载btrfs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# lsmod | grep btrfs
[root@centos68 ~]# modinfo btrfs
filename: /lib/modules/2.6.32-642.el6.x86_64/kernel/fs/btrfs/btrfs.ko
license: GPL
alias: devname:btrfs-control
alias: char-major-10-234
srcversion: B412C18B0F5BF7F1B3C941A
depends: libcrc32c,zlib_deflate,lzo_compress,lzo_decompress
vermagic: 2.6.32-642.el6.x86_64 SMP mod_unload modversions
[root@centos68 ~]# insmod $(modinfo -n btrfs)
insmod: error inserting ‘/lib/modules/2.6.32-642.el6.x86_64/kernel/fs/btrfs/btrfs.ko’: -1 Unknown symbol in module
[root@centos68 ~]# lsmod | grep libcrc32c
[root@centos68 ~]# lsmod | grep zlib_deflate
[root@centos68 ~]# lsmod | grep lzo_compress
[root@centos68 ~]# lsmod | grep lzo_decompress
[root@centos68 ~]# insmod $(modinfo -n libcrc32c)
[root@centos68 ~]# insmod $(modinfo -n zlib_deflate)
[root@centos68 ~]# insmod $(modinfo -n lzo_compress)
[root@centos68 ~]# insmod $(modinfo -n lzo_decompress)
[root@centos68 ~]# insmod $(modinfo -n btrfs)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
rmmod命令:
rmmod [ modulename ]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# modprobe xfs
[root@centos68 ~]# lsmod | grep xfs
xfs 1135329 0
exportfs 4236 1 xfs
[root@centos68 ~]# rmmod xfs
[root@centos68 ~]# lsmod | grep xfs
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Modprobe直接卸载关联的模块,而rmmod不会。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# rmmod btrfs
[root@centos68 ~]# lsmod | grep lzo_decompress
lzo_decompress 2343 0
[root@centos68 ~]# lsmod | grep btrfs
[root@centos68 ~]# modprobe -r btrfs
[root@centos68 ~]# lsmod | grep btrfs
[root@centos68 ~]# lsmod | grep lzo_decompress
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
/proc目录:
内核把自己内部状态信息及统计信息,以及可配置参数通过proc伪文件系统加以输出;
数字为每一个进程的状态信息。非数字目录或者目录:内核自己状态信息、可配置参数接口、统计信息。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# sysctl -a | wc -l
724
[root@centos68 ~]# ls /proc/
1 1256 1475 15 19 2125 25 270 35 45 50 83 buddyinfo diskstats interrupts key-users meminfo net slabinfo timer_list zoneinfo
10 1278 1488 1507 1968 2191 250 28 36 46 554 9 bus dma iomem kmsg misc pagetypeinfo softirqs timer_stats
11 13 1490 1511 2 22 253 29 37 467 6 916 cgroups driver ioports kpagecount modules partitions stat tty
114 1300 1492 16 20 2210 26 3 38 468 693 917 cmdline execdomains irq kpageflags mounts sched_debug swaps uptime
1174 14 1494 17 21 2255 268 30 399 48 7 956 cpuinfo fb kallsyms loadavg mpt schedstat sys version
1199 1461 1496 18 2102 23 269 33 4 49 8 acpi crypto filesystems kcore locks mtd scsi sysrq-trigger vmallocinfo
12 1471 1498 1845 2107 24 27 34 401 5 82 asound devices fs keys mdstat mtrr self sysvipc vmstat
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
参数:
-
只读:输出信息
-
可写:可接受用户指定”新值”来实现对内核某功能或特性的配置
-
可写的一般都在/proc/sys下面,sysctl设置控制这个目录下的诸多参数。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# ls -l /proc/sys/
total 0
dr-xr-xr-x 0 root root 0 Jan 29 15:45 abi
dr-xr-xr-x 0 root root 0 Jan 29 11:50 crypto
dr-xr-xr-x 0 root root 0 Jan 29 15:45 debug
dr-xr-xr-x 0 root root 0 Jan 29 15:45 dev
dr-xr-xr-x 0 root root 0 Jan 29 11:50 fs
dr-xr-xr-x 0 root root 0 Jan 29 11:50 kernel
dr-xr-xr-x 0 root root 0 Jan 29 11:50 net
dr-xr-xr-x 0 root root 0 Jan 29 11:50 vm
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
sysctl命令用于查看或设定此目录中诸多参数;
sysctl -w path.to.parameter=VALUE
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# find /proc/sys/ -name hostname
/proc/sys/kernel/hostname
[root@centos68 ~]# hostname
centos6868
[root@centos68 ~]# sysctl -w kernel.hostname=centos68.zmjchina.cn
kernel.hostname = centos68.zmjchina.cn
[root@centos68 ~]# hostname
centos68.zmjchina.cn
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
echo命令通过重定向的方式也可以修改大多数参数的值;
echo “VALUE” > /proc/sys/path/to/parameter
~]# echo “www.magedu.com” > /proc/sys/kernel/hostname
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# hostname
centos6868
[root@centos68 ~]# echo “centos68.zmjchina.cn” > /proc/sys/kernel/hostname
[root@centos68 ~]# hostname
centos68.zmjchina.cn
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
sysctl命令:
默认配置文件:/etc/sysctl.conf
-
设置某参数
sysctl -w parameter=VALUE
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# find /proc/sys/ -name hostname
/proc/sys/kernel/hostname
[root@centos68 ~]# hostname
centos6868
[root@centos68 ~]# sysctl -w kernel.hostname=centos68.zmjchina.cn
kernel.hostname = centos68.zmjchina.cn
[root@centos68 ~]# hostname
centos68.zmjchina.cn
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
通过读取配置文件设置参数
sysctl -p [/path/to/conf_file]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0
[root@centos68 ~]# cat /etc/sysctl.conf | grep “^net.ipv4.ip_forward”
net.ipv4.ip_forward = o
[root@centos68 ~]# vim /etc/sysctl.conf
[root@centos68 ~]# cat /etc/sysctl.conf | grep “^net.ipv4.ip_forward”
net.ipv4.ip_forward = 1
[root@centos68 ~]# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0
[root@centos68 ~]# sysctl -p /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
[root@centos68 ~]# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
查询有多少参数可用 –a:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# sysctl -a | wc -l
724
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
常用的几个参数:
-
net.ipv4.ip_forward
-
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# cat /proc/sys/net/ipv4/ip_forward
0
[root@centos68 ~]# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
vm.drop_caches
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# free
total used free shared buffers cached
Mem: 1012080 805208 206872 264 52124 562464
-/+ buffers/cache: 190620 821460
Swap: 2031612 0 2031612
[root@centos68 ~]# ls /proc/sys/vm/drop_caches -l
-rw-r–r– 1 root root 0 Jan 29 15:45 /proc/sys/vm/drop_caches
[root@centos68 ~]# sysctl -w vm.drop_caches=1
vm.drop_caches = 1
[root@centos68 ~]# free
total used free shared buffers cached
Mem: 1012080 184624 827456 264 188 10608
-/+ buffers/cache: 173828 838252
Swap: 2031612 0 2031612
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
kernel.hostname
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# find /proc/sys/ -name hostname
/proc/sys/kernel/hostname
[root@centos68 ~]# hostname
centos6868
[root@centos68 ~]# sysctl -w kernel.hostname=centos68.zmjchina.cn
kernel.hostname = centos68.zmjchina.cn
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
/sys目录:
-
sysfs:输出内核识别出的各硬件设备的相关属性信息,也有内核对硬件特性的设定信息;有些参数是可以修改的,用于调整硬件工作特性。我们都知道dev是输出设备文件的,那么我们系统又如何知道有哪些设备又如何创建设备文件的呢?内核启动的是时候通过探测各硬件的io port 端口上有哪些设备连接进来,并通过获取这些硬件自己的工作电压所输出的这些硬件信息,才能知道这是内核。只有用户空间访问硬件设备才会使用设备文件,内核自身不需要。2.4以前设备文件都是事先创建好的,无论是否有都会有。(有进20000个,实际使用就几十个)。内核无论探测多少设备都不会自动为它创建设备文件,dev目录下的设备文件,2.4后让内核启动后探测硬件设备,探测完以后该启动的启动,但是当用户空需要用到此前探测到的设备文件,用内生机制触发探再测一遍然后输出到sys目录。输出保存所有的硬件设备。
-
用户空间udev通过此路径下输出的信息动态为各设备创建所需要设备文件;udev是运行用户空间程序;专用工具:udevadmin, hotplug;
-
udev为设备创建设备文件时,会读取其事先定义好的规则文件,一般在/etc/udev/rules.d及/usr/lib/udev/rules.d目录下;
-
-
ramdisk文件的制作:
-
mkinitrd命令:为当前正在使用的内核重新制作ramdisk文件
-
~] # mkinitrd /boot/initramfs-$(uname -r).img $(uname -r)
cpio –i:解开文件 –d:创建目录
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[root@centos68 ~]# mkinitrd /home/initramfs-$(uname -r).img $(uname -r)
[root@centos68 ~]# cd /home/
[root@centos68 home]# file initramfs-2.6.32-642.el6.x86_64.img
initramfs-2.6.32-642.el6.x86_64.img: gzip compressed data, from Unix, last modified: Sun Jan 29 20:09:04 2017, max compression
[root@centos68 home]# mv initramfs-2.6.32-642.el6.x86_64.img initramfs-2.6.32-642.el6.x86_64.img.gz
[root@centos68 home]# ls -l
total 24460
-rw——-. 1 root root 25046281 Jan 29 20:09 initramfs-2.6.32-642.el6.x86_64.img.gz
[root@centos68 home]# gzip -d initramfs-2.6.32-642.el6.x86_64.img.gz
[root@centos68 home]# mkdir initrd
[root@centos68 home]# cd initrd/
[root@centos68 initrd]# file ../initramfs-2.6.32-642.el6.x86_64.img
../initramfs-2.6.32-642.el6.x86_64.img: ASCII cpio archive (SVR4 with no CRC)
[root@centos68 initrd]# cpio -id < ../initramfs-2.6.32-642.el6.x86_64.img
137405 blocks
[root@centos68 initrd]# ls
bin emergency initqueue-finished lib64 pre-pivot sbin usr
cmdline etc initqueue-settled mount pre-trigger sys var
dev init initqueue-timeout netroot pre-udev sysroot
dracut-004-409.el6 initqueue lib pre-mount proc tmp
[root@centos68 initrd]# ls /sbin/switch_root -l
-rwxr-xr-x. 1 root root 8688 May 10 2016 /sbin/switch_root
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
dracut命令: 为当前正在使用的内核重新制作ramdisk文件
~] # dracut /boot/initramfs-$(uname -r).img $(uname -r)