LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 309|回复: 0

initramfs 的重要性与监理新 initramfs 文件

[复制链接]
发表于 2024-1-21 23:50:17 | 显示全部楼层 |阅读模式
在前面提到过 initramfs,它的目的是在于提供开机过程中所需要的最重要核心模块,让系统开机过程可以顺利完成。

一般来说,需要 initramfs 的时刻有:

根目录所在磁盘为 STAT、USB 或 SCSI 等连接接口
根目录所在文件系统为 LVM、RAID 等特殊格式
根目录所在文件系统为非传统 LInux 认识的文件系统时
其他必须要在核心加载时提供的模块
一般来说,各 distribution 提供的核心都会附上 initramfs 文件,但是如果你有特殊需要想重新制作 initramfs 文件的话,可以使用 dracut\mkinitrd 来处理

在 CentOS 7 下应该使用 dracut,这里也主要介绍它

dracut [-fv] [--add-drivers 列表] initramfs 文件名 核心版本

选项与参数:

        -f:强迫编译出 initramfs,如果 initramfs 文件已经存在,则覆盖旧文件
        -v:显示 dracut 的运行过程
        --add-drivers 列表:在原本的默认核心模块中,增加某些你想要的模块,模块维护核心所在目录 `/lib/modules/$(uname -r)/kernel/*`
        initramfs 文件名:你需要的文件名,开头最好以 initramfs,后面接版本与功能
        核心版本:默认是目前运行中的核心版本,也可以手动输入其他不同版本
       
        dracut 还有很多功能。例如下面的几个参数:
        --modules:将 dracut 所提供的开机锁需模块(核心模块)加载,可用模块在 /usr/lib/dracut/modules.d/ 目录
        --gzip|--bzip2|--xz:尝试使用哪一种压缩方式来进行 initramfs 压缩,默认使用 gzip
        --filesystem:加入某些额外的文件系支持
       
# 范例 1:以 dracut 的默认功能建立一个 initramfs 虚拟盘文件
[root@study ~]# dracut -v initramfs-test.img $(uname -r)
Executing: /sbin/dracut -v initramfs-test.img 3.10.0-1062.el7.x86_64
dracut module 'busybox' will not be installed, because command 'busybox' could not be found!
...
dracut module 'cifs' will not be installed, because command 'mount.cifs' could not be found!
*** Including module: bash ***
*** Including module: nss-softokn ***
*** Including module: i18n ***
*** Including module: network ***
*** Including module: ifcfg ***
*** Including module: drm ***
*** Including module: plymouth ***
*** Including module: dm ***
Skipping udev rule: 64-device-mapper.rules
....

# 范例 2:额外加入 e100e 网卡驱动与 ext4/nfs 文件系统在新的 initramfs 内
[root@study ~]# dracut -v --add-drivers "e10001" --filesystems "ext4 nfs" initramfs-new.img $(uname -r)
[root@study ~]# lsinitrd initramfs-new.img | grep -E '(e1000|ext4|nfs)'
Arguments: -v --add-drivers 'e10001' --filesystems 'ext4 nfs'
nfs
-rw-r--r--   1 root     root           15 Mar 29 21:52 etc/modprobe.d/nfs.conf
...


        Copied!

建立完成之后,同时核心也处理完成后,就可以使用 grub2 来建立选单了。下面继续

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表