[GUIDE] Enlarge DATAFS partition and get rid of Internal SD (UMS)
Tired of running out of space in the /data partition? I found a way to get rid of the UMS partition and enlarge the DATAFS partition on our beloved Galaxy S II.
WARNING: with this guide you can brick your phone and it's not intended for novice users, you have to know what you're doing.
Theory about partitions
The internal MMC (/dev/block/mmcblk0) contains partition information in two areas, one standard, the GPT partition table and in another area Samsung-specific, the PIT. With odin (or heimdall) you can simply upload a new PIT and flag for repartition, this way both the PIT and the GPT get updated. I think the PIT needs to be updated in order to use Odin for flashing stock firmware.
Creating a modified PIT file
You can get your current PIT file by downloading it with heimdall or getting a stock one for your specific model from the internet. I attached the stock one for my phone, I9100 16GB (original_I9100_16GB.pit).
$ heimdall download-pit --output mypit.pit
After you got the original PIT you can edit it with PIT Magic
, a Windows .NET tool to edit PIT information, you can also run it with mono on linux/osx.
Open the file in PIT Magic and go to PIT Entry list #11, the DATAFS partition. We need to focus on two fields, the "Block size", that's the block where the partition starts and "Block count", the size of the partition in blocks. The next partition must start on the block given by the sum of the previous partition block size and block count.
In order to enlarge the DATAFS partition, just raise the value in the block count field, keeping in mind the size of a block is 512 bytes. The next partition (UMS, the internal sd) must start as stated above, so just write the correct value in the block size field of the #12 partition. I suggest to keep the UMS partition if you're running a stock or stock-derived rom, just make it very small (in the attached PIT I made it about 50MB, small-ums_I9100_16GB.pit), but if you're running an AOSP flavor of android you can get rid of the UMS partition and the HIDDEN one (/preload). Keep in mind the sum of block size and block count of the #12 UMS partition must be exactly the number in the block size of the #13 HIDDEN partition (or the DATAFS must end on the last block of the HIDDEN partition if you're getting rid of the last two partitions).
After you saved the new pit file, just upload to your phone with heimdall or odin.
$ heimdall flash --repartition --pit newpit.pit
You can have a look at the new partition table in recovery, with an adb shell, using parted. You can see the same numbers as the ones in the PIT file using the command "unit s" then "print".
Change android storage layout
$ adb shell
~ # parted /dev/block/mmcblk0
GNU Parted 188.8.131.52.179-aef3
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit s
Model: MMC V3U00M (sd/mmc)
Disk /dev/block/mmcblk0: 30777344s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 8192s 49151s 40960s ext4 EFS
2 49152s 51711s 2560s SBL1
3 53248s 55807s 2560s SBL2
4 57344s 73727s 16384s PARAM
5 73728s 90111s 16384s KERNEL
6 90112s 106495s 16384s RECOVERY
7 106496s 311295s 204800s ext4 CACHE
8 311296s 344063s 32768s MODEM
9 344064s 1392639s 1048576s ext4 FACTORYFS
10 1392640s 29720475s 28327836s ext4 DATAFS
11 29720476s 29720575s 100s fat32 UMS
12 29720576s 30769151s 1048576s ext4 HIDDEN
Now we have to tell android to ignore the internal partition and use the external sd card as the main one. If you just want to swap the two, just google around, there are plenty of guides about this.
We have to edit two files, /system/etc/vold.fstab and storage_list.xml inside /system/framework/framework-res.apk. I have attached an update.zip for samsung stock roms (no-internal-ums-samsung.zip) and for cyanogenmod 10.1 (no-internal-ums-cm10.1.zip), if you use one of these, you can skip the following details, the updater will take care of the modifications.
In vold.fstab we just have to remove references to the internal sdcard and change the mount point for the external one to /storage/sdcard0.
The other file, storage_list.xml is trickyer, as it's inside an apk. This file contains a list of all the storage the hardware can handle. We need to remove the internal sd card from this file. In order to do this you need apktool
. These are the command I used to extract the apk.
$ java -jar /Android/apktool1.5.2/apktool.jar if framework-res.apk
$ java -jar /Android/apktool1.5.2/apktool.jar if twframework-res.apk
$ java -jar /Android/apktool1.5.2/apktool.jar d framework-res.apk
Now you have to edit framework-res/res/xml/storage_list.xml as follow for a samsung stock derived rom:
In order to repack the apk:
$ java -jar /Android/apktool1.5.2/apktool.jar b framework-res/ framework-res.apk
For the samsung stock you have to copy the signature from the original apk (the META-INF directory and AndroidManifest.xml).
$ zip -r ../framework-res.apk META-INF
$ zip -r ../framework-res.apk AndroidManifest.xml
In order to use this method with cm 10.2, repartition (removing both ums and preload or by resizing them) and add this in /system/build.prop (in order to make the external sd the main storage).
No need for update zip, just repartition and edit build.prop
I would have never succeeded in making this guide if I hadn't found these useful forum posts on xda.
[GUIDE] External2Internal Ultimate
PIT file method to revive your phone from a MMC_CAP_ERASE brick
Sd card swapping on cm 10.2