手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

RHEL6 启动过程

[日期:2012-07-01] 来源:Linux社区  作者:linuxkeep [字体:大 中 小]

Linux内核是可以通过动态加载内核模块的 (就请想成驱动程序即可),这些内核模块就放在 /lib/modules/目录内。由于模块放到磁盘根目录内(这就是为什么/lib不可以与/ 分别放在不同的分区原因), 因此在开机的过程中内核必须要挂载根目录,这样才能够读取内核模块提供加载驱动程序的功能。 而且为了担心影响到磁盘内的文件系统,开机过程中根目录是以只读的方式来挂载的。

#rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc

KEYTABLE=us crashkernel=auto rhgb quiet

Speeding up the Boot Process

If you want to speed up the boot process, you can specify as much information for dracut on the kernel command as possible. For example, you can tell dracut, that you root partition is not on a LVM volume or not on a raid partition, or that it lives inside a specific crypto LUKS encrypted volume. By default, dracut searches everywhere. A typical dracut kernel command line for a plain primary or logica partition would contain:

rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM (elinks /usr/share/doc/dracut-004/dracut-rhel6.html or man 8 dracut)

This turns off every automatic assembly of LVM, MD raids, DM raids and crypto LUKS.

Keyboard Settings

If you have to input passwords for encrypted disk volumes, you might want to set the keyboard layout and specify a display font.

A typical german kernel command would contain:

LANG=de_DE.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=de-latin1-nodeadkeys

rhgb表示RedHat graphics boot,就是会看到图片来代替启动过程中显示的文本信息,这些信息在启动后用dmesg也可以看到

quiet表示在启动过程中只有重要信息显示,类似硬件自检的消息不回显示crashkernel=auto kdump使用的内存空间

#initrd /initramfs-2.6.32-71.el6.i686.img

boot loader装入kernel,然后kernel需要执行/sbin/init,读取这个文件就必须先mount根文件系统,早期是通过启动时的 root="参数"告诉内核根文件系统在哪个设备上,随着硬件和技术的发展,现在根文件系统可能位于一个网络存储如NFS上,可能由于RAID而散布于多个设备上,可能位于一个加密设备上需要提供用户名和密码,这时root="参数"就显得不够了。为了应付这种局面,先后出现两种机制来作为boot loader装载kernel到真正的/sbin/init执行这个启动过程的桥梁: initrd和nitramfs

initrd:

虚拟文件系统(Initial RAM Disk) 一般使用的文件名为 /boot/initrd ,这个文件的作用是,能够通过 boot loader 来加载到内存中, 然后这个文件会被解压缩并且在内存当中仿真成一个根目录, 且此仿真在内存当中的文件系统能够提供一支可执行的程序,通过该程序来加载开机过程中所最需要的内核模块,通常这些模块就是 USB, RAID, LVM,SCSI 等文件系统与磁盘接口的驱动程序。等载入完成后,会帮助内核重新呼叫 /sbin/init 来开始后续的正常开机流程。

Initial RAM Disk是一个基于ram的块设备,因此它占据了一块固定的内存,而且事先要使用特定的工具比如mke2fs格式化,还需要一个文件系统驱动来读写其上的文件。如果这个disk上的空间没有用完,这些未用的内存就浪费掉了,并且这个disk的空间固定导致容量有限,要想装入更多的文件就需要重新格式化。由于Linux的块设备缓冲特性,ram disk上的数据被拷贝到page cache(对于文件数据)和dentry cache(对于目录项),这个也导致内存浪费。

initramfs:

最初的想法是Linus提出的: 把cache当作文件系统装载。 他在一个叫ramfs的cache实现上加了一层很薄的封装,其它内核开发人员编写了一个改进版tmpfs, 这个文件系统上的数据可以写出到交换分区,而且可以设定一个tmpfs装载点的最大尺寸以免耗尽内存。initramfs就是tmpfs的一个应用。Linux 2.6 kernel提出了这种新的实现机制,即 initramfs。顾名思义,initramfs只是一种RAM filesystem而不是disk。

initramfs的优点:

(1)tmpfs随着其中数据的增减自动增减容量。

(2)在tmpfs和page cache/dentry cache之间没有重复数据。

(3)tmpfs重复利用了Linux caching的代码,因此几乎没有增加内核尺寸,而caching的代码已经经过良好测试,所以tmpfs的代码质量也有保证。

(4)不需要额外的文件系统驱动。

另外,initrd机制被设计为旧的"root="机制的前端,而非其替代物,它假设真正的根设备是一个块设备,而且也假设了自己不是真正的根设备,这样不便将NFS等作为根文件系统,最后/linuxrc不是以PID=1执行的,因为1这个进程ID是给/sbin/init保留的。initrd机制找到真正的根设备后将其设备号写入/proc/sys/kernel/real-root-dev,然后控制转移到内核由其装载根文件系统并启动/sbin /init。initramfs则去掉了上述假设,而且/init以PID=1执行,由init装载根文件系统并用exec转到真正的/sbin /init,这样也 导致一个更为干净漂亮的设计。

下面让我们来看看initrd文件的具体内容,

[root@osdba~]# mkdir /tmp/initramfs/

[root@osdba~]# cp /boot/initramfs-2.6.32-71.el6.i686.img /tmp/initramfs/

[root@osdba~]# cd /tmp/initramfs/

[root@osdba initramfs]# file initramfs-2.6.32-71.el6.i686.img

initramfs-2.6.32-71.el6.i686.img: gzip compressed data, from Unix, last modified: Wed Aug 24 23:14:47 2011, max compression

我们可以看到,这个文件是GZIP压缩的文件,我们把后缀改成gz,然后再进行解压

[root@osdba initramfs]# mv initramfs-2.6.32-71.el6.i686.img initramfs-2.6.32-71.el6.i686.img.gz

[root@osdba initramfs]# gunzip initramfs-2.6.32-71.el6.i686.img.gz

解压后,我们再来看看这个文件是什么类型的

[root@osdba initramfs]# file initramfs-2.6.32-71.el6.i686.img

initramfs-2.6.32-71.el6.i686.img: ASCII cpio archive (SVR4 with no CRC)

是cpio压缩成的文件

[root@osdba initramfs]# cpio -iv < initramfs-2.6.32-71.el6.i686.img

[root@osdba initramfs]# ls -l

total 29708

drwxr-xr-x. 2 root root 4096 Sep 19 14:52 bin

drwxr-xr-x. 2 root root 4096 Sep 19 14:52 cmdline

drwxr-xr-x. 3 root root 4096 Sep 19 14:52 dev

-rw-r--r--. 1 root root 18 Sep 19 14:52 dracut-004-32.el6

drwxr-xr-x. 2 root root 4096 Sep 19 14:52 emergency

drwxr-xr-x. 7 root root 4096 Sep 19 14:52 etc

-rwxr-xr-x. 1 root root 8088 Sep 19 14:52 init

drwxr-xr-x. 2 root root 4096 Sep 19 14:52 initqueue

drwxr-xr-x. 2 root root 4096 Sep 19 14:52 initqueue-finished

drwxr-xr-x. 2 root root 4096 Sep 19 14:52 initqueue-settled

-rw-r--r--. 1 root root 30326784 Sep 19 14:57 initramfs-2.6.32-71.el6.i686.img

drwxr-xr-x. 9 root root 4096 Sep 19 14:52 lib

drwxr-xr-x. 2 root root 4096 Sep 19 14:52 mount

drwxr-xr-x. 2 root root 4096 Sep 19 14:52 pre-pivot

drwxr-xr-x. 2 root root 4096 Sep 19 14:52 pre-trigger

drwxr-xr-x. 2 root root 4096 Sep 19 14:52 pre-udev

drwxr-xr-x. 2 root root 4096 Sep 19 14:52 proc

drwxr-xr-x. 2 root root 4096 Sep 19 14:52 sbin

drwxr-xr-x. 2 root root 4096 Sep 19 14:52 sys

drwxr-xr-x. 2 root root 4096 Sep 19 14:52 sysroot

drwxr-xr-x. 2 root root 4096 Sep 19 14:52 tmp

drwxr-xr-x. 6 root root 4096 Sep 19 14:52 usr

drwxr-xr-x. 3 root root 4096 Sep 19 14:52 var

看结果,和我们系统中的/很类似。(有兴趣,慢慢了解)

linux
相关资讯       RHEL6 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款