Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

How to unpack/repack initramfs in zImage

OP dkcldark

7th September 2010, 10:52 PM   |  #1  
OP Member
Thanks Meter: 13
 
79 posts
Join Date:Joined: Jul 2010
Here we go.

I'm saying that I'm not a very good developer so this information could be messy, contain unnecessary works or a bit wrong.
And also I'm not sure if this method will work with every zImage from every device.

I've tested with
I9000-JM2/JM7 : ECLAIR
JPC : FROYO
and they work like a charm.

OK, now we start.

Download this file

http://www.multiupload.com/GSVLO15WDL

It has cross-compiler in it so that it's slightly big.

------------------------------------------------------------

This is basically for devs so I won't tell you specifically. (or I can't...maybe)



1. Extract cpio'ed initramfs file from zImage.

## EDIT : In order to extract initramfs.cpio, go through from step4 to step11.
A file which starts with "30 37 30" means that this is a cpio'ed file.
So, trim the Image-Orig file from the beginning to the point just before "30" then, you've got a cpio compressed file.
You can now simply decompress it.

Quote:

cat initramfs.cpio | cpio -i --no-absolute-filenames



2. Decompress and edit these files. Make sure you shouldn't go over the original size. (simply, I removed redbend_ua in /sbin forder)
3. Recompress to cpio. ( I've used scripts/gen_initramfs_list.sh which is in the kernel source for a safe bet)

## EDIT : What I've done is here. chdir to "zImage_repack/2.6.29" forder then

Quote:

/bin/bash scripts/gen_initramfs_list.sh -o usr/initramfs_data.cpio -u 0 -g 0 /home/zero/Desktop/JPC/initramfs/i9000_initramfs_list







4. open the zImage with a hexeditor.
5. find "1f 8b 08".
6. cut off from the beginning to the point just before the "1f" so that this file begins with "1f 8b 08".
7. save as anyname.gz
8. in terminal >>>> gunzip anyname.gz

Now, you've got an Image file. I'll call this as an Image-Orig.

9. open the Image-Orig file with a hexeditor.
10. remember the entire size of this file. One of mine was "0xb9a5df".
11. find "30 37 30" hexademical code and "TRAILER!!!" text.
12. cut off from the first "30" to the last "!".
an example is here



13. open the cpio file you had recompressed with the hexeditor.
14. paste this codes to the exactly same place where the former initramfs was, in Image-Origin file. (Up to now, I feel like English is more difficult than this trick...sigh, sorry for my bad english!)
15. Almost done. We're gonna make the modified Image file's size identically to the Image-Orig. It's simple. just fill the hole with a bunch of NULLs. put your finger on "0" button and have a little sleep.


I think I need a visual assistant.






















Save it as "Image".


At this point, you should have an Image file which size is the same as Image-Orig.


Now open the file you've downloaded at the first.

there is a forder called place_Image_here

yeah, place the Image there and execute the "Repack_kernel.sh" file.

In several seconds, you'll have a zImage file.

I'm so tired and I can't last this writing so, if you have any question, I'll give you a reply.

Thanks!




## PLUS : I've attached the modified JPC kernel which supports /system/etc/init.d/userscripts.sh

It's named JPC_modified_kernel.tar.zip and you should take the ".zip" off in order to use with Odin.

## PLUS2 : I've compiled gnu_parted! also attached. good luck, RyanZA!
-info : GNU parted v2.2 (original version, didn't apply bug fixes.)
disabled device-mapper and read-line while compiling, does this matter?






Attached Files
File Type: zip JPC_modified_kernel.tar.zip - [Click for QR Code] (4.45 MB, 1195 views)
File Type: zip gnu_parted.zip - [Click for QR Code] (2.89 MB, 1004 views)
Last edited by dkcldark; 8th September 2010 at 02:01 AM.
The Following 10 Users Say Thank You to dkcldark For This Useful Post: [ View ]
7th September 2010, 11:08 PM   |  #2  
Senior Member
Flag JHB
Thanks Meter: 743
 
2,021 posts
Join Date:Joined: Jan 2006
...Wow.

Good job, sir. Good job.

Quote:
Originally Posted by dkcldark

1. Extract cpio'ed initramfs file from zImage.

I mostly followed along through the later steps and I don't see any issues, but unfortunately the first step leaves me clueless. How would you do that?!
The Following User Says Thank You to RyanZA For This Useful Post: [ View ]
8th September 2010, 12:24 AM   |  #3  
Recognized Developer
Thanks Meter: 357
 
10
569 posts
Join Date:Joined: Jul 2010
@dkcldark: good job. nice pictures.



Thats what i do to extract initramfs, basically the same. But i have added instructions to extract from kernels compiled by kernel devs here at xda.
(kernels with gzipped cpio)

Uncompressing the zImage:
$ grep -a -b --only-matching $'\x1f\x8b\x08\x00' < zImage
12896:�
$ dd if=zImage bs=1 skip={number from above command} | zcat - > Image

if not gzipped cpio (this one for stock-samsung-kernel):
$ grep -a -b --only-matching '070701' Image
$ dd if=Image bs=1 skip={your first matching number from line above} > initramfs.cpio
else if cpio is gzipped:
$ grep -a -b --only-matching $'\x1f\x8b\x08' < Image
84448:�
2639420:�
Only the first number is interesting, so we can fetch the initramfs:
$ dd if=Image bs=1 skip={your first number, in my case 84448} | gzip -d -c - > initramfs.cpio

Now extract initramfs.cpio:
$ mkdir somedirtoextract
$ cd somedirtoextract/
$ cpio -i --no-absolute-filenames < ../initramfs.cpio

If you want to have device nodes created, make sure you do it as root:
sudo cpio -i --no-absolute-filenames < ../initramfs.cpio
Last edited by neldar; 8th September 2010 at 12:28 AM.
The Following User Says Thank You to neldar For This Useful Post: [ View ]
8th September 2010, 02:10 AM   |  #4  
xan's Avatar
Recognized Developer
Flag Crack-ow
Thanks Meter: 457
 
1,399 posts
Join Date:Joined: May 2006
Donate to Me
More
I'm stunned...
8th September 2010, 12:52 PM   |  #5  
Member
Thanks Meter: 3
 
70 posts
Join Date:Joined: Jul 2010
wondewring if theres a way to change this:

c002e660 T __initramfs_start
c035d949 T __initramfs_end
8th September 2010, 01:31 PM   |  #6  
Member
Thanks Meter: 1
 
49 posts
Join Date:Joined: Jul 2010
I've compiled a short page about extracting initramfs some time ago here: http://forum.xda-developers.com/wiki...fs_from_zImage
(also accessible from the SGS wiki page).

Please feel free to extend this page with more instructions / scripts on how also re-pack it back.
The Following User Says Thank You to gshklover For This Useful Post: [ View ]
21st September 2010, 09:38 PM   |  #7  
FadeFx's Avatar
Senior Member
Flag Vienna
Thanks Meter: 1,991
 
6,800 posts
Join Date:Joined: Mar 2010
Donate to Me
More
hi dkcldark, as i sayed i try to do this with the kernel from i5800 galaxy3, but ran into first problem after saving the image-orig.gz, i get a gz filke with a file image-orig with 0 bytes size and extracting results in an error.
hope you can somehow help me. like i sayed already, i am not really used to such blackbelt stuff, just trying to get a working lagfix for the g3
21st September 2010, 10:55 PM   |  #8  
OP Member
Thanks Meter: 13
 
79 posts
Join Date:Joined: Jul 2010
Quote:
Originally Posted by FadeFx

hi dkcldark, as i sayed i try to do this with the kernel from i5800 galaxy3, but ran into first problem after saving the image-orig.gz, i get a gz filke with a file image-orig with 0 bytes size and extracting results in an error.
hope you can somehow help me. like i sayed already, i am not really used to such blackbelt stuff, just trying to get a working lagfix for the g3


hello would you give me the kernel file please?
I'll have a look and give you an instruction
22nd September 2010, 08:41 AM   |  #9  
FadeFx's Avatar
Senior Member
Flag Vienna
Thanks Meter: 1,991
 
6,800 posts
Join Date:Joined: Mar 2010
Donate to Me
More
here you go: http://archiv.to/GET/FILE4C99994EB1316

thanx for help...
28th September 2010, 12:30 AM   |  #10  
xan's Avatar
Recognized Developer
Flag Crack-ow
Thanks Meter: 457
 
1,399 posts
Join Date:Joined: May 2006
Donate to Me
More
As far I understand this method -> Could we have JPK's kernel initramfs repacked in similar manner, to include EXT2/4 support?

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes