FORUMS
Remove All Ads from XDA

[script] repack-zImage.sh: Unpack and repack a zImage without kernel source, V. 5

158 posts
Thanks Meter: 78
 
By mizch, Senior Member on 5th January 2011, 03:58 PM
Post Reply Email Thread
4th February 2013, 12:43 PM |#61  
lynxdog's Avatar
Senior Member
Flag New Zealand
Thanks Meter: 66
 
More
Dont sh just bash
Dont use sh to execute the script, use bash. I know it's an old thread but hey....
5th July 2014, 09:44 PM |#62  
Account currently disabled
Flag Kiev
Thanks Meter: 57
 
More
Could someone help to extract. Script tells that file is not found but it's in the directory with the script and utils.
Attached Files
File Type: zip zImage.zip - [Click for QR Code] (4.06 MB, 125 views)
7th July 2014, 04:49 AM |#63  
DoR2's Avatar
Senior Member
Flag Snezhinsk
Thanks Meter: 105
 
More
Quote:
Originally Posted by Vlaaaad

Could someone help to extract. Script tells that file is not found but it's in the directory with the script and utils.

I have tried to unpack your zImage but I got an error
Code:
Separating gzipped part from trailer in 'piggy.gz+piggy_trailer'
Trying size: 2131356  3197034  3729873  3996293  4129503  4196108  4229411  4246063  4254389  4258552  4260634  4261675  4262196  4262457  4262588  4262654./repack-zImage.sh: line 284: [: : integer expression expected

padding check (may take some time): 14

Found uncompressed ramdisk.
Detecting padding (may take some time): 4188
Unpacking initramfs
cpio: Malformed number rrect 
cpio: Malformed number cpio m
cpio: Malformed number ethod 
cpio: Malformed number used: 
cpio: Malformed number use -H
cpio: Malformed number  newc 
cpio: Malformed number option
cpio: Malformed number o cpio magi
cpio: premature end of file

repack-zImage.sh: cpio -t failed.
Terminated
Also I can recommend running this command in order to get full access to all files in this directory.
Code:
chmod 777 *
BTW, you can try to use ArchiKitchen in order to unpack zImage and work on your ROM. Good Luck!
12th January 2015, 12:57 AM |#64  
gekkehenkie11's Avatar
Inactive Recognized Developer
Thanks Meter: 5,623
 
More
This tool seems outdated, doesn't work on modern kernels including DT it seems ...
27th February 2015, 10:13 AM |#65  
Member
Thanks Meter: 2
 
More
It should work on a kernel of galaxy gear s watch?
28th February 2015, 07:23 PM |#66  
Member
Thanks Meter: 2
 
More
It should work on a kernel of galaxy gear s watch?

Quote:
Originally Posted by mizch

repack-zImage.sh is a bash script for Linux which allows you to unpack a kernel image (zImage) for modification and repack it afterwards into a new working kernel image.

You don't need a kernel tree for this program nor a compiler. It should work with any zImage that contains an initramfs, for whatever phone, operating system or CPU architecture you like.

My main purpose when I wrote it was to modify the initramfs of leaked Samsung i5800 firmware for which no kernel source is available.

Usage:
=====

Put the unzipped script into some directory along your $PATH (e.g., /usr/local/bin). Put the unpacked files from initramfs_utils.zip into /usr/local/bin.

Then simply run 'repack-zImage.sh -u' with your zImage in the current directory and it will create a directory named 'zImage_unpacked' which contains the unpacked blocks of your zImage. Refer to the comments near the start of the program to identify which file corresponds to which fragment of the original zImage. (The file name of the zImage should be "zImage". If it isn't, pass it as the only non-option argument. The subdirectory's name will change accordingly.)

Most notably, there will be a directory 'initramfs' in there, which contains all files from the original initramfs in their original tree. You can modify the contents as you like, but keep in mind that your initramfs cannot grow larger than the space reserved for it in the original zImage. So you're restricted to relatively small changes which should, however, satisfy many needs. You always can call a script or executable on some other partition (including the SD card if already mounted) if you need more room for your modifications.

After your modifications are done, cd back to the directory which contains zImage and zImage_unpacked and run 'repack-zImage.sh -p' to start the packing process.

This will create a directory called 'zImage_packing' which contains your new zImage (and a zImage.tar for loaders like ODIN). It will emit (between others) one or two messages about a padding being done and about how many bytes were padded. This number (or the lower number of the two) is an indication about how many compressed bytes are left for further additions to the initrd.

If your initramfs (or some other modified part) grows too large, the script will abort with an appropriate error message.

In initramfs-utils.zip, three programs are provided. They should be copied to /usr/local/bin:
* cpio_set0. This is a slightly modified cpio (compiled for 32 bit Linux). repack-zImage.sh will run without it, but there may be slightly more room in your initramfs if you use the modified one. It sets all file times in the archive to 0 (epoch), thus yielding better and consistent compression results. Else, the size of the compressed initramfs will differ from invocation to invocation due to differing atimes. Put it somewhere along your $PATH (e.g., /usr/local/bin).
* gen_init_cpio and
* gen_initramfs_list.sh. These are utilities copied from a kernel tree and used to support creation of an initramfs (in certain modes).

'repack-zImage.sh --help' will output usage information.


Happy hacking,

mizch


Current Version: 6
2011-05-03
('repack-zImage.sh --version' will output version information.)

- added support for lzma compressed ramdisks (both directions)

Version 4
2011-02-17

- Workaround for ambiguous gunzip result, see post #20
- Some code cleanup + CLI cleanup
- better error detection

Version 3
2011-01-06

- now also works with unzipped initramfs withing gzipped zImage part (i.e., all kinds of zImages)

Version 1
2011-01-05

- initial version. Works only for gzipped initramfs within gzipped zImage (e.g., G3 Eclair kernels)

-----------------------
repack-zImage.zip contains version 4 of the script.
For the newest version, download repack-zImage.v6.zip and initramfs-utils.zip.

15th June 2015, 11:53 PM |#67  
gekkehenkie11's Avatar
Inactive Recognized Developer
Thanks Meter: 5,623
 
More
Still no new kernel unpacker tool ?

---------- Post added at 11:53 PM ---------- Previous post was at 11:03 PM ----------

Actually I just found out how to decompress a modern kernel Just search the boot.img for 894C5A4F (that's 0x89 followed by "LZO"). In my case I needed the second hit (after some ascii text 'System halted' etc). So cut everything off before that, save it with a .LZO extention and you can simply unpack it with an LZO unpacker
7th July 2016, 11:29 AM |#68  
Junior Member
Thanks Meter: 0
 
More
in -p option, tar command will failed if your image is not named as zImage
28th July 2016, 07:59 PM |#69  
Senior Member
Flag Gandhinagar
Thanks Meter: 64
 
More
repack-zImage.sh: Can't find a gzip header in file 'zImage'
please help me to solve this error i have tried 10.10 n 16.04
Attached Thumbnails
Click image for larger version

Name:	1.png
Views:	230
Size:	27.4 KB
ID:	3826621  
23rd November 2019, 09:36 AM |#70  
Sutan99's Avatar
Junior Member
Flag Brebes
Thanks Meter: 1
 
More
syntax error 100 :'( on Lubuntu
Post Reply Subscribe to Thread

Tags
kernel, zimag

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes