Extracting/Recreating RHEL/Centos6 initrd.img and install.img
A quick note about extracting and recreating RHEL6 or Centos6 (and their derivations) installation media components:
Initrd:
Extract:
mv initrd.img /tmp/initrd.img.xz
cd /tmp
xz --format=lzma initrd.img.xz --decompress
mkdir initrd
cd initrd
cpio -ivdum < ../initrd.img
Archive (after you applied your changes):
cd /tmp/initrd
find . | cpio -o -H newc | xz -9 --format=lzma > ../new-initrd.img
/images/install.img:
Extract:
mount -o loop install.img /mnt
mkdir /tmp/install.img.dir
cd /mnt ; tar cf - --one-file-system . | ( cd /tmp/install.img.dir ; tar xf - )
umount /mnt
Archive (after you applied your changes):
cd /tmp
mksquashfs install.img.dir/ install-new.img
Additional note for Anaconda installation parameters:
I did not test it, however there is a boot flag called stage2= which should lead to a new install.img file, other than the hardcoded one. I don’t if it will accept /images/install-new.img as its flag, but it can be a good start there.
One more thing:
Make sure that the vmlinuz and initrd used for any custom properties, in $CDROOT/isolinux do not exceed 8.3 format. Longer names didn’t work for me. I assume (without any further checks) that this is isolinux limitation.
# mount -o loop install.img /mnt
mount: you must specify the filesystem type
This trick will work for ISO. The initrd.img is not an ISO. It is commonly (today) a compressed CPIO archive.
I am not sure if it is a typo or formatting issue.. If you copy paste below, it may throw error.. make sure it is –format and — decompress ( dash dash)
xz –format=lzma initrd.img.xz –decompress
This is because of the blog formatting. The hypen is UTF8 one, and not the regular minus sign you are used to. This causes the problem. I will see how I can fix it for this post.
You can use unsquashfs for extracting as well:
sudo unsquashfs install.img
sudo mkdir /mnt/installimg/
sudo mount -o loop squashfs-root/LiveOS/rootfs.img /mnt/installimg/
Much more straightforward.
Thanks! Always good to learn new stuff 🙂