dracut 基本介绍

dracut是一款用于构建initramfs镜像的工具,其设计旨在减少硬编码并提高内存加载速度。该工具通过依赖udev自动识别设备节点,快速挂载rootfs。dracut采用模块化设计,用户可根据需求定制不同的功能模块。

dracut 基本介绍
dracut 维基   https://dracut.wiki.kernel.org/index.php/Main_Page

         http://www.360doc.com/content/13/0428/09/12139495_281449877.shtml

dracut 官方手册 https://www.kernel.org/pub/linux/utils/boot/dracut/dracut.html#dracutkernel7

https://www.kernel.org/pub/linux/utils/boot/dracut/

基本介绍
dracut 是一个事件驱动的 initramfs 基础设施。dracut(工具)被用来通过拷贝工具和文件,从一个已经安装的系统创建一个 initramfs 镜像,并将镜像与dracut框架结合在一起。通常发现在 /usr/lib/dracut/modules.d/.

不像已经存在的initramfs框架,dracut的框架尝试有尽可能更少的硬编码进入initramfs。initramfs在生命中有一个基本的目标:获取已经挂载的rootfs,以致我们能够过渡到真正的rootfs。这是所有驱动装置的可用性。因此,取代脚本硬编码去做各种事情,dracut的 initramfs 依赖 udev 去创建符号链接到设备节点,接着,当rootfs的设备节点出现的时候,它被挂载和根切换到rootfs设备。 这个有助于保持在initramfs里要求的时间尽可能的少,以致一些事情,如5s钟启动,作为一个initramfs的存在结果不是不可能的。

在dracut中,大部分的initramfs生成器功能由一群生成模块提供,这些模块是被主要的dracut工具采购,来安装特定的功能进入initramfs。他们存在于这些模块的子目录。和使用由dracut-functions提供的功能去做他们的工作。

dracut 作为新一代的 initramfs 系统,和前一代的initramfs系统的 mkinitrd 的不同点在于, dracut设计上就考虑到了映像尺寸的问题,尽量避免硬编码,以提高生成的 cpio 映像载入内存的速度。实际上,由于initramfs的唯一作用就是挂载rootfs(因此不需要把一堆无用的比如 plymouth 等都装进去),它主要依赖 udev 去获取 rootfs 的设备节点,一旦 rootfs 节点出现则立刻切换过去。按照官方维基的说法:5秒启动不是梦。另外它采用了模块化的方式,使用者可自由在 %{_libdir}/dracut/modules.d 下创建他需要的特殊模块,可扩展性很强。最后它的使用方式和 mkinitrd 非常接近,迁移成本较低。

 dracut 用于制作initrd启动镜像文件, dracut-network会为镜像内添加nfs等网络支持.

centos 7.2
版本: dracut-033-359.el7.x86_64

   dracut-config-rescue-033-360.el7_2.x86_64

   dracut-033-360.el7_2.x86_64
   dracut-network-033-360.el7_2.x86_64

centos 6

  dracut-004-32.el6.noarch
  dracut-kernel-004-32.el6.noarch

命令行工具:
  dracut   create initial ramdisk images for preloading modules。 dracut创建虚拟磁盘映像,提供给内核,预加载块设备模块(例如 IDE,SCSI或者RAID),通过加载这些设备模块访问根文件系统。

      dracut [OPTION…] [ []]

   创建一个带有kernel版本号,为kernel使用的 initramfs 镜像。如果 被省略,那么使用实际运行的内核版本号。如果 被省略或为空,那么缺省的位置 /boot/initramfs-.img 被使用

   在启动时,内核解包这个存档进入内存,挂载和使用它作为初始化根文件系统。所有发现的根设备发生在这个早期的用户空间。

   完整的内核命令行选项,详看 dracut.cmdline(7).

   如果被降到一个紧急shell,当启动你的 initramfs时,文件 /run/initramfs/rdsosreport.txt 被创建,这个文件能被安全(手动挂载)的成为一个分区(通用 /启动)或一个USB盘. 通过在内核命令添加 rd.debug 产生附件的调试信息。 /run/initramfs/rdsosreport.txt 包含所有的日志和一些工具的输出。这个文件应该被联系到关于dracut问题的任何报告。

  lsinitrd   tool to show the contents of an initramfs image。if is omitted, then lsinitrd uses the default image /boot///initrd or /boot/initramfs-.img.

       lsinitrd [OPTION…] [ [ [ […] ]]]

      lsinitrd [OPTION…] -k

    lsinitrd 显示一个 initramfs 镜像的内容。 如果 被省略,那么 lsinitrd 用 这个缺省的镜像 /boot///initrd 或者 /boot/initramfs-.img

    OPTIONS
      -h, –help           print a help message and exit.

      -s, –size           sort the contents of the initramfs by size.

      -f, –file      print the contents of .

      -k, –kver   inspect the initramfs of .

  mkinitrd  is a compat wrapper, which calls dracut to generate an initramfs 调用 dracut 来产生 initramfs。

      mkinitrd [OPTION…] []  

    mkinitrd 通过调用 dracut 去创建一个 initramfs 带有版本的镜像 镜像。

    注意: 如果需要生成一个更细粒度控制的镜像,“dracut”应该被直接调用。

    OPTIONS

      –version          print info about the version

      -v, –verbose        increase verbosity level

      -f, –force          overwrite existing initramfs file.

      *–image-version      append the kernel version to the target image -.

      –with=      add the kernel module to the initramfs.

      –preload=    preload the kernel module in the initramfs before any other kernel modules are loaded. This can be used to ensure a certain device naming, which should in theory be avoided and the use of symbolic links in /dev is encouraged.

      –nocompress       do not compress the resulting image.

      –help            print a help message and exit.

配置
  /etc/dracut.conf            see dracut.conf5

  /etc/dracut.conf.d/*.conf        see dracut.conf5

 /usr/lib/dracut/dracut.conf.d/*.conf   see dracut.conf5

  Configuration in the initramfs
  /etc/conf.d/              Any files found in /etc/conf.d/ will be sourced in the initramfs to set initial values. Command line options will override these values set in the configuration files.

  /etc/cmdline              Can contain additional command line options. Deprecated, better use /etc/cmdline.d/*.conf.

  /etc/cmdline.d/*.conf          Can contain additional command line options.

服务
  dracut-cmdline.service

  dracut-initqueue.service

  dracut-mount.service

  dracut-pre-mount.service

  dracut-pre-pivot.service

  dracut-pre-trigger.service

  dracut-pre-udev.service

  dracut-shutdown.service

日志
  /var/log/dracut.log      initramfs 镜像创建的日志文件

  /tmp/dracut.log       initramfs 镜像创建的日志文件, 如果 /var/log/dracut.log 没有被写。

参考:

  PXE启动服务器及客户端镜像制作 http://blog.youkuaiyun.com/beck_chen/article/details/52672324

07-06
系统运维中,`dracut` 是一个用于生成 initramfs(initial RAM filesystem)的工具,initramfs 是在 Linux 系统启动早期阶段加载到内存中的临时根文件系统。它负责挂载实际的根文件系统并继续启动流程。当系统无法正常引导时,`dracut` 提供了多种方法用于调试和修复问题。 ### `dracut` 的基本使用 默认情况下,大多数 Linux 发行版会在内核升级或系统更新时自动调用 `dracut` 生成新的 initramfs。手动运行 `dracut` 可以通过以下命令: ```bash dracut /boot/initramfs-$(uname -r).img $(uname -r) ``` 此命令将为当前运行的内核版本生成一个 initramfs 镜像,并保存到 `/boot` 目录下[^1]。 ### 调试模式 如果系统无法正常启动,可以使用 `dracut` 的调试功能来排查问题。添加 `--debug` 参数可启用调试输出: ```bash dracut --debug /boot/initramfs-$(uname -r).img $(uname -r) ``` 此外,可以在内核命令行中添加 `rd.shell` 参数,使得系统在 initramfs 阶段进入交互式 shell,便于检查环境状态和执行诊断命令[^1]。 ### 故障排查技巧 - **模块缺失**:确保所需的驱动程序模块被包含在 initramfs 中。可以通过修改 `/etc/dracut.conf` 或创建 `.conf` 文件在 `/etc/dracut.conf.d/` 目录下,指定需要加入的模块。 - **文件系统损坏**:使用 `dracut` 时可以加入 `--fstab` 参数以确保 `/etc/fstab` 正确解析,并尝试修复文件系统错误。 - **网络引导问题**:若系统依赖网络挂载根文件系统(如 NFS),需确认是否启用了 `--add` 参数并加入了 `network` 模块: ```bash dracut --add network /boot/initramfs-$(uname -r).img $(uname -r) ``` - **加密设备支持**:对于使用 LUKS 加密的卷,应确保 initramfs 包含 `crypt` 模块,以便解锁加密分区。 - **日志分析**:在系统启动过程中查看早期的日志信息有助于定位问题。可以在 initramfs 中启用 `--logfile` 参数记录日志至磁盘。 ### 自定义 initramfs 用户可以通过配置文件定制 initramfs 的内容。例如,在 `/etc/dracut.conf.d/` 下创建 `custom.conf` 文件,添加如下内容以始终包含特定模块: ```ini add_dracutmodules+=" module_name " ``` 其中 `module_name` 替换为你希望添加的模块名称,如 `dmraid`、`iscsi` 等[^1]。 ### 总结 合理利用 `dracut` 工具不仅可以帮助构建可靠的 initramfs,还可以作为排查系统启动问题的重要手段。理解其参数与配置机制是解决复杂启动场景的关键。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值