Question: How do I view, modify and recreate the new initrd.img on Ubuntu, Debian, CentOS, Fedora, Red-Hat, Arch Linux, or SUSE distributions?
1. How To View Content Of initrd.img file?
initrd.img is in gzip format. So move initrd.img to initrd.gz as shown below.
# cp /tftpboot/el5/initrd.img . # ls cdrom initrd.img # mv initrd.img initrd.gz
Unzip the initrd.gz file as shown below.
# gunzip initrd.gz # ls cdrom initrd
After unziping the initrd.gz file, the initrd is further in cpio ‘newc’ format. So extract the files from initrd using cpio ‘newc’ format as shown below.
Note: info cpio will give more information about ‘newc’ format.
# mkdir tmp2 # cd tmp2/ # cpio -id < ../initrd 16524 blocks
Now you can view the content of initrd.img file
# ls bin dev etc init modules proc sbin selinux sys tmp var
2. How To Modify Content of Image and Recreate New Image?
After extracting the file as shown below, make appropriate modification to any of those files. Then pack the files back into the archive using the following commands. Pack the modified files back to cpio ‘newc’ format.
# find . | cpio --create --format='newc' > /tmp/newinitrd 16524 blocks # ls /tmp/ cdrom initrd newinitrd tmp2 # ls -l /tmp/newinitrd -rw-r--r-- 1 root root 8460288 Jul 2 14:50 /tmp/newinitrd
Gzip the archive file.
# gzip newinitrd # ls cdrom initrd newinitrd.gz tmp2 # ls -l newinitrd.gz -rw-r--r-- 1 root root 6649867 Jul 2 14:50 newinitrd.gz
Move file as an image file. You can use the newinitrd.img as your new boot image.
# mv newinitrd.gz newinitrd.img # ls -l newinitrd.img -rw-r--r-- 1 root root 6649867 Jul 2 14:50 newinitrd.img
Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.Get the Linux Sysadmin Course Now!
If you enjoyed this article, you might also like..
|
|
|
|






My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about
{ 15 comments… read them below or add one }
Nice one…
Neat!
I have always done my initrd’s using Debian’s make-kpgk utils… but this hack is real neat!
Kudos for your site!
This is very useful.
@Lakshmanan, @beparas, Thanks for your comments. I’m very glad that you found this helpful.
@runlevel0, Building kernel using make-kpkg by installing ‘kernel-package’ and ‘fakeroot’ packages definitely has it’s own advantages. Thanks for bringing make-kpkg utility to our attention.
hello!
I want to know if I recreate new image file after modify something.using:
dd if=tmp2 of=newinitrd.img
I want to know It’s right or wrong?why?
very good article..
thanks.
Thank you so much for this article !
Thank you soo much!!!
This was the ticket I could modify the grub and logon screens but the boot splash that was the hard one. Not any more! I have my own theme from end to end now!
YOU ROCK!!!!!
Coog
Thanks for the article. I tend to have a use for this about once or twice a year.
The extraction can be merged into a single command, simplifying this a bit:
mkdir /tmp/initrd; cd /tmp/initrd
gunzip -c ../newinitrd.img
Hi fellas, just wanted to say I appreciate this post. I was able to prevent the loading of modules I didn’t want by changing the file under /conf in the archive. I found it easier to copy the thing to my home directory and then do all the stuff. About to see if I can use XZ to compress the image and make it take up less space ( I know it’s pointless but I don’t care
). Thank you for the post. I now have more useful tools 
-Dave
Thanks! This saved my day.
Just fixed one virtual machine with this information. Copied initrd from other virtual machine and then edited initrd to fit in vm configuration. Needed to edit run_all.sh and config/* scripts and replace rootdevice information and filesystem type and added correct fsck.
Thanks. I wanted to inspect the contents of an initrd image and I found most of the articles on the web misleading / partially correct. Most of them either assume the image to be a gzipped image, or a cpio file or a plain image. The fact is that (at least on my Linux distro), it is a gzipped cpio archive. Your article was helpful.
Another way I could mount the image is using sysfs
ex.: mount -t sysfs initrd-2.6.18-1.2798.fc6.img drtini
A lot of information about initrd/initramfs is available at http://en.wikipedia.org/wiki/Initrd. This article explains the old initrd format (compressed image) and the newer initramfs format (cpio archive – optionally compressed).
Nice one