I have written a customized shell script(command) ,which i want to put in initrd /bin and then, i want it to be copied to Linux OS /opt/xyz directory .Where xyz is customized directory created during installation.

How can i achieve this task.


1 Answer 1


How to ?

get a sample redhat initramfs

cp /boot/initramfs-2.6.32-220.el6.x86_64.img initramfs.img

what have we got ?

  • initramfs.img: gzip compressed data, from Unix, last modified: Thu Oct 22 07:04:25 2015, max compression

gunzip it

gunzip < initramfs.img > initramfs.stage1
  • initramfs.stage1: ASCII cpio archive (SVR4 with no CRC)

extract it

cpio -icv < initramfs.stage1
(lots of line)
96258 blocks

add my stuff

mkdir opt/xyz
date > opt/xyz/foo.txt

no leading / !!

remake the cpio (I delete initramfs.* files)

find . -type f -print | cpio -ocv > ../newinitram.stage2
(lots of lines)
96186 blocks

what have we got ?

  • ../newinitram.stage2: ASCII cpio archive (SVR4 with no CRC)

now, compress it.

gzip -9 < ../newinitram.stage2 > newinitrd.stage3
  • newinitrd.stage3: gzip compressed data, from Unix, last modified: Sat Dec 19 06:32:08 2015, max compression

now, booting your kernel should be easy.

  • Thanks.So, if i have iso image ,then how can i extract initrd and again compress it and put it back to iso .So,that during installation my changes will be effective.
    – Gaurav KS
    Dec 20, 2015 at 8:12
  • 0 - Given that you want to edit initrd, I thought you know how to build a iso file/disk, however you are not intending to put a whole application in initrd ? 1- I don't have my iso building scripts at hand, I'll be replying tomorrow. 2- If you feel this question as helpfull you might gav point.
    – Archemar
    Dec 20, 2015 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.