[Guide] Repartition Nexus5 to increase system partition - Space for Rom & Stock Gapps

Kotaless

Senior Member
Dec 25, 2012
144
77
58
Istanbul
Everything worked well... But even though stock gapps successfully installed, I don't have apps such as launcher, keyboard, etc... after the boot. I think it's not for only me, and is there any solution existing?
Are you using Dirty Unicorns? It's the only rom I have encountered this issue.
Even if you install successfully, system partition backs to default size when you reboot. I had to flash pico gapps.
 

Kotaless

Senior Member
Dec 25, 2012
144
77
58
Istanbul
No... Every rom I tried caused the problem... Is it becauase I'm trying on Oreo?
I tried like 5 oreo roms until DU and it was fine. Maybe some recent commits cause this problem. Try older roms like AOSIP and let me know if you have time.
Edit: Maybe latest TWRP cause this. I don't know. But something recent caused this.
 
Last edited:

ThinnerMetalX

Senior Member
Dec 18, 2016
317
118
0
Genova
Alright thnx :D Maybe I should try older twrp
I had the same problem with the Unlegacy ROM. I solved the problem by following these steps:
1. Flash latest TWRP.
2. Reboot recovery
3. Factory reset (if you wipe all partitions, even the internal storage, factory reset after)
4. Flash rom
5. Reboot recovery
6. Flash GAPPS
7. Reboot

Worked for me :)
 

Riskypedia

Senior Member
Apr 4, 2014
159
30
0
21
Daegu
riskypedia.github.io
I had the same problem with the Unlegacy ROM. I solved the problem by following these steps:
1. Flash latest TWRP.
2. Reboot recovery
3. Factory reset (if you wipe all partitions, even the internal storage, factory reset after)
4. Flash rom
5. Reboot recovery
6. Flash GAPPS
7. Reboot

Worked for me :)
So, you mean I should wipe whole phone and then flash rom, reboot recovery, type command to resize partition(since rom would change system partition to 1gb back as OP said), and finally the gapps?
 

JekaPinsk

Senior Member
Jan 2, 2013
378
174
0
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/mmcblk0p25' 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.
 
Last edited:

ahmed-max

Member
Aug 3, 2011
7
1
0
Hello guys!
Try this:
1) Install ROM
2) Backup ROM
3) Enable "Use 'rm -rf' instead of formatting" in TWRP settings
4) Format /system and use 'resize2fs -f /dev/block/mmcblk0p25'
5) Reboot TWRP
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.
works like charm thank you very much.
if i may add u may need to untick "use rm-rf instead of formatting" before restoring coz irt gave me errors when it's used
 
  • Like
Reactions: JekaPinsk

silpy

Member
Oct 22, 2014
10
2
23
worked like a charm on nexus 5[16GB] and i didnt loose a 'bit' of data in the process.

backstory: so i wanted to install google app as a system app in Oreo but wasnt able to do so cuz of the limited system partition .
after searching awhile, i found this thread and now i cant thank you enough for this wonder

