Modifying initrd.img

Sometimes you might want to alter the content inside initrd.img for many reasons…

Using mkinitrd might sound like the obvious solution, but it doesn’t do much except for boot time drivers…

But assume you want to embed a kick start file inside the installer’s initrd.img, let’s take this for example…

Installing a new version of Linux, on a machine that already has Linux running…

So, you have more than 1 NIC on the machine and you try the kickstart, install will pause waiting for you to choose which NIC to use, and it won’t go anywhere until you give it an answer…

The only way to overcome this is by include the kickstart file within the initrd…Initrd files are just files archived with cpio and compressed with gzip…

So the following set of commands should do the trick:

mv initrd.img initrd.img.gz

gunzip initrd.img.gz

mkdir initrd

cd initrd && cpio -i –make-directories < ../initrd.img

vi ks.cfg

Now paste your kickstart file content, and add a line similar to this one in the install directive, please note this is one continuous line, not two lines…

network –device=eth0 –bootproto=static –ip= –netmask= –gateway= –nameserver=

After you’re happy with your kick start file, save it and continue with these commands:

(find . | cpio –quiet -c -o) > ../initrd.img

cd .. && rm -rf initrd

gzip initrd.img

mv initrd.img.gz initrd.img

Now you set the value of “ks=” to “file:/ks.cfg” instead of the URL value…

These are the example lines needed for installation via grub for an existing running OS, assuming I’ve put the files in /dev/sda1 mounted as /boot:

title Installer

root (hd0,0)

kernel /vmlinuz ks=file:/ks.cfg

initrd /initrd.img

And you’re done…


3 Responses

  1. I know the above was just an example, but you don’t need to put the ks.cfg file (kickstart file) in the initrd image when you have more than one ethernet interface. There are directives you can pass to the kernel at boot time, like “ksdevice=eth4” to specify that, and you can point to your ks.cfg file on an NFS share somewhere. You just need to make sure that what you pass at boot time matches what you have in your ks.cfg file. They don’t HAVE to match, but generally you want them to. If you’re not using DHCP, you can add directives for a static IP, gatway device, etc. too.

    • Thanks for the tip, hope someone had pointed this to me earlier :), in fact that was the only way I knew then to do the job…
      Once again, thanks very much for the tip…

  2. […] boot time options… Posted on March 15, 2010 by smshaker In a previous post, a friend replied that I didn’t really need to modify initrd.img to embed ks.cfg just because I […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: