Oddities Reading boot.img - Way Too Big and Errors In Kernel This is related to this question but as I've made some progress since and run into some rather different issues that would mean I'd essentially have to rewrite it to be a totally different question I've decided to make a new question. As in that question, some device info:


It's a BLU ADVANCE 4.0
Board is Mediatek MT6572
Android version is 4.2.2
Kernel version is 3.4.5
I do have root access


I've been trying to take a backup of certain partitions on my phone (boot.img, system.img, recovery.img) but I've run into some problems.

I've found backups online for this model, taken backups with MTK Droid Root and Tools and tried to read directly from /dev/bootimg and /dev/recovery. I've run into a few different issues. There are three main ones and I include them all here as I think they're related. I'm going to start with the one that's consistent across all of these:

Issue #1

The kernel part of my boot.img seems to be way too small (about 18.0KiB - that's not right, is it?) and ends with a bunch of error messages before the GZIP 1F8B that I think marks the start of the ramdisk. Here are the messages:

System halted.
Attempting division by 0!...
Uncompressing Linux.....
decompressor returned an error.. 
done, booting the kernel...
invalid distance too far back...
invalid distance code...
invalid literal/length code.
incorrect header check..
unknown compression method..
invalid window size.invalid block type..
invalid stored block lengths....
too many length or distance symbols.
invalid code lengths set....
invalid bit length repeat...
invalid literal/lengths set.
invalid distances set...
incorrect data check....
Out of memory while allocating output buffer....
Out of memory while allocating input buffer.
Out of memory while allocating z_stream.
Out of memory while allocating workspace....
Not a gzip file.
header error....
read error..
uncompression error........


The newlines are from me, I tried to format it as best I could. I'm a little confused about what's going on here as I'm just reading the image - there shouldn't be error messages. Am I just seeing lists of possible errors in the kernel?



Issue #2

I can't extract the contents of the ramdisk in the properly sized kernels (I want to check that the backups worked properly) as in this guide to unpacking boot images
When I run this command:

gunzip -c ../your-ramdisk-file | cpio -i


I get the following messages (a whole bunch like the first and finishing with the last two):

cpio: Malformed number (�K�����
gzip: ../ramdisk.gz: decompression OK, trailing garbage ignored
cpio: premature end of file


and no new file outputted. Note that I can unzip the file by omitting the cpio bit and redirecting the output and it will produce a file containing some recognizable text in a hex editor, so I assume the extraction was successful.



Issue #3

The boot.img read from /dev/bootimg, though it seems to be valid at the start, is way, way too big - I stopped it at 3.0GiB+. For reference the one I found online and the one I generated with MTK Droid Tools and Root are 6.0MiB. By truncating it to 500MiB I was able to find the same kernel structure as in the other ones, though I wasn't sure where the ramdisk ended so couldn't reliably check that.

I suppose my question is basically: what is wrong with my boot.img? Is it valid (despite the errors and inability to extract the ramdisk) and safe to use as a backup?
It turns out most of the problems seem to have stemmed from my trying to split the boot and recovery images in the wrong place. I was trying to extract the kernel and ramdisk at the 1F8B for gzip (the kernel before, ramdisk after), but there were several instances of 1F8B (specifically 1F8B 0800) in the hex code and the first one was not the correct one.

After splitting the image in the right place, I got a more realistically sized kernel and a ramdisk which extracted successfully.

I was also able to get boot.img and recovery.img via adb from /dev/bootimg and /dev/recovery by explicitly limiting the size as per aureljared's comment on the question regarding my original problem:

dd if=/dev/bootimg of=/where/to/store/it bs=6291456 count=1


Though the images still contain the error messages, I think they're probably supposed to be there as I've found them in some other known good images online.

Note that I haven't truly tested the images are valid as they're just backups and the only way to test them is to flash them and thus potentially brick my phone if they're bad. I'm fairly confident this problem is solved since I can extract the ramdisk, though.