change initramfs by hand?


 
Thread Tools Search this Thread
Operating Systems Linux Debian change initramfs by hand?
# 1  
Old 12-14-2008
Tools change initramfs by hand?

What's the correct way to change the initramfs file that's used during boot?
I know that it's a gzipped cpio archive, but when I gunzip, extract, re-archive (without changing any files), and gzip, then the result is that the system does not boot any more. And I even set the cpio archive type.

Do I need special tools for the initramfs? There are progs like update-initramfs but the point is that I need to put in files that were *not* put in by the tools that originally created the initramfs.
# 2  
Old 12-15-2008
Not special tools, per se... First you gunzip it, like you said. What method did you use to extract/archive? Usually, one would do:
Code:
mkdir /tmp/initrd
cd /tmp/initrd
gunzip -c Initrd.img.gz | cpio -id 

# make changes to /tmp/initrd directory
find . | cpio -o | gzip -c >/boot/initrd.new.img

# 3  
Old 12-15-2008
Thanks otheus! I tried that (without making changes to the files in the /tmp/initrd directory), and I changed the link in /boot to point to initrd.new.img.
Now I get the following error during boot:

Code:
RAMDISK: Compressed image found at block 0
RAMDISK: incomplete write (-28 != 32768) 8388608
List of all partitions:
No filesystem could mount root, tried:
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

And there the computer hangs. Not even Ctrl-Alt-Del reboots it. Poweroff is needed.
# 4  
Old 12-15-2008
The method I described works as of Linux 2.6.13 (or before FC3) If you are using an older version (uname -k) perhaps you have to create a filesystem. See "Manually building a custom initial RAM disk" at Linux initial RAM disk (initrd) overview.

Code:
$ mkdir /tmp/initrd.tmp ; cd /tmp/initrd.tmp
$ <extract>
$ du -sk . 
$ # use size reported above for: $blocks
$ dd if=/dev/zero of=/tmp/initrd.img bs=1024 count=$blocks
$ /sbin/mke2fs -F -m 0 -b 1024 /tmp/initrd.img $blocks
$ mount /tmp/initrd.img /mnt/initrd -t ext2 -o loop=/dev/loop0

If that works, copy the files from /tmp/initrd.tmp into /mnt/initrd. Afterwards:
Code:
$ umount /mnt/initrd
$ gzip /tmp/initrd.img

Now move it to /boot. Good luck!
# 5  
Old 12-15-2008
Thanks for the help otheus. I appreciate.

Quote:
Originally Posted by otheus
The method I described works as of Linux 2.6.13 (or before FC3) If you are using an older version (uname -k) perhaps you have to create a filesystem.

I have kernel 2.6.26.

The ibm web page (initrd overview) is really well made, but it's partially obsolete (as they say themselves: "up to FC3"; it's also 2.5 years old).

I tried the code you suggested anyway; every step of the initrd creation process works well, but the system won't boot. With both methods (this and the one you suggested earlier) I get the following error during boot:

Code:
RAMDISK: Compressed image found at block 0
RAMDISK: incomplete write (-28 != 32768) 8388608
List of all partitions:
No filesystem could mount root, tried:
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

Which is probably an improvement over the previous error message which I got before posting here for the first time:

Code:
Failed to execute /init
Kernel panic - not syncing: No init found. Try passing init= option to kernel.

So I guess I'm closer, but not there yet...
# 6  
Old 12-16-2008
OK, so a modern kernel, so the first method should be enough.

Could you post your grub.conf file please?
# 7  
Old 12-16-2008
Quote:
Originally Posted by otheus
Could you post your grub.conf file please?
Sure, but I don't think the grub.conf matters too much; it boots the original initrd just fine, and I don't modify any grub files when trying the new initrd.

BTW where is grub.conf? The only grub files I see are in /boot/grub, and the only human-readable ones are "default", "device.map" and "menu.lst". The first is empty except comments, the second only contains the lines

(hd0) /dev/hda
(hd1) /dev/sda

but seems to be unimportant as the unmodified initrd boots just the same when switching this to

(hd0) /dev/sda
(hd1) /dev/hda

