on  It Road.com

列出 initramfs 镜像的内容

要仅列出 initramfs 镜像文件的内容,我们可以运行 lsinitrd :

# lsinitrd /boot/initramfs-3.10.0-229.el7.x86_64.img  | more
Image: /boot/initramfs-3.10.0-229.el7.x86_64.img: 19M
========================================================================
Version: dracut-033-359.el7
Arguments: -f
dracut modules:
bash
nss-softokn
i18n
network
ifcfg
drm
plymouth
dm
kernel-modules
lvm
resume
rootfs-block
terminfo
udev-rules
biosdevname
systemd
usrmount
base
fs-lib
shutdown
========================================================================
drwxr-xr-x  12 root     root            0 Jan 23 10:27 .
crw-r--r--   1 root     root       5,   1 Jan 23 10:27 dev/console
crw-r--r--   1 root     root       1,  11 Jan 23 10:27 dev/kmsg
crw-r--r--   1 root     root       1,   3 Jan 23 10:27 dev/null
CentOS/RHEL 7:如何提取 initramfs 镜像

如何提取 initramfs 镜像文件以查看或者编辑其中内容?

这篇文章提供了为 RHEL 7 提取 initramfs 镜像文件的步骤。
与以前的版本不同,在 RHEL 7 上对 initramfs 镜像文件使用 cpio 命令不会提取所有文件(或者会出现一些错误)。
例如:

# ls -la /boot/initramfs-$(uname -r).img
-rw------- 1 root root 19602671 Nov  4  2016 /boot/initramfs-3.10.0-229.el7.x86_64.img
# file initramfs-3.10.0-229.el7.x86_64.img
initramfs-3.10.0-229.el7.x86_64.img: gzip compressed data, from Unix, last modified: Thu Nov  4 16:02:04 2016, max compression
# gzip -dc initramfs-3.10.0-229.el7.x86_64.img | cpio -id      --- will not extract all files or will give some error

要在 RHEL7 上提取它,请使用 skipcpio :

  1. 将 initramfs 镜像文件复制到某个目录。
# mkdir /tmp/initramfs
# cp /boot/initramfs-3.10.0-229.el7.x86_64.img
  1. 使用 /usr/lib/dracut/skipcpio 命令提取内容:
# cd /tmp/initramfs
# /usr/lib/dracut/skipcpio initramfs-3.10.0-229.el7.x86_64.img | zcat | cpio -ivd
.
var
var/lock
var/run
lib

其中 skipcpio 是 dracut 的内置工具。

日期:2020-09-17 00:12:40 来源:oir作者:oir