[GUIDE][XS/XSL]One time re-partitioning for Marshmelow ROM flashing

Mirhawk

Senior Member
Jan 31, 2014
1,453
635
113
A Marshmellow based AOSP ROM was recently released by billchen1997. To flash it, re-partitioning of the partition table is required.To do so, following procedure can be used.

Note: This procedure doesn't work with nAOSP 6.0 ROM released by mickybart now, please find the appropriate instructions in ROM thread.

Do make a note of few things though:
  1. Internal storage which can be accessed via PC by selecting "File transfer"option manually after connecting.
  2. Recovery for Me was retained since I had flashed it in fota partition, hence I would recommend flashing recovery in fota partition before hand.
  3. Performing them on PC would be convenient as some calculations are required.
  4. Wiping all partitions before hand is recommended.
  5. Text formatting conventions are used in the code sections to depict different meanings:
    • Bold : States the commands to be entered on adb.
    • Italic : States what values, usually which varies user to user, has to be entered at the place.
    • Underlined : States output shown by a certain command preceding it.
    • Repeated x/y/z are variables.
  6. As pointed out by @GjorgiDxc, the phone is not directly encrypted. We need to encrypt it manually. To do so, flash only the ROM, without gapps or root, boot into ROM and encrypt the phone. More details can be found here. Encrypting data would make data partition inaccessible in TWRP.

Procedure:
  1. Take backup of Your apps as well as the data from the internal storage (Photos, Music, Video etc) as it will all be wiped.
  2. Boot into TWRP.
  3. Goto mount option and untick all partitions.
  4. On PC, using adb, type out the following commands,

    1. Print the current partition table. Note down the starting cylinder of partition 14, It will be needed further.
      Code:
      [B]adb shell
      fdisk /dev/block/mmcblk0
      p[/B]

    2. Now delete the sdcard(15) and data(14) partition.
      Code:
      [B]d
      15
      d
      14[/B]

    3. Create new data partition which uses remaining space.
      Code:
      [B]n[/B]
      [U]First cylinder (xxx-yyyyyy, default xxx): [/U] [I]You have to enter the start cylinder of partition 14 as read in partition table earlier.[/I]
      [U]Last cylinder or +size or +sizeM or +sizeK (zzzzz-yyyyyy, default yyyyyy):[/U] [I]Enter the yyyyyy value.[/I]

    4. Print and write the modified partition table. Note down the "Blocks" value of partition 14 here.
      Code:
      [B]p
      w[/B]

    5. Code:
      [U]Command (m for help): [/U][B]t[/B]
      [U]Partition number (1-14): [/U][B]14[/B]
      [U]Hex code (type L to list codes):[/U][B] 83[/B]
    6. One of the two paths can be followed here now. It depends on which filesystem is required for data partition, ext4 or f2fs. For ext4, follow the first subsection and for f2fs, second one.

      1. Now the calculation needs to be done for ext4 file system. From the "Blocks" value of partition 14, subtract 16, since we have to leave 16384 bytes and each block equals 1024 bytes (16*1024=16384).
        For Me, the "Blocks" value of partition 14 was 29161464. Hence, my final value was 29161464-16=29161448. Now divide the solution by 4.
        Therefore, 29145080/4=7290362. Consider it as final_size. This many blocks will be allocated for the data partition. This needs to be done since the partition needs to be made using blocks size.
      2. Now we format the data partition such that it acquires the space and as well as leaves the trailing 16384 bytes. This creates a data partition with ext4 type, allocation unit as 4096 and size in blocks as final_size.
        Code:
        [B]mke2fs -t ext4 -b 4096 /dev/block/mmcblk0p14[/B] [I]final_size[/I]



      1. For f2fs file system, simply run the following command, no need of any calculation:
        Code:
        [B]mkfs.f2fs -r 16384 /dev/block/mmcblk0p14[/B]




    7. Code:
      [B]exit
      adb push -p pure_aosp_marshmallow_r1.zip /tmp/[/B]
  5. Now on phone, in TWRP, Flash the ROM via install option, and done!

Notes:
  1. First Reboot is long.
  2. If after boot it says encryption failed, let it reset the phone. Then it will work properly.
  3. For root, flashing Update zip of SuperSU from here works.
  4. Wiping data via TWRP menu will allocate the trailing 16384 bytes to it too, so it is not to be done.
  5. For gapps, flash Pico gapps from here. Then after reboot and login, go to Settings, Apps>Settings icon at top right> App permissions. Now in each permission, open the permission, select show system from options and enable the permission for all system apps.
  6. If You get error like "Error retrieving information from sever.[RPC:C:S-7:AEC-7 CDY7-E3OJ-V2TKC]" in Google Play Store and are not able to install any app, then log out and log in again into Your google account via settings.
  7. If You copy a file and want to access it via TWRP, mount data partition and go to /data/media. Although data won't mount if You encrypt Your phone.
Credits to @SystemR89 for his tutorial as base and billchen1997, @mickybart for his instructions and TWRP.
Calculations are not needed now since micybart has modified the TWRP to leave trailing 16384 bytes at end. The TWRP can be found here.
 
Last edited:

nageswarswain

Senior Member
Feb 6, 2014
1,462
395
0
JAJPUR,ODISHA,INDIA
@Mirhawk so what are you saying Friend? What will be the difference we get than your instruction.will it solve my battery not charching problem.?actually I used mickybarts recovery last time.so was that OK or I have to flash the official twrp to do the job
 

Mirhawk

Senior Member
Jan 31, 2014
1,453
635
113
Thanks for your guide friend. What is difference between this method and your previous method http://forum.xda-developers.com/showthread.php?p=64433804 ? I think your previous method is easier and it's not confusing.
BTW I wiped /data in twrp and I don't have any problem
The earlier one allocated less space for user. Yeah, I agree, this one is a bit more complicated than previous one, but it is as per some of the instructions provided by billchen1997. Wiping /data with previous process works, but as it wouldn't with this process. I will have to test that if it will work.

@Mirhawk so what are you saying Friend? What will be the difference we get than your instruction.will it solve my battery not charching problem.?actually I used mickybarts recovery last time.so was that OK or I have to flash the official twrp to do the job
As said above, it will allocate more usable space for user. Well, modifying of partition should not affect Your offline charging. I used the TWRP by SdtBarbarossa, if it makes any difference.
 
Last edited:
  • Like
Reactions: nageswarswain

GjorgiDxc

Senior Member
Sep 28, 2014
941
310
0
Bitola
Why were you saying storage is not accessable via PC? Internal storage shows up fine for me via PC. The only issue I have is with recovery, but there should be a fix to the recovery by mickybart (he is maintaining TWRP) to recognize the new repartitioning, so I can live with that.
 

Mirhawk

Senior Member
Jan 31, 2014
1,453
635
113
Why were you saying storage is not accessable via PC? Internal storage shows up fine for me via PC. The only issue I have is with recovery, but there should be a fix to the recovery by mickybart (he is maintaining TWRP) to recognize the new repartitioning, so I can live with that.
You are able to save in internal storage using PC? And if You save a file, does it show up in /storage/emulated/0?
All I get is blank window when I open "Xperia S" icon in windows explorer.

Never mind, forgot to select the option for file transfer. Will update that now.
 
Last edited:

GjorgiDxc

Senior Member
Sep 28, 2014
941
310
0
Bitola
You are able to save in internal storage using PC? And if You save a file, does it show up in /storage/emulated/0?
All I get is blank window when I open "Xperia S" icon in windows explorer.
Yes I can. I think after creating partiton14 you should type
t
14
c

I think I did that, but anyway yes i can see the whole 27GB of storage on the computer, and thats how i flash gapps. I flash rom via /tmp and gapps after it boots up. Also maybe you've missed this, but you have to toggle "File tranfer" in the notification shade, the default is "Charging cable" and it doesn't display the internal storage. Pull down notifications, tap on the one bellow USB debugging and select the second option. :) I'll post some screenshots maybe later, I'm doing some battery testing atm.
 
  • Like
Reactions: Mirhawk

Mirhawk

Senior Member
Jan 31, 2014
1,453
635
113
Yes I can. I think after creating partiton14 you should type
t
14
c

I think I did that, but anyway yes i can see the whole 27GB of storage on the computer, and thats how i flash gapps. I flash rom via /tmp and gapps after it boots up. Also maybe you've missed this, but you have to toggle "File tranfer" in the notification shade, the default is "Charging cable" and it doesn't display the internal storage. Pull down notifications, tap on the one bellow USB debugging and select the second option. :) I'll post some screenshots maybe later, I'm doing some battery testing atm.
Yeah, thanks, the notification doesn't show up on lock screen.
I don't think there is any need to type "c" after creating partition, since it converts the partition to fat32 and it is not needed here.
 

GjorgiDxc

Senior Member
Sep 28, 2014
941
310
0
Bitola
Yeah, thanks, the notification doesn't show up on lock screen.
I don't think there is any need to type "c" after creating partition, since it converts the partition to fat32 and it is not needed here.
I never knew that, still no issues with doing that :)
So you've missed the notification? You're able to see storage now right?
 

pejman97

Senior Member
Jun 14, 2014
206
19
0
Arak
You are able to save in internal storage using PC? And if You save a file, does it show up in /storage/emulated/0?
All I get is blank window when I open "Xperia S" icon in windows explorer.

Never mind, forgot to select the option for file transfer. Will update that now.
I'm able to access all 27GB in my device and PC. I did everything exactly like you instruction http://forum.xda-developers.com/showpost.php?p=64433804&postcount=1487 till item 4, then I went to wipe menu in twrp and ticked /data partition then pressed on "Repair or change file system" then pressed on resize, then it changed and shows all 27GB then I choose EXT4 then wiped all partitions on my device by twrp, then I did rest of your instruction
 

Mirhawk

Senior Member
Jan 31, 2014
1,453
635
113
I never knew that, still no issues with doing that :)
So you've missed the notification? You're able to see storage now right?
@Mirhawk try this if it works.connect device to PC.then select file transfer.then goto settings developer option and turn off the USB debugging.it worked for me
Yup, it works for Me, just had to unlock the screen to get notification.

I'm able to access all 27GB in my device and PC. I did everything exactly like you instruction http://forum.xda-developers.com/showpost.php?p=64433804&postcount=1487 till item 4, then I went to wipe menu in twrp and ticked /data partition then pressed on "Repair or change file system" then pressed on resize, then it changed and shows all 27GB then I choose EXT4 then wiped all partitions on my device by twrp, then I did rest of your instruction
Yeah, it would work that way since the 16384 bytes are left outside the data partition end border in the older procedure. Here, we leave the 16384 bytes inside the end boundary of the data partition. My screenshots after following this procedure with size are attached.
 
Last edited:

pejman97

Senior Member
Jun 14, 2014
206
19
0
Arak
Yup, it works for Me, just had to unlock the screen to get notification.


Yeah, it would work that way since the 16384 bytes are left outside the data partition end border in the older procedure. Here, we leave the 16384 bytes inside the end boundary of the data partition. My screenshots after following this procedure with size are attached.
We both did the same but why I lost about 1GB rather than you?
 

darknessmc

Senior Member
Jul 30, 2013
685
131
73
In the previous method, more than 16384 bytes are left out. There 16384 cylinders*bytes_per_cylinder are left out. Hence there is a difference in size.
Thanks for your instructions it's clear at the the beginning. Now there is no way to use old p15 in this rom until doing like this to use all storage size. That's clear now. So, can I leave about 1G as mmcblk0p15 with vfat system just to flash an update and gapps in the future? Cause all data partition will be wiped if we reset the device.
 

jgilalonso666

Senior Member
Oct 4, 2010
175
32
0
Can anyone help me? When I try adb in PC, i receive this message: device not found.
I have the phone with TWRP and connected by Usb to the PC.
In the past, i increased the partition for lollipop without problems.
What am i doing bad??

Update:
If I connect the phone with lollipop instead TWRP i can access to the phone without problems. Adb found my de vice attached.
 
Last edited:

pejman97

Senior Member
Jun 14, 2014
206
19
0
Arak
Can anyone help me? When I try adb in PC, i receive this message: device not found.
I have the phone with TWRP and connected by Usb to the PC.
In the past, i increased the partition for lollipop without problems.
What am i doing bad??
Just connect your device to PC and open command. Write (adb devices) if the device doesn't detect while youre device is connected to PC go to advance menu in twrp and open side load and swipe then press cancel then your device should be detected by this command (adb devices)