process: i did followed the *exact* same process and also managed to retain my ROM and data
*'firstly, i made a NAND backup of everything via twrp
-then i thought what if i could use a portion of cache partition instead of userdata to add to the system partition (spoiler: thats what i did)
-this way, the userdata would remained untouched and the cache wasnt anything i was gonna miss
-here's my partition table before resizing:
Code:
~ # ./parted /dev/block/mmcblk0 p
Model: MMC SEM16G (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
...
25      193MB   1267MB  1074MB  ext4         system
26      1267MB  1298MB  31.5MB               crypto
27      1298MB  2032MB  734MB   ext4         cache
28      2032MB  15.8GB  13.7GB  ext4         userdata
29      15.8GB  15.8GB  5632B                grow
here's the same thing after resizing:

Code:
Number  Start   End     Size    File system  Name      Flags
...
25      193MB   1731MB  1538MB  ext4         system             //system is now resized to 1.5GB 
26      1731MB  1762MB  31.0MB               crypto
27      1762MB  2032MB  270MB   ext4         cache            //cache is reduced to 270
28      2032MB  15.8GB  13.7GB  ext4         userdata          //the userdata was untouched
29      15.8GB  15.8GB  5632B                grow

-*finally, instead of downloading & clean flashing a rom, i restored the NAND backup that i previously made via twrp
---its worth noting that i didnt resize the system partition after restoring the backup as instructed in the OP (you should if you do a clean flash)
-then i downloaded OpenGAPPS nano (as it consisted google app), pushed it to my device via adb and installed it via recovery
-rebooted (without clearing cache) and uoeno
:D

well thanks alot for this awesome post
 

ylescure

Member
Feb 2, 2015
23
13
23
It worked, Thank you!

What i essentially did was make a nandroid backup followed by "adb pull /sdcard/" on the computer.
Followed your instructions (just before the flashing section), pushed the sdcard data back and restored the backup.
chowned and chmodded the /sdcard directory:

Code:
chown media_rw:media_rw /sdcard
chmod 755 /sdcard
Resized the /system bit, rebooted and hoped it wouldn't 'bootloop'.

The process was nerve wracking, but now the handset is ready for a future stable ROM (I'm still on stock).
In addition to this, I found that fix https://forum.xda-developers.com/showthread.php?t=2222297

Code:
chown -R media_rw:media_rw /data/media/
find /data/media/ -type d -exec chmod 775 {} ';'
find /data/media/ -type f -exec chmod 664 {} ';'
restorecon -FR /data/media/
 

GokberkTunc

Senior Member
Jul 27, 2011
64
18
28
Ankara
TL;DR
Success: Repartition of a Nexus 5 16GB
Success: Flash cm-14.1-20161028-UNOFFICIAL-hammerhead.zip
Success: Flash open_gapps-arm-7.1-stock-20161217.zip
FAIL: Getting through the Google/CM set up process (Google Play services crashes)
Success: Flash Aroma Gapps

Gapps selections:
Code:
AndroidPay=0
Books=0
CalculatorGoogle=1
CalendarGoogle=1
CalSync=0
CameraGoogle=1
Chrome=1
ClockGoogle=1
CloudPrint=0
ContactsGoogle=1
DialerFramework=1
DialerGoogle=1
DMAgent=0
Docs=0
Drive=0
Earth=0
ExchangeGoogle=0
FaceDetect=0
FaceUnlock=1
Fitness=1
GCS=1
Gmail=0
GoogleNow=0
GooglePlus=0
GoogleTTS=0
Hangouts=0
Hotword=0
Indic=0
Japanese=0
Keep=1
KeyboardGoogle=1
Korean=0
Maps=1
Messenger=0
Movies=0
Music=1
NewsStand=0
NewsWidget=0
PackageInstallerGoogle=0
Pinyin=0
PixelIcons=1
PixelLauncher=1
Photos=1
PlayGames=0
PrintServiceGoogle=0
ProjectFi=0
Sheets=0
Slides=0
Search=1
Speech=0
StorageManagerGoogle=0
Street=0
TagGoogle=0
Talkback=0
Translate=1
VRService=0
Wallpapers=1
WebViewGoogle=1
YouTube=1
Zhuyin=0
inclorexcl=1
Aim
To convert my Nexus 5 16GB into a Pixel using CM14.1 and Stock Open Gapps (I didn't want to keep flashing random pixel-experience.zip files)

Issue (strikethrough issues are with Stock Gapps)
When using Aroma Gapps:
1. Launcher3 crashes everytime the G search bar is clicked on
2. Google Now is not on the left pane despite my chosen packages
1. I couldn't Sign into my WiFi because no soft keyboard would appear (workaround: I created a password-less Hotspot on another phone)
2. I wasn't able to get past through the Google setup process; Google Play Services would crash every time I attempted to skip Tap & Go taking me back to a SIM card missing screen. On skipping this, I get taken to Tap & Go... and repeat
I've wiped all the caches (of course). If anyone has any ideas, it would be great.


Question to @surfrock66
You have a parted command that says:
Code:
~ # ./parted /dev/block/mmcblk0 mkpart primary 3056MB 30.8GB
Should this not be:
Code:
~ # ./parted /dev/block/mmcblk0 mkpart primary 3056MB 31.3GB
I may not have understood this fully

Thanks surfrock66 for the original method; my method varies slightly and is as follows:
Code:
Download and unpack parted.rar via the

# With phone in TWRP Recovery
$ sudo adb push parted /
$ sudo adb shell
~ # chmod +x parted
~ # ./parted /dev/block/mmcblk0 p

Model: MMC SEM16G (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.7MB  1049kB               sbl1
 3      68.7MB  69.2MB  524kB                rpm
 4      69.2MB  69.7MB  524kB                tz
 5      69.7MB  70.3MB  524kB                sdi
 6      70.3MB  70.8MB  524kB                aboot
 7      70.8MB  72.9MB  2097kB               pad
 8      72.9MB  73.9MB  1049kB               sbl1b
 9      73.9MB  74.4MB  524kB                tzb
10      74.4MB  75.0MB  524kB                rpmb
11      75.0MB  75.5MB  524kB                abootb
12      75.5MB  78.6MB  3146kB               modemst1
13      78.6MB  81.8MB  3146kB               modemst2
14      81.8MB  82.3MB  524kB                metadata
15      82.3MB  99.1MB  16.8MB               misc
16      99.1MB  116MB   16.8MB  ext4         persist
17      116MB   119MB   3146kB               imgdata
18      119MB   142MB   23.1MB               laf
19      142MB   165MB   23.1MB               boot
20      165MB   188MB   23.1MB               recovery
21      188MB   191MB   3146kB               fsg
22      191MB   192MB   524kB                fsc
23      192MB   192MB   524kB                ssd
24      192MB   193MB   524kB                DDR
25      193MB   1267MB  1074MB  ext4         system
26      1267MB  1298MB  31.5MB               crypto
27      1298MB  2032MB  734MB   ext4         cache
28      2032MB  15.8GB  13.7GB  ext4         userdata
29      15.8GB  15.8GB  5632B                grow

~ # umount /data
~ # umount /sdcard
~ # umount /cache
~ # ./parted /dev/block/mmcblk0 rm 25
~ # ./parted /dev/block/mmcblk0 rm 26
~ # ./parted /dev/block/mmcblk0 rm 27
~ # ./parted /dev/block/mmcblk0 rm 28
~ # ./parted /dev/block/mmcblk0 mkpart primary 193MB 2291MB
~ # ./parted /dev/block/mmcblk0 mkpart extended 2291MB 2322MB
~ # ./parted /dev/block/mmcblk0 mkpart primary 2322MB 3056MB
~ # ./parted /dev/block/mmcblk0 mkpart primary 3056MB 15.8GB
~ # ./parted /dev/block/mmcblk0 p
~ # ./parted /dev/block/mmcblk0 name 25 system
~ # ./parted /dev/block/mmcblk0 name 26 crypto
~ # ./parted /dev/block/mmcblk0 name 27 cache
~ # ./parted /dev/block/mmcblk0 name 28 userdata
~ # mke2fs -b 4096 -T ext4 /dev/block/mmcblk0p25
~ # mke2fs -b 4096 -T ext4 /dev/block/mmcblk0p27
~ # mke2fs -b 4096 -T ext4 /dev/block/mmcblk0p28
~ # ./parted /dev/block/mmcblk0 p
~ # mount -a
~ # exit

Model: MMC SEM16G (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.7MB  1049kB               sbl1
 3      68.7MB  69.2MB  524kB                rpm
 4      69.2MB  69.7MB  524kB                tz
 5      69.7MB  70.3MB  524kB                sdi
 6      70.3MB  70.8MB  524kB                aboot
 7      70.8MB  72.9MB  2097kB               pad
 8      72.9MB  73.9MB  1049kB               sbl1b
 9      73.9MB  74.4MB  524kB                tzb
10      74.4MB  75.0MB  524kB                rpmb
11      75.0MB  75.5MB  524kB                abootb
12      75.5MB  78.6MB  3146kB               modemst1
13      78.6MB  81.8MB  3146kB               modemst2
14      81.8MB  82.3MB  524kB                metadata
15      82.3MB  99.1MB  16.8MB               misc
16      99.1MB  116MB   16.8MB  ext4         persist
17      116MB   119MB   3146kB               imgdata
18      119MB   142MB   23.1MB               laf
19      142MB   165MB   23.1MB               boot
20      165MB   188MB   23.1MB               recovery
21      188MB   191MB   3146kB               fsg
22      191MB   192MB   524kB                fsc
23      192MB   192MB   524kB                ssd
24      192MB   193MB   524kB                DDR
25      193MB   2291MB  2098MB  ext4         system
26      2291MB  2322MB  31.0MB               crypto
27      2322MB  3056MB  734MB   ext4         cache
28      3056MB  15.8GB  12.7GB  ext4         userdata
29      15.8GB  15.8GB  5632B                grow

# This didn't work for me
$ sudo adb push cm-14.1-20161028-UNOFFICIAL-hammerhead.zip /
$ sudo adb push open_gapps-arm-7.1-stock-20161217.zip /

$ sudo adb reboot recovery
# So I copied over the files once I reboot into recovery
# I had to reboot into recovery again to see my CM14.1 and Gapps files
# Flashed them using TWRP

$ sudo adb shell
~ # unmount /system/
/sbin/sh: unmount: not found
# I have no idea why this happened

~ # resize2fs -f /dev/block/mmcblk0p25 2000M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/block/mmcblk0p25 to 512000 (4k) blocks.
The filesystem on /dev/block/mmcblk0p25 is now 512000 blocks long.

~ # mount -a
mount: mounting /dev/block/mmcblk0p1 on /firmware failed: Invalid argument
mount: mounting /usb-otg on vfat failed: No such file or directory
# I have no idea why this happened either

~ # exit
Amazing. Thank you for this guide. it works like a charm. I just wanna ask a question. I want 3 gb space instead of 2 gb. i did all things correct but just last step gonna fail. you said resize2fs -f /dev/block/mmcblk0p25 2000M". i changed it to "resize2fs -f /dev/block/mmcblk0p25 3000M". it mess it up everything and i back to the original, it worked. but there is missing 1 gb.
i parted partition like that.
./parted /dev/block/mmcblk0 mkpart primary 193MB 3291MB
./parted /dev/block/mmcblk0 mkpart extended 3291MB 3322MB
./parted /dev/block/mmcblk0 mkpart primary 3322MB 4056MB
./parted /dev/block/mmcblk0 mkpart primary 4056MB 15.8GB

what should i write instead of 2000M to?
 

sneak

Senior Member
Nov 30, 2013
139
27
0
Well I tried this by first increasing the system partition by 620MB since I was short by 617.xx MB according to the OpenGApps log. It didn't work; I was told that there wasn't enough space on the partition for GApps still.

I chose to shrink userdata and cache partitions to donate some space to system.

So I partitioned all over again and set the system partition to 2GB and the stock GApps still won't install (I flash this version of crDroid first).

Here's how the partition table looks:

Code:
~ # [6n./parted /dev/block/mmcblk0 p
Model: MMC SEM16G (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.7MB  1049kB               sbl1
 3      68.7MB  69.2MB  524kB                rpm
 4      69.2MB  69.7MB  524kB                tz
 5      69.7MB  70.3MB  524kB                sdi
 6      70.3MB  70.8MB  524kB                aboot
 7      70.8MB  72.9MB  2097kB               pad
 8      72.9MB  73.9MB  1049kB               sbl1b
 9      73.9MB  74.4MB  524kB                tzb
10      74.4MB  75.0MB  524kB                rpmb
11      75.0MB  75.5MB  524kB                abootb
12      75.5MB  78.6MB  3146kB               modemst1
13      78.6MB  81.8MB  3146kB               modemst2
14      81.8MB  82.3MB  524kB                metadata
15      82.3MB  99.1MB  16.8MB               misc
16      99.1MB  116MB   16.8MB  ext4         persist
17      116MB   119MB   3146kB               imgdata
18      119MB   142MB   23.1MB               laf
19      142MB   165MB   23.1MB               boot
20      165MB   188MB   23.1MB               recovery
21      188MB   191MB   3146kB               fsg
22      191MB   192MB   524kB                fsc
23      192MB   192MB   524kB                ssd
24      192MB   193MB   524kB                DDR
25      193MB   2291MB  2098MB  ext4         system
26      2291MB  2322MB  31.0MB               crypto
27      2322MB  2836MB  514MB   ext4         cache
28      2836MB  14.7GB  11.9GB  ext4         userdata
29      15.8GB  15.8GB  5632B                grow
There's the impossible claim I need 616,648 KB (same as before re-partitioning) according to the GApps log:

Code:
         Total System Size (KB) | 1033516
         Used System Space (KB) | 835184
        Current Free Space (KB) | 198332
 Additional Space Required (KB) | 616648   << See Calculations Below

UPDATE:

Resolved issue by doing this (yes I see it's in the original post, but I didn't realize it wasn't just for his specific needs):

Code:
resize2fs -f /dev/block/mmcblk0p25 2000M
mount -a
Then flashing the GApps again... so I plan to change the partitions one last time to give me back more space on my 16GB model then do this all over again.
 
Last edited:

sammrevenn

New member
Mar 10, 2020
2
0
0
Amqui
Help with Nexus 5 hammerhead

Yes, this...my numbers show the methodology, but for the 16GB nexus 5 (or any other phone) you need to start by looking at the starting state of the partition table, then do the math from start to finish. I hope I've provided enough methodology and warnings that someone will either abort or do it right.
Hi, I'm searching for the stock partition table log for my Nexus 5 16GB.
I would like to rebuild my partition to have 2gb system.
My /cache partition and /userdata are broken (doesn't not exist).

Can anyone help please?
Marc.
 

sammrevenn

New member
Mar 10, 2020
2
0
0
Amqui
Thanks for your help, I managed to install Lineage OS 17.1 and GAPPS to my Nexus 5 16G.
It was a bit messy, but I could do it, for a moment I thought I bricked it.
:D

I was wandering what is the /grow partition if anyone knows?