5,599,254 Members 37,419 Now Online
XDA Developers Android and Mobile Development Forum

How to unpack/repack initramfs in zImage

Tip us?
 
dkcldark
Old
(Last edited by dkcldark; 8th September 2010 at 01:01 AM.)
#1  
Member - OP
Thanks Meter 12
Posts: 79
Join Date: Jul 2010
Default How to unpack/repack initramfs in zImage

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, 1068 views)
File Type: zip gnu_parted.zip - [Click for QR Code] (2.89 MB, 900 views)
The Following 10 Users Say Thank You to dkcldark For This Useful Post: [ Click to Expand ]
 
RyanZA
Old
#2  
Senior Member
Thanks Meter 726
Posts: 2,021
Join Date: Jan 2006
Location: JHB
...Wow.

Good job, sir. Good job.

Quote:
Originally Posted by dkcldark View Post
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: [ Click to Expand ]
 
neldar
Old
(Last edited by neldar; 7th September 2010 at 11:28 PM.)
#3  
Recognized Developer
Thanks Meter 349
Posts: 569
Join Date: 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
The Following User Says Thank You to neldar For This Useful Post: [ Click to Expand ]
 
xan
Old
#4  
xan's Avatar
Recognized Developer
Thanks Meter 454
Posts: 1,399
Join Date: May 2006
Location: Crack-ow

 
DONATE TO ME
I'm stunned...
Feeling like translating something? here you go
Voltage Control Lite/Extreme 4.9.8 *Siyah support + Profiles + Widget + CPU history*: -> Take control of your OC/UV for Galaxy S OC kernels. Android Market / YAAM
ExTweaks / ExTweaks Plus 0.20 *Universal Tweaks Interface frontend for Siyah kernel*

14apr: [Froyo]Insane OC/UV kernel K13E
What is your OC result?
 
husq510
Old
#5  
Member
Thanks Meter 3
Posts: 70
Join Date: Jul 2010
wondewring if theres a way to change this:

c002e660 T __initramfs_start
c035d949 T __initramfs_end
 
gshklover
Old
#6  
Member
Thanks Meter 1
Posts: 49
Join Date: 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: [ Click to Expand ]
 
FadeFx
Old
#7  
FadeFx's Avatar
Senior Member
Thanks Meter 1839
Posts: 6,501
Join Date: Mar 2010
Location: Vienna

 
DONATE TO ME
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
 
dkcldark
Old
#8  
Member - OP
Thanks Meter 12
Posts: 79
Join Date: Jul 2010
Quote:
Originally Posted by FadeFx View Post
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
 
FadeFx
Old
#9  
FadeFx's Avatar
Senior Member
Thanks Meter 1839
Posts: 6,501
Join Date: Mar 2010
Location: Vienna

 
DONATE TO ME
here you go: http://archiv.to/GET/FILE4C99994EB1316

thanx for help...
 
xan
Old
#10  
xan's Avatar
Recognized Developer
Thanks Meter 454
Posts: 1,399
Join Date: May 2006
Location: Crack-ow

 
DONATE TO ME
As far I understand this method -> Could we have JPK's kernel initramfs repacked in similar manner, to include EXT2/4 support?
Feeling like translating something? here you go
Voltage Control Lite/Extreme 4.9.8 *Siyah support + Profiles + Widget + CPU history*: -> Take control of your OC/UV for Galaxy S OC kernels. Android Market / YAAM
ExTweaks / ExTweaks Plus 0.20 *Universal Tweaks Interface frontend for Siyah kernel*

14apr: [Froyo]Insane OC/UV kernel K13E
What is your OC result?

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes