FORUMS
Remove All Ads from XDA

[GUIDE] Increase your Nexus 4's system partition for more space!

1,575 posts
Thanks Meter: 911
 
By bmg1001, Senior Member on 6th June 2018, 03:05 AM
Post Reply Email Thread
I got tired of installing amazing ROMs created by the talented folks here on XDA, but being held back on things like Google Apps because of the tiny /system partition we have on the Nexus 4. I looked around and found guides to increase the system space in the Nexus 5 and Nexus 7 2013, so I basically just adapted them to work on our beloved Nexus 4.

As always, do this at your OWN risk. I am not responsible for bricking your Nexus 4. I will simply list the process which I used to increase my Nexus 4's system partition (by taking a big ol' chunk from the cache partition). Remember, any sort of modification to your device of this caliber WILL void any warranty you might still have.


REQUIREMENTS:
parted (Uploaded to my Google Drive. If it downloads as a .txt, rename it to remove the extension and make it a plain file)
adb and fastboot, and preferably knowledge on how they work

Step 1: Install TWRP onto your Nexus 4 and reboot into it.

Step 2: Open up command prompt / terminal and check to see if your Nexus 4 is connected properly with "adb devices".

Step 3: Once you've confirmed that adb is fully working and your Nexus 4 is properly connected to your PC, download parted and use adb to push it to your Nexus 4 using the command:

Code:
adb push parted /
Step 4: Now enter the following command:
Code:
adb shell
and then the command:
Code:
chmod +x parted
This will enter adb shell and make the "parted" binary you pushed to your device earlier executable.

Step 5:
Now run the command
Code:
./parted /dev/block/mmcblk0 p
You should see a long list with a bunch of numbers and names in your terminal. These are the partitions on your device. parted will give you the partition number, the "start" and "end" of the partition, the size, and the name.
This is the partition layout on my device. It will probably be the same on your device, though the size of userdata may vary depending on whether you have the 8gb or 16gb Nexus 4.
Code:
~ # ./parted /dev/block/mmcblk0 p
Model: MMC 016G92 (sd/mmc)
Disk /dev/block/mmcblk0: 15.8GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name      Flags
 1      524kB   67.6MB  67.1MB  fat16        modem
 2      67.6MB  68.2MB  524kB                sbl1
 3      68.2MB  68.7MB  524kB                sbl2
 4      68.7MB  70.8MB  2097kB               sbl3
 5      70.8MB  71.3MB  524kB                tz
 6      71.3MB  94.4MB  23.1MB               boot
 7      94.4MB  117MB   23.1MB               recovery
 8      117MB   118MB   799kB                m9kefs1
 9      118MB   119MB   799kB                m9kefs2
10      119MB   120MB   799kB                m9kefs3
11      120MB   121MB   524kB                rpm
12      121MB   121MB   524kB                aboot
13      121MB   122MB   524kB                sbl2b
14      122MB   124MB   2097kB               sbl3b
15      124MB   124MB   524kB                abootb
16      124MB   125MB   524kB                rpmb
17      125MB   125MB   524kB                tzb
18      125MB   126MB   524kB                metadata
19      126MB   143MB   16.8MB               misc
20      143MB   159MB   16.8MB  ext4         persist
21      159MB   1040MB  881MB   ext2         system
22      1040MB  1627MB  587MB   ext4         cache
23      1627MB  15.8GB  14.1GB  ext4         userdata
24      15.8GB  15.8GB  524kB                DDR
25      15.8GB  15.8GB  507kB                grow


Step 6:
Now run the following three commands:
Code:
umount /data
umount /sdcard
umount /cache
Step 7: So, on my Nexus 4, the system partition is number 21, and cache is 22. We're kinda lucky in the fact that system and cache are right next to each other, meaning we don't have to touch any other partition.

You'll want to run these two next commands. These commands will essentially "remove" the two partitions.

Code:
./parted /dev/block/mmcblk0 rm 21
./parted /dev/block/mmcblk0 rm 22
Step 8: Now it is time to recreate these two partitions, however, when recreating them, we will make system bigger and the cache smaller. From the partitions list we got in Step 5, we can see that system starts at 159 and ends at 1040, while cache starts at 1040 and ends at 1627. The following two commands will rebuild /system starting at 159, but ending at 1590, while rebuilding cache at 1590, and ending at 1627. We are essentially stealing a large chunk from cache, since we don't really need that anymore on newer ROMs.

Code:
./parted /dev/block/mmcblk0 mkpart primary 159 1590
./parted /dev/block/mmcblk0 mkpart primary 1590 1627
Step 9: Now run this command:
Code:
./parted /dev/block/mmcblk0 p
This will bring up the partitions list, or table, again. This time, however, we'll see the new partitions where system and cache were, however, they have no names! The following two commands will name the two partitions again.

Code:
./parted /dev/block/mmcblk0 name 21 system
./parted /dev/block/mmcblk0 name 22 cache
Step 10: Great! Now the partitions should be named again! Now, we still have to format the partitions as ext4 so that we can actually use them. The following two commands will do that for you.

Code:
mke2fs -b 4096 -T ext4 /dev/block/mmcblk0p21
mke2fs -b 4096 -T ext4 /dev/block/mmcblk0p22
Step 11: At this point, feel free to run the command from Step 5 to take one more look at the partition table and make sure everything looks good. Now run the command
Code:
mount -a
and then type in
Code:
exit
.

Step 12: Now we are pretty much done. We've extended the system partition from approx. 881mb to 1431mb, which is a nice large chunk of memory. In the future, we could always mess with the partitions more to add even more space by stealing from userdata, but until we reach that point, I think we are pretty well set for now!

Now...
You'll want to reboot TWRP, and flash a new ROM. You can now use a much bigger Google Apps package, without any worries.
Do note, however, that flashing a ROM will "resize" system to be smaller, but this isn't a huge deal. After flashing a ROM, while still in TWRP, you'll want to go to Wipe > Advanced Wipe > check "system" then head to "Repair or Change File System", > then tap on "Resize File System." If you encounter any errors while trying to resize, try remounting system or rebooting TWRP. Afterwards, you should be able to flash your Google Apps package. I'm not sure if you need to repeat these steps after flashing things other than ROMs, but repeating this process within TWRP should work just as well.


I hope I helped y'all out and feel free to post if this guide worked for you or if you have any other comments!
CREDITS:
@surfrock66 for his Nexus 5 guide here.
@rkhat for his Nexus 7 2013 guide here.
The Following 21 Users Say Thank You to bmg1001 For This Useful Post: [ View ] Gift bmg1001 Ad-Free
10th June 2018, 07:35 PM |#3  
SnapShot86's Avatar
Member
Flag Volzhskiy
Thanks Meter: 23
 
More
Worked Thanx
The Following 2 Users Say Thank You to SnapShot86 For This Useful Post: [ View ] Gift SnapShot86 Ad-Free
13th June 2018, 07:52 PM |#4  
Junior Member
Flag São Paulo
Thanks Meter: 6
 
More
It worked here on my 8 Gb mako. Here are the original parted output:

Code:
Model: MMC 008G92 (sd/mmc)
Disk /dev/block/mmcblk0: 7818MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name      Flags
 1      524kB   67.6MB  67.1MB  fat16        modem
 2      67.6MB  68.2MB  524kB                sbl1
 3      68.2MB  68.7MB  524kB                sbl2
 4      68.7MB  70.8MB  2097kB               sbl3
 5      70.8MB  71.3MB  524kB                tz
 6      71.3MB  94.4MB  23.1MB               boot
 7      94.4MB  117MB   23.1MB               recovery
 8      117MB   118MB   799kB                m9kefs1
 9      118MB   119MB   799kB                m9kefs2
10      119MB   120MB   799kB                m9kefs3
11      120MB   121MB   524kB                rpm
12      121MB   121MB   524kB                aboot
13      121MB   122MB   524kB                sbl2b
14      122MB   124MB   2097kB               sbl3b
15      124MB   124MB   524kB                abootb
16      124MB   125MB   524kB                rpmb
17      125MB   125MB   524kB                tzb
18      125MB   126MB   524kB                metadata
19      126MB   143MB   16.8MB               misc
20      143MB   159MB   16.8MB  ext4         persist
21      159MB   1040MB  881MB   ext2         system
22      1040MB  1627MB  587MB   ext4         cache
23      1627MB  7817MB  6190MB  ext4         userdata
24      7817MB  7818MB  524kB                DDR
25      7818MB  7818MB  507kB                grow
I'm using Nitrogen OS 8.1 with GZR Gapps
The Following User Says Thank You to jfsobreira For This Useful Post: [ View ] Gift jfsobreira Ad-Free
14th June 2018, 09:48 PM |#5  
Quote:
Originally Posted by jfsobreira

It worked here on my 8 Gb mako. Here are the original parted output:

Code:
Model: MMC 008G92 (sd/mmc)
Disk /dev/block/mmcblk0: 7818MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name      Flags
 1      524kB   67.6MB  67.1MB  fat16        modem
 2      67.6MB  68.2MB  524kB                sbl1
 3      68.2MB  68.7MB  524kB                sbl2
 4      68.7MB  70.8MB  2097kB               sbl3
 5      70.8MB  71.3MB  524kB                tz
 6      71.3MB  94.4MB  23.1MB               boot
 7      94.4MB  117MB   23.1MB               recovery
 8      117MB   118MB   799kB                m9kefs1
 9      118MB   119MB   799kB                m9kefs2
10      119MB   120MB   799kB                m9kefs3
11      120MB   121MB   524kB                rpm
12      121MB   121MB   524kB                aboot
13      121MB   122MB   524kB                sbl2b
14      122MB   124MB   2097kB               sbl3b
15      124MB   124MB   524kB                abootb
16      124MB   125MB   524kB                rpmb
17      125MB   125MB   524kB                tzb
18      125MB   126MB   524kB                metadata
19      126MB   143MB   16.8MB               misc
20      143MB   159MB   16.8MB  ext4         persist
21      159MB   1040MB  881MB   ext2         system
22      1040MB  1627MB  587MB   ext4         cache
23      1627MB  7817MB  6190MB  ext4         userdata
24      7817MB  7818MB  524kB                DDR
25      7818MB  7818MB  507kB                grow
I'm using Nitrogen OS 8.1 with GZR Gapps

Awesome! Thanks for letting me know. Glad it worked for you.
31st July 2018, 04:06 PM |#6  
Senior Member
Thanks Meter: 34
 
More
thank you very much !
2nd August 2018, 08:34 PM |#7  
Junior Member
Thanks Meter: 0
 
More
Thx !
Thx !
5th August 2018, 12:14 AM |#8  
sambartle's Avatar
Senior Member
Flag Sheffield
Thanks Meter: 19
 
More
Great guide works perfectly.. has anyone tried to reverse the process and go back to stock to reflash a factory image?

I just tried it on my old Nexus 4, and after resettting the partitions, and reflashing the factory image, its just a permanent bootloop. I've cleared all the cache, tried a wipe from the stock recovery, tried flashing TWRP and wiping there.. nothing seems to work. Im not too worried, but it'd be nice if it could boot again.
6th August 2018, 10:14 AM |#9  
Junior Member
Thanks Meter: 1
 
More
Thanks for your guide. It worked like a charm for my Nexus 4.

Just a small addition: To resize the system partition automatically I placed a script in /system/addon.d:

Code:
#!/sbin/sh
#
# /system/addon.d/10-resize-system.sh
#
. /tmp/backuptool.functions

case "$1" in
  backup)
    # Stub
  ;;
  restore)
    # Stub
  ;;
  pre-backup)
    # Stub
  ;;
  post-backup)
    # Stub
  ;;
  pre-restore)
    /sbin/resize2fs /dev/block/platform/msm_sdcc.1/by-name/system
  ;;
  post-restore)
    # Stub
  ;;
esac
The Following User Says Thank You to franz.s For This Useful Post: [ View ] Gift franz.s Ad-Free
6th August 2018, 10:41 AM |#10  
caliban2's Avatar
Senior Member
Thanks Meter: 551
 
More
If it doesn't work for you
Thanks for this great guide!

Decided to breath some new life into an old N4 in my family and now it's going (very) strong again with LineageOS 15.1. Still had to clear a bit over 100 MB with .gapps-config from Stock-OpenGapps, but that's no biggie. I always liked to start with the big package and then remove everything that I don't need from it.

Second issue gave me some headaches at first.

"Resize File System" in TWRP apparently worked and Gapps-Install went through (~100 MB free at the end), but boot would fail and crash back to recovery.
(I'm using the daily LOS-nightlies by Milaq and Stock-Package from OpenGapps, maybe it's no problem with other ROMs and/or Gapps-Packages.)

Turns out the fix in TWRP wasn't really working, nevermind what partition size it shows for /system afterwards. It's somehow corrupted and still has the original size -> most of the gapps stuff get's written to nirvana, thus the failing boot.

I found the solution over in the Nexus5-Thread:

Quote:
Originally Posted by JekaPinsk

Hello guys!
Try this:
1) Install ROM
2) Backup ROM
3) Enable "Use 'rm -rf' instead of formatting" in TWRP settings
4) Format /system
4.1) Unmount /system and use 'resize2fs -f /dev/block/mmcblk0p21' in terminal (TWRP)
5) Reboot TWRP
5.1) Uncheck "Use 'rm -rf' instead of formatting" in TWRP settings
6) Restore backup
7) Install Stock OpenGapps
8) Done!

The idea behind it is that ROM installation somehow corrupt /system partition thus any write operations above normal data region silently fail.

at step 4.1 I already changed the partition number to 21 for Nexus4. In the original post it says mmcblk0p25, because on the Nexus 5 that's /system.

Now it works.
In theory this procedure should also work for updating the ROM without losing data, but haven't tested it yet. (Maybe throw in a wipe of /system as step 0...?)

To be clear: This isn't the fault of the guide to resize system-partition.
Problem is (at least certain) ROMs resetting size of file system to original and then TWRP failing to fix that doing it the easy way as described in OP (-> bug in TWRP?).

EDIT:
Above procedure also works for an update without data loss. Only difference was I did a normal wipe of /system first, "step 0" so to say.

No idea if all this is still necessary with TWRP 3.2.3-0, I'm not willing to risk a full wipe at this point. ^^
The Following 3 Users Say Thank You to caliban2 For This Useful Post: [ View ] Gift caliban2 Ad-Free
15th August 2018, 10:27 PM |#11  
i need this...can't even install the smallest gapps package after oreo.... word!! thanks!
Post Reply Subscribe to Thread

Tags
nexus, partition, resize, space, system

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

Advanced Search
Display Modes