Oded
Oded

Reputation: 31

How can I repack initramfs image on RHEL7?

On RHEL 7 the initramfs image file format changed. To unpack the image the skipcpio is needed. for example

/usr/lib/dracut/skipcpio /boot/initramfs-3.10.0-957.el7.x86_64.img | gunzip -c | cpio -idmv

I succeeded to unpack the image with the command above but I cannot pack it back. The old way (like it was on RHEL 6) is not working (

find . | cpio -o -c | gzip -9 > /boot/new.img

Is it possible to pack the image back on RHEL7?

Thanks

Upvotes: 0

Views: 2038

Answers (2)

Michael Yuniverg
Michael Yuniverg

Reputation: 107

I got a solution when RHEL7 has the .img file packed in more complex way. Hints to its structure were described in https://ahelpme.com/linux/tips/unpack-centos-7-initramfs-file-with-and-without-dracut-skipcpio/, however there were no instructions for repacking after modification. Here I show the whole process:

cd /tmp
rm -f tryMe.img
rm -f initramfs-tmp.img
rm -rf cc
rm -f modified.gz
mkdir cc
cd cc
cat /boot/initramfs-3.10.0-1062.4.1.el7.x86_64.img | cpio -idmv # note number of blocks in 
                                                                # output; I assume 4976
find . | cpio -o -H newc > /tmp/tryMe.img
rm -rf *
dd if=/boot/initramfs-3.10.0-1062.4.1.el7.x86_64.img of=../initramfs-tmp.img bs=512 skip=4976
zcat ../initramfs-tmp.img | cpio -idm
find . | cpio --create --format='newc' > /tmp/modified
gzip -9 /tmp/modified
cat /tmp/modified.gz >> /tmp/tryMe.img
#backup your original somehow and then
mv /tmp/tryMe.img /boot/initramfs-3.10.0-1062.4.1.el7.x86_64.img

Upvotes: 2

Oded
Oded

Reputation: 31

The packing is the same as old Red Hat Enterprise Linux (RHEL) versions:

find . | cpio -o -H newc > ../initramfsFile

gzip -c ../initramfsFile > initramfsFils.img

Upvotes: -1

Related Questions