[Android General] DestructoSphere:
This guide was written for the Huawei y6 with a gpt partition table, mounts that use partition names not numbers and the userdata partition is the last one on disk however with a little adaption this should work for most gpt devices.

If you are unsure if your system uses partition names for the mount system look in /fstab."hardware" to see if your devices are labelled in the following manner. "/dev/block/bootdevice/by-name/system".

If the fstab file does not exist all is not lost look in your root directory at the .rc files for the command mounting system.

If you are unsure ask in the thread before doing anything. Better to ask than be stuck with a brick.

This guide covers modification to only system and userdata partitions but if you use great care the basics covered here will allow for modification to other partitions as long as you understand the risk and know that backups are your friend.

If you are unable to follow instructions and end up with a bricked device that is your own fault and attempts to blame me will be laughed at.

I obtained the attached parted binary from here

So you have flashed a custom ROM and without all the OEM bloatware you now have some unused free space in your system partition just sitting there gathering dust.

You are stuck with this space... Wrong.

You can repartition your device with a little paitence, time and work.

Read along if you are curious about how to get the space you deserve.

Prerequisites:

Free space (Duh).

The ability to follow instructions and to read ALL steps before you start so you know what your plan is.

An unlocked bootloader which you already have if you flashed a custom ROM.

A custom recovery (twrp preferred).

Parted binary (see attachment at the bottom of this post).

A computer with adb installed and working (there are many guides out there if you don't have it, Google is your friend).

A calculator (well I'm sure your computer has one but just so you know).

Some knowledge using terminal commands.

Risk of Bricking your device:

Low if you backup and can double check typing and calulations.

High if you can't do one of the above.

Because parted does not allow resizing of ext4 partitions you must delete partitions you want to change then recreate them.

All steps must be performed while in recovery because you are going to have to unmount any partition before you can change it.

Step 1:

Boot into recovery and make a backup. You MUST do this otherwise you will have nothing to restore.

Step 2:

Plug your device into your computer.

Copy the parted binary into your working directory on your PC.

Open your Command Prompt (Windows) or Terminal (Linux) and navigate to where adb is installed and you also put parted, or if you have adb in your PATH just go to where parted is.

Run

~ # adb devices

to ensure your device is present.

Run

~ # adb root

to get root priviliges.

Run

~ # adb push parted /sbin/parted

/sbin is in your devices PATH so you don't have to worry about typing /parted.

Run

~ # adb shell

Run

~ # chmod 755 /sbin/parted

If you get an error about a read only file system run

mount -o remount,rw /

then try again.

Step 3: Now you need to do some homework to find your sector size, sector count and how much free space you have available.

DO NOT shrink your filesystem to smaller than you need to operate. I always add at LEAST 50 mb to the used space however I recommend you think for the future, are you planning on restoring to stock?, are you planning on flashing OpenGAPPS?, are you planning on moving third party apps into the system?, are you planning on adding media or custom boot animations to the system?

So in the case below I would not make the partition any smaller than 800 MB.

~ # df
Filesystem Size Used Free Blksize
/system 1.2G 748.5M 441.8M 4096
/data 5.2G 3.5G 1.6G 4096
/cache 147.2M 4.7M 142.5M 4096

Now issue the following command to get your disks sector size in bytes remember to note this down.

~ # blockdev --getss /dev/block/mmcblk0
512

Time to use parted.

Issue the following commands to get some info on your current partitions.

"unit s" tells parted to show sectors instead of blocks, bytes etc.

~ # parted /dev/block/mmcblk0
(parted) unit s
(parted) print

Number Start End Size File system Name Flags
22 876562s 1191132s 314571s ext4 cache
23 1191133s 3990839s 2799707s ext4 system
24 3990840s 15269854s 11279015s ext4 userdata

Remember to not the partition number as you will need it later.

Remember to note your partition name with exact case, if you changed "system" to "System" you will have problems.

Also note the start sector of your system partition for the later steps.

Also note the end sector number for your userdata partition for the later steps.

Now get your calulator ready.

Some things to keep in mind here are that the number of sectors times sector size is the size of your partition in bytes and your starting sector must be 1 after the end of the previous partition.

So the following equation will give you the numbers you need.

Desired size in MB * 1024 * 1024 / Sector Size = Number of sectors

Starting sector + Number of sectors - 1 = Last Sector

If you want a 1.1 Gb partition, you have 512 byte sectors and the starting sector is 1191133 you would then use the following equation.

1100 * 1024 * 1024 / 512 = 2252800

1191133 + 2252800 - 1 = 3443932

Step 4:

Now using the info you have gathered you can change your partitions.

So I would issue the following commands to delete, create and name the system partition with the size I want.

(parted) rm 23

(parted) mkpart 23 ext4 1191133 3443932

(parted) name 23 system

Now to resize the data partition.

You need to start with the first available sector after the end of system and end with the last available sector noted earlier.

(parted) rm 24

(parted) mkpart 24 ext4 3443933 15269854

(parted) name 24 userdata

Now that your partitions are all done you can exit parted with the following.

(parted) quit

Step 5:

Now restore the backup you made earlier.

If you get an error restoring which usually only happens if you have altered partition numbers just reboot back into recovery and restore then so the kernel gets to update its own info.

Reboot.

Congratulations you now have repartitioned your device.

Don't forget to thank this post if you are grateful.