November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

CentOS / RHEL 7 : How to extract initramfs image and edit/view it

In some cases you may want to extract the initramfs image file to check built-in contents. This post provides steps to extract initramfs image files for RHEL 7. Unlike previous version, on RHEL 7 using cpio command for the initramfs image file will not extract all files (or will give some error). For example:

# ls -la /boot/initramfs-$(uname -r).img
-rw——- 1 root root 19602671 Feb 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 Feb 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
To extract it on RHEL7, use skipcpio:
1. copy the initramfs image file to some directory.

# mkdir /tmp/initramfs
# cp /boot/initramfs-3.10.0-229.el7.x86_64.img
2. extract the contents using the /usr/lib/dracut/skipcpio command :

# 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
where skipcpio is the built-in tool from dracut.

Listing the content of initramfs image

To only list the contents of an initramfs image file, you can run 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 May 23 10:27 .
crw-r–r– 1 root root 5, 1 May 23 10:27 dev/console
crw-r–r– 1 root root 1, 11 May 23 10:27 dev/kmsg
crw-r–r– 1 root root 1, 3 May 23 10:27 dev/null

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>