and the third contains the usual kernel and initrd config, but it boots the unmodified initrd fine and I never modify it. Instead I change the link initrd.img in /boot to point to the modified initrd. There's still a grub entry using an initrd called initrd.img-2.6.26-1-686 which I never modify, and that always boots. Given that initrd.img-2.6.26-1-686 and the unmodified initrd.img are binary equal, the file menu.lst probably isn't the problem either.

Something else occured to me: do I need to specify the --format option in cpio? E.g. change from "bin" to "newc" format? Because when I look at the (gunzipped) initrd in boot with "file", it says:

"ASCII cpio archive (SVR4 with no CRC)".

But this is not the default which cpio creates.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Just want to ask if there is a shorter hand to doing this one liner

Hi all, In Oracle, I am using SQL*Plus and selecting all rows in a table and spooling to a file as pipe delimited. I have to use pagesize 0 but unfortunately, using this option excludes the header and I can't get around having it to display the header fields. So to get around this, I have to... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. UNIX for Beginners Questions & Answers

Why bind to LiveCD /proc before building initramfs ?

Imagine I have an unbootable system where I need to update the kernel image using update-initramfs. I have seen numerous examples online which show the following $ mount -t proc none /mnt/ubuntu/proc $ mount -o bind /dev /mnt/ubuntu/dev $ mount -o bind /sys /mnt/ubuntu/sys After that we... (8 Replies)
Discussion started by: sreyan32
8 Replies

3. Shell Programming and Scripting

Merge left hand strings mapping to different right hand strings

Hello, I am working on an Urdu to Hindi dictionary which has the following structure: a=b a=c n=d n=q and so on. i.e. Headword separated from gloss by a = I am giving below a live sample بتا=बता بتا=बित्ता بتا=बुत्ता بتان=बतान بتان=बितान بتانا=बिताना I need the following... (3 Replies)
Discussion started by: gimley
3 Replies

4. Debian

Only have initramfs now...

Long story short, I had a ps3 with both Lenny and Sid repositories. Knowing this is a bad idea and that Lenny is being deprecated I decided I wanted to move everything to Sid. I changed my repos and ran apt-get-update, upgrade, dist-upgrade. Had one warning during the apt-get upgrade that... (0 Replies)
Discussion started by: Azrael
0 Replies

5. Linux

initramfs on 2.4 kernel

Is there a patch available to support initramfs on the 2.4 kernel? We can't upgrade to 2.6 for legacy purposes. All I found on google were early references to how initramfs is better than the 2.4 initrd. Thanks much! (0 Replies)
Discussion started by: amoeba
0 Replies

6. Shell Programming and Scripting

AWK how to strip from right hand side

guys, i am writing a .ksh file to ssh to a remote machine and change all occurances of .ixf to .WIP like this : -->>> for i in *.ixf do echo $i done mv $i $i.WIP exit <<--- --> this returns .ixf.WIP - i can live with that. then i need to sftp from another remote machine, copy the files... (5 Replies)
Discussion started by: angelolamberti
5 Replies

7. Shell Programming and Scripting

Need a hand. Please?

i have a script in sh. with awk, e.g. want to list all the contents of a subdirectory an a tabular way. ej: outoput directory1 subdirectory1 subdirectory2 subdirectory3 file1 filen file2 filez file2 ... filen+1 ... (1 Reply)
Discussion started by: alexcol
1 Replies

8. Shell Programming and Scripting

How to get the most left hand string ??

Hi, I remember once seeing a way to get the left most string in a word. Let's say: a="First.Second.Third" (separated by dot) echo ${a#*.} shows --> Second.Third echo ${a##*.} shows --> Third How do I get the the left most string "First" Or "First.Second" ??? Tried to replace #... (2 Replies)
Discussion started by: jfortes
2 Replies

9. UNIX for Dummies Questions & Answers

Give us a hand

How do you get an awk output into columns i.e. awk (print $1,$2,$3) doesn't come out into nice columns but lots of lines of txt want something more like. I am crap at unix so give me a hand thx Rich (3 Replies)
Discussion started by: RichardB
3 Replies
Login or Register to Ask a Question