[DEV][TOOLS] Unpack Repack boot.img (Kernel) Files And Modify Ramdisk

Search This thread

iridaki

Retired Forum Moderator
Feb 21, 2007
4,532
5,190
37
Edinburgh, Scotland
Hello!

This is -at least I hope it is- an easy to follow guide on how to unpack boot.img files (aka custom kernels) and modify the ramdisk.
Now, why would you want to do that?
First and simplest thing that comes to mind is for editing the kernel boot logo (the one that appears before the boot animation).
There are also a lot of other things you can edit in the ramdisk, but they require a bit more advanced knowledge, so we won't talk about them here.

Requirements:
1. Linux (any form will do, for example virtual box etc)
2. Perl (already included in Ubuntu, me thinks)
3. The Xperia Boot Tools package attached in this post
4. The mkbootimg binary (I already compiled it for Linux x86 and included it in the attachment)
5. Reading this post VERY VERY VERY carefully :D

Step 1: The mkbootimg binary

Let's install mkbootimg (we need it in order to repack the boot.img).
In a terminal window, cd to the directory where you extracted the mkbootimg file and type:

Code:
[B][I]sudo cp mkbootimg /bin/[/I][/B]

And then

Code:
[B][I]sudo chmod 755 /bin/mkbootimg[/I][/B]

Done!

* After first command, terminal will ask for your user password, type it, press enter and the command will be executed immediately.

Step 2: Splitting the boot.img

At this point, we need a boot.img file to play with.
Pick your favorite custom kernel and get the .img.
Place it in a folder along with the 2 perl scripts from the attached package.
In a terminal window, cd to the above-mentioned folder.
Next, type this command:

Code:
[B][I]perl split_bootimg.pl boot.img[/I][/B]

The command will return something like this:
Page size: 2048 (0x00000800)
Kernel size: 3132176 (0x002fcb10)
Ramdisk size: 3484496 (0x00352b50)
Second size: 0 (0x00000000)
Board name:
Command line:
Writing boot.img-kernel ... complete.
Writing boot.img-ramdisk.gz ... complete.


Now the kernel is successfully extracted to your current directory.
It consists of 2 files: boot.img-kernel and boot.img-ramdisk.gz.

Step 3: Unpacking ramdisk

So we unvealed the ramdisk in our previous step but it is still of no use to us, so we need to un-gzip and then un-cpio it.
In the same terminal window as before, type:

Code:
[I][B]mkdir ramdisk[/B]

Code:
[B]cd ramdisk[/B]

Code:
[B]gzip -dc ../boot.img-ramdisk.gz | cpio -i[/B][/I]

Last command will return something like:

10503 blocks

Our ramdisk is unpacked now in the newly created /ramdisk folder.

Step 4: Editing ramdisk files

Now you can edit the contents of the ramdisk.
BE EXTREMELY CAREFUL AND NEVER EVER DO ANYTHING "JUST 'CAUSE"... :p
You need to be fully aware of what you're doing.
Good news is, changing the logo.rle (the static boot logo image) is fairly easy.
You just need to replace it with your .rle file.
I am not going to explain how to make your own .rle files right now.
Feel free to have a look at this thread for more info.
However, I attach the stock SE boot logo in case anyone misses it when he's on custom kernel. ;)

IMPORTANT: Don't accidentally add irrelevant files to the ramdisk directory as cpio will include them too and your new boot.img will be useless.

Also, bear in mind:

there is a bug in the semc S1 bootloader... sometimes if the boot.img isnt of a correct size then the device will not boot... the workaround is to add a "filler" file (which is say 512KB file with junk data) to the ramdisk so as to increase the size of the final boot.img file...

thanks to jerpelea for this incredible tip... i must have wasted atleast 10-15 hrs trying to figure out why my kernel failed to boot :p

Step 5: Repack the ramdisk

Now that's all done, we need to pack the kernel back up into a flashable img file.
First, we will pack the ramdisk back to it's original state.
In the same terminal window as before, type:

Code:
[B][I]find . | cpio -o -H newc | gzip > ../newramdisk.cpio.gz[/I][/B]


