[Q] Replace Internal Data Partition for External SD

mobrien118

Member
Sep 29, 2012
27
7
0
Ballwin
Let me start with: I know that there have been many posts on this, but before you get mad, I was unable to find an answer to what I specifically want to do.

For reference: I am a software developer and sysadmin with a decent amount of Linux experience, but not a lot of android specific experience.

Now that the introduction is out of the way:

What I would like to do is completely remove the "USERDATA" partition (the "Internal SD card"), grow the "SYSTEM" partition to fill that space, and then mount my SD Card (external) as the SD Card that the system sees.

I'm currently on Cyanogenmod 10.1 but want to upgrade to 11 soon.

The reason I want to do this is because:
  • I have all if my apps that I can set to install to SD Card
  • Both "internal" partitions are full (only about 200MB is available for pictures/etc. and I can no longer update apps)
  • Camera (and pretty much everything else as well) stores to the Internal SD card by default

If the system partition was 1.1+1.4=2.5GB and all of my apps were "installed" to a real SD card, it would be a lot more comfortable.

So, here's what I am thinking *might* work (maybe not in the right order, though?):
  1. Point the fstab entry for the internal SD card to the external SD card
  2. I have the PIT file. I will delete the "USERDATA " and grow "SYSTEM" to fill the space

When I write it out in steps, it seems pretty simple...

My concerns:
Will a ROM update (to CM11) re-partition back to the old way (and, in the process, break a bunch of stuff)?

I don't ever plan to go back to stock android or change to another ROM (other than upgrades).

Thanks for reading this long post and for any insight you may be able to provide.

--mobrien118
 
  • Like
Reactions: kaefers and Veliion

Somcom3X

Inactive Recognized Developer
Aug 19, 2012
2,959
3,204
0
Metro Detroit
Modifying partitions is a bit dangerous.
But I have to ask you why do you need another GB of /system storage?
There was a line you can put in the build.prop that flips your ext. SD with the internal one on cm10 I believe.
This'd interest me if I could get rid of usbdisk and sdcard0 merged.
It would need the phone to be repartitioned though, causing issues with the backups and ROMs.
You may even have to compile cm from source.
Its a lot of trouble :)


Sent from my SAMSUNG-SGH-T769 using Tapatalk
 

aguaz

Senior Member
Jan 16, 2014
136
31
0
I just did so on S4 Mini with cm-11 Android 4.4.

First I was thinking of using symlinks and/or bind mounts to redirect to the the external sdcard, but that's a bit of a hassle because
1) Since 4.2: both emulated and external storage is mounted with a fuse layer on top not supporting symlinks
2) Since 4.4: no more global write access on external storage

So moving data was the simplest solution. Besides providing (much) more space my sdcard is also around 20% faster in sequential writes: 8.5 MB/s internal vs 10.5 MB/s external. Is it really 2014?
I haven't yet decided what to do with the original data partition, so for the moment I left it unused. Hence I haven't touched the internal partition table.


Quick summary
  • partition sdcard (gdisk)
    I recommend using GPT, this lets you work with partition names rather than numbers. For the sake of still having an "official" external sdcard I made two partitions. Keep in mind that it's usually the first partition which gets automatically mounted as external sdcard. So I made the 2nd partition the new home for data. This partition however has to be manually specified in the ramdisks fstab which involves flashing the boot partition.
  • format the new partitions (mkfs.ext4)
  • copy the original /data directory tree to the new data partition
  • extract initrd from boot.img (abootimg)
  • extract files from initrd (gunzip & cpio)
  • replace the /data entry in fstab pointing at your new data partition
  • re-pack initrd and boot.img (gzip, cpio & abootimg)
  • flash boot.img onto the boot partition (dd)
If you use recovery, you also have to edit it's fstab (analog to boot.img mentioned above)

done


Alternatively has anyone tried an init.d script? I see those scripts get executed before the mounting of data & sdcard
 
Last edited:
  • Like
Reactions: Whitest

aguaz

Senior Member
Jan 16, 2014
136
31
0
Meanwhile the original userdata partition got replaced by 3 new partitions: system2, cache2 & userdata2 which are now used for a dual boot ROM.
I've only changed GPT, not PIT. ROMs and Recovery don't use PIT, so as long as Heimdall/Odin isn't involved it should not cause any issues.
 

SORAnoDYStopia

Senior Member
Jan 27, 2015
209
51
0
Auckland
Hey guys,

So after read all that, I am also vry interested in what the OP has suggested. I get that the pit doesn't need to be affected, but as the OP asked, when flashing a new rom or updating an existing, would the partition be reformatted back to the way android handles it, ie; back to the system and data seperate and the sdcard not being used as the internal partition?

I am no developer and only have minimal knowledge in linux and android programing, but I am a quick study and any guide to help me sort this would be greatly appreciated.

Also I am about to get a second S4 mini specifcally for doing things like this so if I brick I don't care?

My next question is could it be possible to code the PIT file to do this for you so that you can just flash that through odin, but again would flashing roms affect this.

Cheers,
Sora.
 

Whitest

Senior Member
Oct 6, 2011
143
60
0
I just did so on S4 Mini with cm-11 Android 4.4.

First I was thinking of using symlinks and/or bind mounts to redirect to the the external sdcard, but that's a bit of a hassle because
1) Since 4.2: both emulated and external storage is mounted with a fuse layer on top not supporting symlinks
2) Since 4.4: no more global write access on external storage

So moving data was the simplest solution. Besides providing (much) more space my sdcard is also around 20% faster in sequential writes: 8.5 MB/s internal vs 10.5 MB/s external. Is it really 2014?
I haven't yet decided what to do with the original data partition, so for the moment I left it unused. Hence I haven't touched the internal partition table.


Quick summary
  • partition sdcard (gdisk)
    I recommend using GPT, this lets you work with partition names rather than numbers. For the sake of still having an "official" external sdcard I made two partitions. Keep in mind that it's usually the first partition which gets automatically mounted as external sdcard. So I made the 2nd partition the new home for data. This partition however has to be manually specified in the ramdisks fstab which involves flashing the boot partition.
  • format the new partitions (mkfs.ext4)
  • copy the original /data directory tree to the new data partition
  • extract initrd from boot.img (abootimg)
  • extract files from initrd (gunzip & cpio)
  • replace the /data entry in fstab pointing at your new data partition
  • re-pack initrd and boot.img (gzip, cpio & abootimg)
  • flash boot.img onto the boot partition (dd)
If you use recovery, you also have to edit it's fstab (analog to boot.img mentioned above)

done


Alternatively has anyone tried an init.d script? I see those scripts get executed before the mounting of data & sdcard
I just managed to replace my internal sd with the external sd following your ruff guide. thank you very much! At first I struggled a bit getting it to work, because I had encrypted my data partition before -.- this seems to change something in the fstab / mounting / boot-up process, I couldn't get my S4 mini to boot with just changing the fstab.qcom in boot.img. With my recovery (TWRP) it worked from the start editing recovery.img's fstab.twrp /data mount point.
After decrypting(formatting) /data and re-editing fstab.qcom in boot.img it finally works :) I'm so happy! Enjoying a lot of space on my sdcard now!

usefull threads / information I learnt from:

(Links last tried 28.05.2015)
 
Last edited: