FORUMS
Remove All Ads from XDA

[GUIDE]Increase kernel and recovery partitons size

593 posts
Thanks Meter: 545
 
Post Reply Email Thread
Quote:

#include <std_disclaimer.h>
/*
* Your warranty is now void.
*
* I am not responsible for bricked devices, dead SD cards,
* thermonuclear war, or you getting fired because the alarm app failed. Please
* do some research if you have any concerns about features included in this ROM
* before flashing it! YOU are choosing to make these modifications, and if
* you point the finger at me for messing up your device, I will laugh at you.
*
*/


WARNING : MESSING WITH KERNEL AND RECOVERY PARTITIONS IS VERY DANGEROUS FOLLOW THIS GUIDE AT YOUR OWN RISK


In this guide you will learn how to increase the size of kernel and recovery partitions. the method should work for other samsung devices.
So it will be something like that .....
Before

After

The way we are going to increase the size of the partitions is to repartition the partition so first you must read this guide here and understand it well as we will need it .


Steps to do this are :
  • Repartition device memory.
  • Edit pit file for the device.



BEFORE DOING ANYTHING YOU SHOULD TAKE BACKUP OF THE PARTITION WE WILL WORK ON


First we will start with kernel partition and please don't touch recovery partition until you make sure that you have done all the steps correctly and your system is working then go for recovery partition

Tools will be used :
Parted : Here .
PIT editor : Here .


This method can work if you want to repartition any other partitions like data or whatever you want .
If you find anything wrong, typo, broken links or even flying elephant please let me know.
One last thing if you did like this guide or you didn't you can push that thanks button
The Following 2 Users Say Thank You to LahKeda For This Useful Post: [ View ] Gift LahKeda Ad-Free
 
 
15th December 2016, 07:12 PM |#2  
LahKeda's Avatar
OP Senior Member
where technology located
Thanks Meter: 545
 
More
Repartitioning device storage .
Repartitioning device storage


After you read the thread I've mentioned before... start repartitioning your device,but actually I won't write every steps of repartitioning but I'll clear some points and give you important tips when you repartition the device .

Let me clear something, the way we are going to use is that we will cut some space from any unimportant partitions and glue it to kernel or recovery partition .


Tip 1 :
So what are the unimportant and important partitions ?
Important and dangerous partitions :
PIT , MD5HDR , Product info , DSP , Modem , odin reserved , EFS , ......

Unimportant and safe partitions :
System , User data , Cache partitions
This doesn't mean that you can mess up with those partitions, it's just mean that you can only take space from those partitions without any worries of break phone functions .
Tip2 :
when you repartition the device you must know where you are and specify your situation ....
There are two situation :

  • Lucky one .
  • Unlucky one .
Lucky situation :
the lucky situation is that when your recovery and kernel partitions aren't next to any dangerous partitions.you will just cut some space of the unimportant partitions and glue it to kernel and recovery partition
like those ones ....

Unlucky situation :
the lucky situation is that when your recovery and kernel partitions are next to any dangerous partitions. so in this situation you will have to change and rearrange places of kernel and recovery partitions.
this is unlucky situation....
Tip3 :
If kernel and recovery partitions are next to each other and you're in the unlucky situation you will just need to move one partition from its place then give its space to the other partition and you should move the kernel partition and give its space for recovery partition as it's safer than moving recovery partition. In case you're in the lucky situation you will just cut the space of unimportant partition and glue it to the partition... look here :

This is unlucky situation : kernel and recovery partitions are next to each other so I'll just delete kernel partition, cut some space of system partition, make that space for kernel partition and give old kernel partition space for recovery partition .
Before :
After :

This is the lucky situation : You will remove kernel partition and safe_partition then make new kernel partition and new safe_partition, but leave some free space before kernel partition because you will add this space to recovery partition later when you make sure that you have done the steps correctly and the kernel is loaded.
Before :
After :

Tip4 :
If kernel and recovery partitions aren't next to each other and you are in lucky situation. You will cut some space and glue it to the partition you want .
And if you are in the unlucky situation you will just move the partition from its place, then cut some space from any safe partition and make this space for the kernel/recovery partition.


Tip 5 :
How much space should you make for kernel and recovery partitions ?
It's good to make each of them about 20~25 MG and don't go too high like 40 or more unless you really this much of space and keep in mind that you take this space from other partitions like system , user data or cache partitions .Also it's good to take the space from your system or cache partitions as you will not need them a lot like user-data partition .


Tip 6 :
Be organized and do everything in order So If you have to remove system and kernel partitions and you will make anything like formate or anything do it in order so first start with removing system partition and recreate it in smaller size then remove kernel partition and recreate it in the new size. WHY ? as if you just removed kernel and system partitions at the same time when you recreate them again you will end up with wrong partition number and your phone won't boot .

Tip 7 :
While you're repartitioning you will find free space at the beginning and end of your device do mess up with them they are related to bootloader and other stuff ... just act like you don't see them at all \.


Let's get started :
-What I will do is remove system partition, cut some space of it, recreate it again in new size, make new kernel partition then assign old kernel space to recovery partition. (I am in unlucky situation) .
You will need parted program to do all partitioning stuff .
-I do recommend using TWRP recovery as it's so powerful .
-Make sure to put parted program in safe place away from the partitions you will take space from it


  1. Put parted in you internal storage .
  2. Boot to recovery .
  3. Plug your device to your pc .
  4. Give parted execution permission ... open a new terminal/console and type "adb shell" then type "chmod a+x /sdcard/parted"
  5. From current shell type "/sdcard/parted /dev/block/mmcblk0p" or "/sdcard/parted /dev/mmcblk0" if your device uses /dev/mmcblk0*" then type "unit mb" then "print". you should see some thing like that .
  6. Then open new terminal/console , type "/sdcard/parted /dev/block/mmcblk0" or "/sdcard/parted /dev/mmcblk0" . then type "unit s" then "print". you should see some thing like that .
  7. Remove system partition "rm 21 " . then type "print free"
  8. Recreate system partition in the new size . "mkpart partition_name start_sector end_sector"

    -I'll take 26MB from system partition so new partition size will be ( old size in sectors - the amount of space I want in sectors[(26*1024*1024)/sector_size] )
    so new size will be 1,835,008 - [(26*1024*1024)/512]=1781760
    -To get end sector: ( start sector + partition size in sectors ) so mine will be ( 1252864 + 1781760 )=3034623
    finally the command is "mkpart system 1252864 3034623"
  9. Put a name for system partition "name partition_number new_name" the name should be like old partition name so if it was system then name it system and if it was KERNEL name it KERNEL
    so mine should be "name 21 system"
  10. Make new kernel partition and name it . "mkpart KERNEL 3034624 3087871 " -> "name 5 KERNEL" .
  11. Also make partition instead at old kernel partition space and just name it anything then formate it as fat16 .
    this steps just to make us sure that the phone is using new kernel partition not the old one .
    so for me I'll do... "mkpart dummy 64512 84992" -> "name 28 dummy" -> "mkfs" -> "yes"->"28"->"fat16"
  12. Now you will have to formate system , kernel partitions as fat16/fat32 ...type "mkfs" then type "Yes" then type partition number then type fat16 or fat32 .
    -But , why ? Let's say that system partition was 1000 sectors and I made it 900 sectors only the device will still read last 100 sectors as the old filesystem type which will make errors because those 100 sectors will be kernel partition and it will be a mess .Don't worry they will be back to their old filesystem types when we restore system and kernel again .
    -Why fat16 and fat32 ? Because parted only supports fat16/fat32/ext2 , and ext2 cause recovery not to mount system and kernel partitions .
    -OK , which one to use fat16 or fat32 ? fat16 for small partitions like kernel and fat32 for large partitions like system .
    -Now it will be like that .
  13. I won't add the space of old kernel partition to recovery until I make sure that everything is okay.
  14. Now I will edit pit map for my device.
  15. After that restore kernel and system and see if the system is booting or not .
  16. If the system booted with the new kernel partition I'll remove recovery partition so it will be merged with the old kernel space then I'll recreate recovery partition again then formate it to fat16 after that I'll edit pit file again then push it to device then put it back to its partition.
  17. Now you can either use heimdall or odin to flash the recovery and make sure that it works well.
The Following User Says Thank You to LahKeda For This Useful Post: [ View ] Gift LahKeda Ad-Free
15th December 2016, 07:13 PM |#3  
LahKeda's Avatar
OP Senior Member
where technology located
Thanks Meter: 545
 
More
Edit PIT file .
Edit PIT


After you repartition kernel/recovery partition you will have to edit pit file to finish up working and make new partitions useable and make your phone work .
There is some points I should clear out first .


What is PIT file ?
It is a file contains a lot of informations about all partitions in your phone .

What is PIT used for ?
  • This file is used by device bootloader to know where is kernel/recovery partition to load it .
  • Heimdall and ODIN , they use this file to know what goes where so they know where to put kernel,recovery,system,modem and everything else .

What I'll edit in PIT file ?
You will have to edit all information for partitions you have changed them .


Let's get started :
  1. Get pit file for your device . How ?
    from parted type print and look for the partition with contains pit file . for me the file is in partition number 26 .
  2. Copy that pit file to your sdcard or external card .
    open another terminal/console then type "adb shell" then the copy command "dd if=/dev/block/block_that_contains_pit of=where_ever_you_want_to_put_pit_in/any_name.pit"
    so for me I'll type "dd if=/dev/block/mmcblk0p26 of=/sdcard/mint.pit"
  3. Pull pit file from the phone through this command . "adb pull /sdcard/mint.pit"
  4. Open pit editor and choose "PIT file analysis" then open your pit file .
  5. Click on "Copy to clipboard" and paste in any new text file as you will need some of those information later in case you messed anything up .
  6. Now go to "PIT file editor tab" and open your PIT file.
  7. PIT entry list choose the entries you will edit .
    if you have edited system and kernel partitions so you will need to modify 2 entries ,but which two ?
    let's say that system partition number is 15 and kernel is 9 so you will edit entries number 15 & 9 .
    For my I'll edit entries number 5 and 21 .
  8. You only will edit two values "Block size " and "Block Count" .
  9. In "Block size" you will enter start sector of your block . and in "Block count" you will enter the size of your partition in sectors .
    To get those values open new terminal/console then type "adb shell" then "/sdcard/parted /dev/block/mmcblk0" or "/sdcard/parted /dev/mmcblk0" then "unit s" then "print"
    So for my system partition : block size = 1,252,864 and block count = 1,781,760
    and for my kernel partition : block size = 3,034,624 and block count = 53,248
  10. Then hit save and go to "PIT file analysis" then open your pit file . and make sure that your changes have been saved .
  11. Now push that PIT file to your device storage and copy it back to it's own partition "adb push pit_name.pit /sdcard/mint.pit" but for you should copy it back with it's original name. to find it go to "PIT file editor " and select the entry number for pit partition . it will be the same as your pit partition number so for me my partition number is 26 so I'll select entry number 26 . then look at "Flash file name" . so for me my pit file name is mint.pit
  12. Now copy pit file back to its partition "dd if=/sdcard/mint.pit of=/dev/block/mmcblk0p26"
  13. Finally I'll restore kernel and system and reboot and see if the system boots or not .
The Following User Says Thank You to LahKeda For This Useful Post: [ View ] Gift LahKeda Ad-Free
15th December 2016, 07:13 PM |#4  
LahKeda's Avatar
OP Senior Member
where technology located
Thanks Meter: 545
 
More
For devs:If you've changed partitions sizes (cut space of them) and you're going to port a ROM or build on from source, make sure to change partitions size in BoardConfing.mk or them ROM won't boot and you'll need to reformat the partitions again. After you finished working and the ROM is stable enough to release or you just want to publish it for testing purpose make sure that you rebuild ROM with the original partitions sizes again.
15th December 2016, 07:13 PM |#5  
LahKeda's Avatar
OP Senior Member
where technology located
Thanks Meter: 545
 
More
Oh He left me
15th December 2016, 07:15 PM |#6  
LahKeda's Avatar
OP Senior Member
where technology located
Thanks Meter: 545
 
More
Cool I'll ask for divorce
3rd July 2017, 04:54 PM |#7  
LahKeda's Avatar
OP Senior Member
where technology located
Thanks Meter: 545
 
More
one more for the future (Maybe)
Post Reply Subscribe to Thread

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

Advanced Search
Display Modes