Hovatek Forum MOBILE Android [Tutorial] How to resize partitions on an android phone using Parted
Can't login? Please, reset your password.
Hovatek is recruiting! Apply Now


[Tutorial] How to resize partitions on an android phone using Parted

[Tutorial] How to resize partitions on an android phone using Parted

Pages (3): 1 2 3 Next
X3non
X3non
X3non
Recognized Contributor
22,062
21-03-2020, 12:41 AM
#1



This is a step by step guide showing how to resize partitions on an android phone using Parted. This guide will come in handy if you're trying to reduce the size of a partition e.g system partition and increase another partition e.g userdata partition

Requirements



Steps on how to resize partitions on an android phone using Parted


Follow the steps below to resize partitions on an android phone using Parted


See the video below or @ https://youtu.be/XEjDKGzd-3o


  1. Before you begin, you should make a backup using TWRP (i have no ext_sd so i copied my backup to my PC)

  2. On your phone, goto TWRP > Mount. Untick all the checkboxs (i.e unmount everything)

  3. Connect your phone to the PC using a USB cable while it's in recovery mode (in my case, TWRP)

  4. Launch a CMD prompt / Powershell window and change directory into the folder containing the parted tool. In my case it's
    Code:

    cd C:\Users\X3non\Desktop\part

    [Image: how-to-resize-partitions-on-an-android-p...rted-1.jpg]

  5. Type the commands below and press Enter after each line
    Code:

    adb push parted /sbin
    adb push mkfs.ext4 /sbin
    adb shell
    chmod 777 /sbin/parted
    chmod 777 /sbin/mkfs.ext4
    parted /dev/block/mmcblk0

    [Image: how-to-resize-partitions-on-an-android-p...rted-2.jpg]

  6. You will be greeted with a welcome message from parted

  7. In parted, type either of the commands below to view a detailed list of all partitions currently on your device
    Code:

    print
    or
    p free

    [Image: how-to-resize-partitions-on-an-android-p...rted-3.jpg]

  8. I want to resize two partitions (system and userdata). Notice that there are several partitions in between the two partitions i want to resize (recovery, cache, misc)

  9. Highlight all the partitions between and including the two partitions you're resizing. Left click and drag to highlight then right click on the highlighted items to copy

    [Image: how-to-resize-partitions-on-an-android-p...rted-4.jpg]

  10. Paste the copied items into any text editor such as notepad for safe keeping

    [Image: how-to-resize-partitions-on-an-android-p...rted-5.jpg]

  11. Using parted, remove all partitions until you remove the partition you wish to resize (in my it's system partition at number 17)
    Code:

    rm 21
    rm 20
    rm 19
    rm 18
    rm 17

    [Image: how-to-resize-partitions-on-an-android-p...rted-6.jpg]

  12. To recreate the partitions that has just been removed, use the command below
    Code:

    mkpart system ext4 43 2141
    where
    • mkpart is the command for creating a new partition
    • system is the partition name
    • ext4 is the file system (if the partition has no fs, then use an empty space. So there will be 3 spaces in between the partition name and the start_length e.g mkpart recovery 2298 2313)
    • start_length is the end_length of the last partition (check using the print command)
    • end_length is start_length + the partition_size (unless you're resizing a partition, use the sizes from the values you pasted into notepad)

  13. Rename the new partition you've just created using the command below
    Code:

    name 17 system
    where
    • name is the command for renaming a partition
    • 17 is the partition's number
    • system is the new name you wish to assign

  14. Set the flag back to the original flag the partition had before removing it using the command below
    Code:

    set msftdata on
    where
    • set is the command for setting flag to a partition
    • msftdata is the partition original flag (you can check the text you copied into notepad)

  15. The output for above 3 commands for creating, naming and setting flag to a partition will look something like this

    [Image: how-to-resize-partitions-on-an-android-p...rted-7.jpg]

  16. You can use the "print" command to check the new changes you made

  17. Now repeat the same procedure for the remaining partitions till you create all partitions you removed

  18. Type the command below to exit parted tool
    Code:

    quit

  19. Type the command below to format userdata to ext4 format (this will make userdata to become accessible on twrp for formatting)
    Code:

    mkfs.ext4 /dev/block/mmcblk0p21
    where
    • mkfs.ext4 is the name of the second file you pushed into the phone along with parted tool
    • /dev/block/mmcblk0p21 ; 21 is the partition number of userdata as seen in the output of print command in parted tool

  20. Once successful, you should see the cursor blinking (waiting for a new command)

    [Image: how-to-resize-partitions-on-an-android-p...rted-8.jpg]

  21. You can now disconnect the phone from the PC, goto TWRP > Wipe > Advanced wipe > Repair / Change file system > Tick the checkboxes beside userdata, cache and system > Repair / Change file system > Ext4 > Swipe to change

  22. Once complete, these partitions can now be mounted and if your TWRP allows for MTP storage mode, you can copy a backup or flashable zip rom into the internal storage

  23. Resizing is complete now but you must either restore a backup in order to boot the device into homescreen or flash back the contents of the partitions you removed

  24. In my case, i simply wanted more internal storage so i restored my twrp backup once resizing was complete


Important Notice
  • You can't resize dynamic partitions (these include partitions within "super" partition on devices running android 10 & above) using this technique
  • You can't resize system partition while your phone is booted to homescreen. If you do then the device will most likely crash and get stuck on bootlogo due to No OS installed
  • Ensure to take a backup of the partitions on your phone before you remove them using parted tool


Quote:In this video tutorial, i'm going to be showing how to resize partitions on an android device using parted tool. Now parted tool is a command line tool
Now i've connected my device and it's currently connected in TWRP recovery
Now before we begin i want to resize my system partition and reduce it's size from 3GB to 2GB, take the extra 1gb and add it into userdata partition to increase my internal storage
Now i've made my TWRP backup and saved it on my PC
Now this is parted tool right here, saved on my PC as well
So i'm going to quickly open a CMD prompt and type adb devices, so my device is detected
Another thing you need to note is that my device is also detected in mtp storage so i can transfer files while in recovery mode
So let me quickly begin, we'll need to transfer this two files into the phone
We'll do this by changing directory, cd, enter
Now i'm in this folder, so adb push parted which is the name of the file i want to copy to /sbin folder, enter
Successful
I'll repeat the same thing for the second file
Now, i'll open shell, adb shell
I'm going to give permisssion to the files i just copied into sbin folder
Once that's done, we'll launch parted by typing parted /dev/block/mmcblk0
Now this is the mount point for internal storage on android devices, Enter
now parted will give me a welcome message, Welcome to parted, type help to view a list of commands
you can just type help if you need to view the list of commands you can run on parted tool
Now, i'm going to do print, this will show me a list of all the partitions currently on my phone now, their start address and end address, the sizes, the file systems
So since i want to reduce the size of system which is here, you can see the size says 3GB, basically this is 3GB and it's at 17
I need to delete all the partitions till i get to system
So to do this, the command in parted is
RM remove 21, so i'll remove 21 first
am i sure i want to continue? yes, okay, cancel
So now we actually need to do something in TWRP before begin and that is Mount, untick system, untick data and untick cache
So we go to twrp mount and untick every item listed there
now we can return back to parted, lets try removing again
RM 21, hold on that is strange, okay so it has actually removed 21 for us and so we remove 20
Okay before we move further, let me quickly highlight these items, we'll need to store these items somewhere so that we can use while calculating the new values
I'm going to quickly paste them in notepad++
Now lets proceed, we remove 20, we remove 19, we remove 18, remove 17
so let me quickly go to print again, and so here we've seen that there's no extra partition outside this one
So it's time to create new partitions, the command for creating new partitions is mkpart partition name is system, the file system is ext4, now the start address will be the end address for this one, then the end address since we want 2GB, this is 1GB
hold on, so this is the size of 3GB, all we need to do is open a calculator, 3147 / 3
so this is the size for 1GB, we want to make it 2GB, so this is the new size we want but to get the end address, end address will be the same thing as this plus the start address
So i hope you understand, that to get end address, we'll add this 2GB to this start address, so plus 43 is equals to 2141
so here we'll type 2141 and press enter
now we'll name 17 going to name this partition, it'll be 17 already so we'll name 17 system which is the last partition we deleted
now set the flag back to what it was, so set 17 msftdata, on
now lets quickly type print again to show us what we've done, and so you can see system partition starts where boot stopped, ends here and the size is 2GB, file system is ext4 so basically we've created system partition
Now all we need to do is repeat the same commands for all the other partitions while making necessary calculations
So cache is the next partition, we'll go to., mkpart cache, now cache also has ext4 so ext4, the start address will be the end address of system, now the size for cache is 157 so all we need to do is add 157 to the start address, plus 157, 2298, so end address is 2298, enter
so we'll name 18 to cache
we'll set 18 to msftdata, on
and if we print, here we go, this is cache, so next is recovery
so mkpart recovery, now recovery has no file system so we'll press an empty space as the name, so there are 3 empty spaces here
so the first empty space, then the empty space for the name then an extra empty space so 3 empty spaces then the start address will be 2298 which is the end address for cache, add 14.7
plus 14.7, okay hold on, let me make it a standard calculator, 2298 + 14.7 , so i'm just going to approximate this to 2313. So 2313
So we name 19 to recovery, set 19 msftdata, just type on and enter
Now when we print, we have recovery, no file system
So we make partition for the next which is misc, also misc does not have any file system so 3 spaces, then start address 2313, misc is 1mb, just add 1mb is 2314 because 1000 plus kb is 1mb and so enter
Now name 20 to be misc, set 20 msftdata on
Now we print, that's misc for you
Now the last partition is userdata. mkpart userdata ext4, you can see it here it's ext4, so the start address is 2314, the end address will be the size of the disk itself so that it'll use up all the free space it can get, so which is 7650, this is it here, this is the full disk length, so the end address will be the end
So name 21 to userdata, lastly set 21 msftdata on and when we print again
Now we have here, internal storage which is userdata 5GB plus, but initially we had 4GB plus
So what you'll realize now is that the system has no operating system , no recovery mode and no userdata so once i reboot from the current twrp i'm going to get stuck on bootlogo
So we are already done with partitioning the device, all we need to do now is flash something into these partitions, before we do that we'll quickly exit parted tool
To exit parted tool, we'll type quit. So this has taken us back to shell
It'll tell you that you need to edit etc/fstab, just ignore this for now. Now we need to format userdata before we proceed
To format userdata, we're going to use the second file we copied. what was the name of the file again, mkfs
So now we type mkfs, now userdata partition is 21 so what we'll do now is /dev/block/mmcblk0p21 then hit enter
so it's currently formatting userdata, okay it's all done now
we can now close this tool, close this, well we don't need this as well
Now what we need now is to goto TWRP, mount cache, okay hold on, you can see there's no internal storage
So all we need to do now is goto TWRP, goto wipe, advanced wipe, wipe cache, data and system then swipe to wipe
okay hold on, so we're going to do repair / change file system
we'll do for data first, repair / change file system, change file system to ext4 then swipe, so it's done formatting data to ext4
back, back
Now we'll do the same thing for system, change file system, ext4, swipe, back, back
We'll do the same thing for cache, change file system to ext4
Now once this is done, we'll go back to TWRP mount and you can see all 3 items can now be mounted, now all we'll need to do is when you come over here, you can see the internal storage is now available
So i'm simply going to copy my twrp backup into the internal storage, my twrp backup contain the exact same partitions that we just wiped and made again, which is cache, userdata, misc, recovery and system
Okay, so copying is complete, i can now disconnect the phone
Now all i'll need to do is restore backup, click on the backup, select all the partitions i need to restore then swipe to restore
So basically this is how resize partitions on an android device using parted tool
Ensure to subsribe for more video tutorials
This post was last modified: 14-09-2021, 10:07 AM by X3non.
Pius Oblie
Pius Oblie
Pius Oblie
Junior Member
32
17-07-2020, 04:10 AM
#2
Hi. How to solve permission denied when I typed chmod 777 /sbin/parted
X3non
X3non
X3non
Recognized Contributor
22,062
17-07-2020, 09:20 AM
#3
(17-07-2020, 04:10 AM)Pius Oblie Hi. How to solve permission denied when I typed chmod 777 /sbin/parted

post the issue along with screenshot showing issued commands on your thread @ https://www.hovatek.com/forum/thread-35727.html
muhd90
muhd90
muhd90
Newbie
1
22-07-2020, 05:50 PM
#4
0mb internal storage host.
hovatek
hovatek
hovatek
Administrator
49,570
25-07-2020, 09:47 AM
#5



(22-07-2020, 05:50 PM)muhd90 0mb internal storage host.

Create a new thread for this by clicking Ask Question at the top

Note!
We have a reply schedule for Free Support. Please upgrade to Private Support if you can't wait.
amey.adhalikar@gmail.com
amey.adhalikar@gmail.com
amey.adhalikar@gmail.com
Enthusiastic Member
6
21-09-2020, 01:39 PM
#6
Hi,

Very good article.
However, while partitioning my Redmi Note 5 Pro, the phone was restarted accidently, and the system partition is deleted from the device, i.e. the partition table doesn't contain the system partition.
Now the phone is stuck on fastboot, and I am not even able to flash recovery or system image to the phone using fastboot.
Could you please help me in this case?

Thanks,
Amey
X3non
X3non
X3non
Recognized Contributor
22,062
22-09-2020, 09:12 AM
#7
(21-09-2020, 01:39 PM)amey.adhalikar@gmail.com Hi,

Very good article.
However, while partitioning my Redmi Note 5 Pro, the phone was restarted accidently, and the system partition is deleted from the device, i.e. the partition table doesn't contain the system partition.
Now the phone is stuck on fastboot, and I am not even able to flash recovery or system image to the phone using fastboot.
Could you please help me in this case?

Thanks,
Amey

create a new thread for your device issue by clicking "Ask Question" at the top
in the new thread, list all the partitions you removed without creating them back
amey.adhalikar@gmail.com
amey.adhalikar@gmail.com
amey.adhalikar@gmail.com
Enthusiastic Member
6
22-09-2020, 01:05 PM
#8
(22-09-2020, 09:12 AM)X3non
(21-09-2020, 01:39 PM)amey.adhalikar@gmail.com Hi,

Very good article.
However, while partitioning my Redmi Note 5 Pro, the phone was restarted accidently, and the system partition is deleted from the device, i.e. the partition table doesn't contain the system partition.
Now the phone is stuck on fastboot, and I am not even able to flash recovery or system image to the phone using fastboot.
Could you please help me in this case?

Thanks,
Amey

create a new thread for your device issue by clicking "Ask Question" at the top
in the new thread, list all the partitions you removed without creating them back

Thanks X3non, I have created this thread: https://www.hovatek.com/forum/thread-366...#pid201842
vikas14
vikas14
vikas14
Newbie
1
09-11-2020, 10:42 PM
#9
i am getting an error Kernel too old Fatal error and no welcome message. Please suggest what to do. I am using Nexus 7 Grouper
X3non
X3non
X3non
Recognized Contributor
22,062
10-11-2020, 12:12 PM
#10



(09-11-2020, 10:42 PM)vikas14 i am getting an error Kernel too old Fatal error and no welcome message. Please suggest what to do. I am using Nexus 7 Grouper

try using an older version of parted tool ; you can download from the list @ http://ftp.gnu.org/gnu/parted/
the version used here is 3.2 , you can view parted's version by issuing the command "Parted" or "parted /dev/block/***"
This post was last modified: 10-11-2020, 12:16 PM by X3non.
Pages (3): 1 2 3 Next
Users browsing this thread:
 1 Guest(s)
Users browsing this thread:
 1 Guest(s)
YtWhTl
live chat
whatsapp telegram instagram