Step 6: Repack the boot.img

In our last step, back into the terminal we go to use the "repack-bootimg" perl script that will give us our brand new boot.img.
Make sure to cd to the directory that the perl scripts are, much like in Step 1.
Type this command:

Code:
[B][I]perl repack-bootimg.pl '/.../.../.../boot.img-kernel' '/.../.../.../ramdisk' newboot.img[/I][/B]

Of course, replace /.../.../ with the path to the boot.img-kernel file and the ramdisk directory respectively.

All done! Your new img is newboot.img and is ready to be flashed! :)

ADVICE: Use fastboot boot and not fastboot flash boot the first time, to test that the new kernel boots. If all is well, proceed with the actual flashing!

FAQ:

- Can I do this on Windows?
- Not that I know of, no. You can use Vmware or VirtualBox to install a raw Ubuntu image (pure command line) on your Windows PC though.
- Great! How can I do this then?
- Wish I knew! I have a Linux partition on my PC, it has been like that forever. Google is your friend! ;)

- This is so complicated, is there an easier way? Can you make a zip for me to use in recovery?
-
censored.jpg

- OK, don't get upset. Can you do it for me?
- I will have to say no, because I know that the minute word gets out that I take requests, I will be overwhelmed.
Took me several hours to figure all this out but it will take you less than 10 minutes to do it yourself if you carefully follow the instructions.

- I think this or that is wrong and it should be like this or that.
- Thank you very much for correcting me! I am still learning! Please post your corrections here or PM me and I will update the thread ASAP! :)

References:

- HOWTO: Unpack, Edit, and Re-Pack Boot Images
- How to Port Android to Another Device
- [How-To] Make custom bootscreen/bootlogo (image to rle)/(rle to image)

Thanks to:

- Riyal for giving me the idea to get into this.
- pvyParts because without him I'd only be "pulling Irises"... :eek: :D


Cheers!
 

Attachments

  • xperiaboottools.zip
    18.8 KB · Views: 16,679
  • default_SE_bootlogo.zip
    1.3 KB · Views: 6,561
Last edited:

rashid.fairus

Senior Member
Dec 6, 2011
1,073
233
Klang
or try pendrivelinux,boot linux from windows..great tutorial,gonna try it
so everyone can be doomlord:p
question,if i manage to change boot image and repack the it back,is there any chance for me to "brick" the kernel?
Sent from my LT18i
 
Last edited:
  • Like
Reactions: iridaki

glaudrem

Senior Member
Nov 25, 2011
187
46
Valencia
Locked Bootloader

Hello Iridaki,

many thanks for your apports (this and the init.d script). I'm actually user from a Spanish forum called www.htcmania.com (you may have heard about thedr0idboy, which is a Neo developer) and we were trying to pack kernels in order to flash it in locked bootloader devices or at least try to create an Overclock module for stock kernel that can be flashed in locked devices.

Do you think we can use this to achieve this goal? I just hate Arc S with it's damn 1.4 GHz processor :S. It was released only a month after I got my Arc.

Many thanks for your time and your efforts!!


P.D: a girl developer!!!:D:D:D
 
  • Like
Reactions: iridaki

iridaki

Retired Forum Moderator
Feb 21, 2007
4,532
5,190
37
Edinburgh, Scotland
so everyone can be doomlord:p
question,if i manage to change boot image and repack the it back,is there any chance for me to "brick" the kernel?

Nah, it takes a lot more to be DoomLord..!!! ;)
If there are no errors in the cmd, boot.img should be OK.
By using flashboot boot command, the kernel is sent to the phone and it tries to boot it. It's not flashing it, so if it fails, it immediately goes back to previous kernel.
So don't worry! Imagine that until I found the correct script, I had tried more or less 10 crapernels (crappy kernels)!!! :D

iR¡D@k!* via Tapatalk
 
  • Like
Reactions: pvyParts

rashid.fairus

Senior Member
Dec 6, 2011
1,073
233
Klang
Nah, it takes a lot more to be DoomLord..!!! ;)
If there are no errors in the cmd, boot.img should be OK.
By using flashboot boot command, the kernel is sent to the phone and it tries to boot it. It's not flashing it, so if it fails, it immediately goes back to previous kernel.
So don't worry! Imagine that until I found the correct script, I had tried more or less 10 crapernels (crappy kernels)!!! :D

iR¡D@k!* via Tapatalk

looks like our themes and apps forum have a new section,kernel theming:D,,(iridaki,you have purple theme for apps and roms,how about kernel?:p:p:p)

Sent from my LT18i
 

dp94

Senior Member
Feb 22, 2011
627
123
Linz
A big thanks, iridaki!

I was looking forward to such thread.
I did also a lot of search on google too, but somehow I couldn't find any match.
I am an experienced Linux user, so that shouldn't be a problem for me.
I'll try everything this weekend.
Afaik, CWM is also stored in the kernel, so is it possible to modify it with the tool?
I don't want to have a step by step guide, just a reference would be great (of course if you know one).

Anyway, thanks for your great contributions in XDA.

Sent from my LT18i using xda premium
 
  • Like
Reactions: iridaki

theduke89

Senior Member
Feb 19, 2011
404
72
OMG... :-o Iris you are a genius.

Sent from my Arc S LT18i using Xda Premium App
 

DooMLoRD

Inactive Recognized Developer
Jul 27, 2010
13,187
39,710
Pune
Hello Iridaki,

many thanks for your apports (this and the init.d script). I'm actually user from a Spanish forum called www.htcmania.com (you may have heard about thedr0idboy, which is a Neo developer) and we were trying to pack kernels in order to flash it in locked bootloader devices or at least try to create an Overclock module for stock kernel that can be flashed in locked devices.

Do you think we can use this to achieve this goal? I just hate Arc S with it's damn 1.4 GHz processor :S. It was released only a month after I got my Arc.

Many thanks for your time and your efforts!!


P.D: a girl developer!!!:D:D:D


currently we cant use custom kernels on locked bootloader...

there is a way to make overclock module for stock kernel... i am looking into that possibility & i have contacted a few devs... i will work on it when i get time...


@Iris


there is a bug in the semc S1 bootloader... sometimes if the boot.img isnt of a correct size then the device will not boot... the workaround is to add a "filler" file (which is say 512KB file with junk data) to the ramdisk so as to increase the size of the final boot.img file...

thanks to jerpelea for this incredible tip... i must have wasted atleast 10-15 hrs trying to figure out why my kernel failed to boot :p
 

iridaki

Retired Forum Moderator
Feb 21, 2007
4,532
5,190
37
Edinburgh, Scotland
@Iris


there is a bug in the semc S1 bootloader... sometimes if the boot.img isnt of a correct size then the device will not boot... the workaround is to add a "filler" file (which is say 512KB file with junk data) to the ramdisk so as to increase the size of the final boot.img file...

thanks to jerpelea for this incredible tip... i must have wasted atleast 10-15 hrs trying to figure out why my kernel failed to boot :p

Great tip indeed!!! Added to the OP! :)
I haven't come across the issue yet because I am only editing some tweaks and the logo.rle but say someone uses a much smaller logo and deletes some scripts, would he need to use a filler file, even if it is for 20-30 KB?
THANKS!
 
Last edited:

DooMLoRD

Inactive Recognized Developer
Jul 27, 2010
13,187
39,710
Pune
Great tip indeed!!! Added to the OP! :)
I haven't come across the issue yet because I am only editing some tweaks and the logo.rle but say someone uses a much smaller logo and deletes some scripts, would he need to use a filler file, even if it is for 20-30 KB?
THANKS!

size of logo doesnt really matter... just the final size of the boot.img matters...

btw the logo.rle must have correct permissions (644)
 

iridaki

Retired Forum Moderator
Feb 21, 2007
4,532
5,190
37
Edinburgh, Scotland
size of logo doesnt really matter... just the final size of the boot.img matters...

btw the logo.rle must have correct permissions (644)

Yes, but if the logo.rle is replaced with a smaller one in size, ramdisk size is reduced accordingly, isn't it?
Permissions are taken care of while unpacking/repacking.
Overall, this guide works, since I've sorted everything out, hasn't failed me yet! :)

Afaik, CWM is also stored in the kernel, so is it possible to modify it with the tool?
I don't want to have a step by step guide, just a reference would be great (of course if you know one).

Anyway, thanks for your great contributions in XDA.

My initial response would have to be: I have no idea! :D
However, tell me what exactly do you want to edit. Images, colors, features?
I'll look into it, currently I have never been in involved with recovery. :eek:

OMG... :-o Iris you are a genius.

I have my moments. :p :p :p
 
Last edited:

LenAsh

Retired Forum Moderator
Mar 20, 2011
4,736
4,708
Midlands, UK
Presumably, kernel.sin can be renamed to boot.img for splitting without problems, or am I missing something pertinent to SE?
 

LenAsh

Retired Forum Moderator
Mar 20, 2011
4,736
4,708
Midlands, UK
Found that previously, but the repacker doesn't work. I think the script he published is a hack of something else and may have errors.
 

iridaki

Retired Forum Moderator
Feb 21, 2007
4,532
5,190
37
Edinburgh, Scotland
Found that previously, but the repacker doesn't work. I think the script he published is a hack of something else and may have errors.

Well, no, the script is OK, it's just made to work with the particular unpacker I included in the package. You need to edit it a wee bit to work with the sin unpacker. If I get some time in the weekend, I'll look into it too.


iR¡D@k!* via Tapatalk
 

LenAsh

Retired Forum Moderator
Mar 20, 2011
4,736
4,708
Midlands, UK
Magic, thanks Iris. I recall the unpacking is fine, it is just repacking that doesn't yield either a boot.img OR kernel.sin due to the mixed file names/folders etc. It's been a few months since I tried... forgive me. All I was doing at the time was taking a stock Neo kernel and making it insecure. Which is dead easy normally. done it plenty with other phones, but SE .sin files threw me.
 
Last edited:

dp94

Senior Member
Feb 22, 2011
627
123
Linz
My initial response would have to be: I have no idea! :D
However, tell me what exactly do you want to edit. Images, colors, features?
I'll look into it, currently I have never been in involved with recovery. :eek:

Just to change the colors, rename options, maybe integrate some features into one option.
I have really tried to search a lot, here in XDA & Google, but I have no idea. :eek:
 

pvyParts

Inactive Recognized Developer
Oct 11, 2010
1,858
2,341
35
Just to change the colors, rename options, maybe integrate some features into one option.
I have really tried to search a lot, here in XDA & Google, but I have no idea. :eek:

You would have to rebuild CWM from sources or so i believe. dont ask me how either as i've not a clue :D

Magic, thanks Iris. I recall the unpacking is fine, it is just repacking that doesn't yield either a boot.img OR kernel.sin due to the mixed file names/folders etc. It's been a few months since I tried... forgive me. All I was doing at the time was taking a stock Neo kernel and making it insecure. Which is dead easy normally. done it plenty with other phones, but SE .sin files threw me.

use this tool
http://xdaforums.com/showthread.php?t=1262656

and then you will have a kernel and ramdisk and then it is just like any other boot img :) i had to edit it to make it unpack the ramdisk aswell. ( had to remove the ../ right after the gzip command )

basicaly use the file in that post instead of iridakis "split_bootimg.pl"

Pvy
 
  • Like
Reactions: dp94 and iridaki

xperseus

Senior Member
Aug 31, 2010
149
28
Phnom Penh
Xiaomi Mi 5
Xiaomi Mi A1
I can change the boot logo now. Thanks very much.. I'm using doomlord kernel, but I love SE original boot logo. Finally I managed to change it. Thanks again. I just follow the instruction and it works. The reduce in size of boot.img didn't cause any problem at all... ;-)

Sent from my LT15i using xda premium
 

Top Liked Posts

  • There are no posts matching your filters.
  • 116
    Hello!

    This is -at least I hope it is- an easy to follow guide on how to unpack boot.img files (aka custom kernels) and modify the ramdisk.
    Now, why would you want to do that?
    First and simplest thing that comes to mind is for editing the kernel boot logo (the one that appears before the boot animation).
    There are also a lot of other things you can edit in the ramdisk, but they require a bit more advanced knowledge, so we won't talk about them here.

    Requirements:
    1. Linux (any form will do, for example virtual box etc)
    2. Perl (already included in Ubuntu, me thinks)
    3. The Xperia Boot Tools package attached in this post
    4. The mkbootimg binary (I already compiled it for Linux x86 and included it in the attachment)
    5. Reading this post VERY VERY VERY carefully :D

    Step 1: The mkbootimg binary

    Let's install mkbootimg (we need it in order to repack the boot.img).
    In a terminal window, cd to the directory where you extracted the mkbootimg file and type:

    Code:
    [B][I]sudo cp mkbootimg /bin/[/I][/B]

    And then

    Code:
    [B][I]sudo chmod 755 /bin/mkbootimg[/I][/B]

    Done!

    * After first command, terminal will ask for your user password, type it, press enter and the command will be executed immediately.

    Step 2: Splitting the boot.img

    At this point, we need a boot.img file to play with.
    Pick your favorite custom kernel and get the .img.
    Place it in a folder along with the 2 perl scripts from the attached package.
    In a terminal window, cd to the above-mentioned folder.
    Next, type this command:

    Code:
    [B][I]perl split_bootimg.pl boot.img[/I][/B]

    The command will return something like this:
    Page size: 2048 (0x00000800)
    Kernel size: 3132176 (0x002fcb10)
    Ramdisk size: 3484496 (0x00352b50)
    Second size: 0 (0x00000000)
    Board name:
    Command line:
    Writing boot.img-kernel ... complete.
    Writing boot.img-ramdisk.gz ... complete.


    Now the kernel is successfully extracted to your current directory.
    It consists of 2 files: boot.img-kernel and boot.img-ramdisk.gz.

    Step 3: Unpacking ramdisk

    So we unvealed the ramdisk in our previous step but it is still of no use to us, so we need to un-gzip and then un-cpio it.
    In the same terminal window as before, type:

    Code:
    [I][B]mkdir ramdisk[/B]

    Code:
    [B]cd ramdisk[/B]

    Code:
    [B]gzip -dc ../boot.img-ramdisk.gz | cpio -i[/B][/I]

    Last command will return something like:

    10503 blocks

    Our ramdisk is unpacked now in the newly created /ramdisk folder.

    Step 4: Editing ramdisk files

    Now you can edit the contents of the ramdisk.
    BE EXTREMELY CAREFUL AND NEVER EVER DO ANYTHING "JUST 'CAUSE"... :p
    You need to be fully aware of what you're doing.
    Good news is, changing the logo.rle (the static boot logo image) is fairly easy.
    You just need to replace it with your .rle file.
    I am not going to explain how to make your own .rle files right now.
    Feel free to have a look at this thread for more info.
    However, I attach the stock SE boot logo in case anyone misses it when he's on custom kernel. ;)

    IMPORTANT: Don't accidentally add irrelevant files to the ramdisk directory as cpio will include them too and your new boot.img will be useless.

    Also, bear in mind:

    there is a bug in the semc S1 bootloader... sometimes if the boot.img isnt of a correct size then the device will not boot... the workaround is to add a "filler" file (which is say 512KB file with junk data) to the ramdisk so as to increase the size of the final boot.img file...

    thanks to jerpelea for this incredible tip... i must have wasted atleast 10-15 hrs trying to figure out why my kernel failed to boot :p

    Step 5: Repack the ramdisk

    Now that's all done, we need to pack the kernel back up into a flashable img file.
    First, we will pack the ramdisk back to it's original state.
    In the same terminal window as before, type:

    Code:
    [B][I]find . | cpio -o -H newc | gzip > ../newramdisk.cpio.gz[/I][/B]


    Step 6: Repack the boot.img

    In our last step, back into the terminal we go to use the "repack-bootimg" perl script that will give us our brand new boot.img.
    Make sure to cd to the directory that the perl scripts are, much like in Step 1.
    Type this command:

    Code:
    [B][I]perl repack-bootimg.pl '/.../.../.../boot.img-kernel' '/.../.../.../ramdisk' newboot.img[/I][/B]

    Of course, replace /.../.../ with the path to the boot.img-kernel file and the ramdisk directory respectively.

    All done! Your new img is newboot.img and is ready to be flashed! :)

    ADVICE: Use fastboot boot and not fastboot flash boot the first time, to test that the new kernel boots. If all is well, proceed with the actual flashing!

    FAQ:

    - Can I do this on Windows?
    - Not that I know of, no. You can use Vmware or VirtualBox to install a raw Ubuntu image (pure command line) on your Windows PC though.
    - Great! How can I do this then?
    - Wish I knew! I have a Linux partition on my PC, it has been like that forever. Google is your friend! ;)

    - This is so complicated, is there an easier way? Can you make a zip for me to use in recovery?
    -
    censored.jpg

    - OK, don't get upset. Can you do it for me?
    - I will have to say no, because I know that the minute word gets out that I take requests, I will be overwhelmed.
    Took me several hours to figure all this out but it will take you less than 10 minutes to do it yourself if you carefully follow the instructions.

    - I think this or that is wrong and it should be like this or that.
    - Thank you very much for correcting me! I am still learning! Please post your corrections here or PM me and I will update the thread ASAP! :)

    References:

    - HOWTO: Unpack, Edit, and Re-Pack Boot Images
    - How to Port Android to Another Device
    - [How-To] Make custom bootscreen/bootlogo (image to rle)/(rle to image)

    Thanks to:

    - Riyal for giving me the idea to get into this.
    - pvyParts because without him I'd only be "pulling Irises"... :eek: :D


    Cheers!
    4
    i stuck on the bigining

    when i enter this line:
    perl split_bootimg.pl boot.img

    terminal return to me:
    Android Magic not found in boot.img. Giving up.

    some help?

    if you are on ubuntu,

    there's an easier method

    sudo apt-get install abootimg

    abootimg -x boot.img

    Sent from my X10S using xda premium
    4
    Hello Iridaki,

    many thanks for your apports (this and the init.d script). I'm actually user from a Spanish forum called www.htcmania.com (you may have heard about thedr0idboy, which is a Neo developer) and we were trying to pack kernels in order to flash it in locked bootloader devices or at least try to create an Overclock module for stock kernel that can be flashed in locked devices.

    Do you think we can use this to achieve this goal? I just hate Arc S with it's damn 1.4 GHz processor :S. It was released only a month after I got my Arc.

    Many thanks for your time and your efforts!!


    P.D: a girl developer!!!:D:D:D


    currently we cant use custom kernels on locked bootloader...

    there is a way to make overclock module for stock kernel... i am looking into that possibility & i have contacted a few devs... i will work on it when i get time...


    @Iris


    there is a bug in the semc S1 bootloader... sometimes if the boot.img isnt of a correct size then the device will not boot... the workaround is to add a "filler" file (which is say 512KB file with junk data) to the ramdisk so as to increase the size of the final boot.img file...

    thanks to jerpelea for this incredible tip... i must have wasted atleast 10-15 hrs trying to figure out why my kernel failed to boot :p
    3
    Thank you very much. I've been looking for something like this.

    Anyways, use VirtualBox instead of VMware. It's a thousand times better.
    3
    Hi iridaki,

    this is a great tread, and few months ago I was trying hard to find any way to change SplashScreen in Kernel on Windows (as I do not have Linux which was required in any "how to" explanation on the Web). At that time I did find this way that you describing but somehow it was too complicated as there was no tread like this to make more clearer. So I found the other (I think easier) way which required Cygwin...:) I give a link to that in appropriate tread so that others can find it too...:) This was just a note because maybe you can find that way easier too - or not...:)

    Thanks for your work and all you do for us - Xperia users...:) ;)