Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,738,501 Members 48,772 Now Online
XDA Developers Android and Mobile Development Forum

[GUIDE][ROOT] Resizing emulated SD card and userdata partitions

Tip us?
 
bsined
Old
(Last edited by bsined; 17th April 2014 at 06:19 AM.)
#1  
bsined's Avatar
Senior Member - OP
Thanks Meter 79
Posts: 198
Join Date: Mar 2013
Location: Washington, DC
Database [GUIDE][ROOT] Resizing emulated SD card and userdata partitions

I originally created this guide for Sony Xperia T/TL/TX/V and have since discovered that the method works for other devices, too. So I present the universal guide to getting rid of that annoyingly tiny allocation of space for internal storage in devices that have plenty of it.

Kudos to @teidus for pointing me to this long-forgotten method.

Screenshots of proof are attached to my original post.

WARNING: You will lose a lot of data if you don't follow this guide!

WARNING: These operations require a rooted device. If you are running unrooted Android 4.3 or newer, you cannot proceed.

NOTE: All of these changes will be reversed if you flash a factory image that contains a partition table.

DISCLAIMER: I'm not responsible for bricked devices and data loss from power surges, hardware damage, or changes to the linked software. Always check the native manuals for all the tools listed here!

I'm also not responsible for your curiosity and desire to resize other partitions. I haven't tried that because messing with /system and /cache can lead to unexpected results.


Requirements:
1. Your device must currently have root access, CMW recovery v6.0.4.6 or later, less than 50% allocated to internal storage, emulated SD card (usually, it's /storage/sdcard0), and at least 8GB of total onboard memory. If you answered "No" to at least one of these, this guide won't help you. To check whether you have an emulated SD card, remove your physical SD card, go into a file manager app, and see whether you still have some sdcard listed.

2. A factory image flashing software for your device unzipped and/or installed on your computer. Look in the relevant forums for downloads.

3. ADB from either Android SDK or your device's flashing tool. Look in the relevant forums for instructions.

4. For locked bootloaders, factory firmware image with Android v4.1.2 or v4.0.x saved on your computer (consult your flashing tool's manual for the default location) - nearly 100% of these have root exploits. Look in the relevant forums for downloads.

5. Root exploit with Superuser or SuperSU installer for your device unzipped on your computer. Look in the relevant forums for downloads.

6. CMW recovery installer v6.0.4.6 or later compatible with your device and the factory firmware version obtained in step 4 unzipped on your computer. Look in the relevant forums for downloads.

7. File system utilities (attached) unzipped to a folder on your device's physical SD card you'll remember (I'll be using /fs-utils in this guide).

8. For Windows 8 users, ADB drivers for your device.
The Guide (skip all the way to the bottom for the short list of ADB commands):

1. Back up all data stored on internal storage:
Option 1: Connect your device to the computer and save it to a computer drive.
Option 2: Open a file manager on the device and copy it to a physical SD card (/sdcard1).
2. Back up your current installation with either Online Nandroid or your current recovery and remove the SD card for safety.

3. Flash your device with basic 4.1.2 install.
Refer to the documentation for your tool.
4. Connect your device to the computer and let the computer recognize it.

5. Enable USB debugging.
5.1 Go to (System) Settings -> Developer options and flip the switch in the top-right corner of the screen.

5.2 Look a bit down (toward the middle of the screen) and check USB debugging.
6. Root your device.
Refer to the documentation for your tool.
7. Install recovery on your device.
Refer to the documentation for your tool.
8. Boot into CMW recovery.
Depending on the device, reboot into recovery may be available in the power menu, or you'll need to press/hold a button during the power on sequence. Refer to the documentation for your recovery.
9. After the device boots into recovery, connect it to the computer.

10. Start ADB shell in command prompt.
Navigate to the folder where adb.exe resides, hold SHIFT, right click the mouse, and select Open command window here, then type adb shell in the command prompt and press ENTER.
11. Execute the following commands one-by-one (you can copy & paste, hit enter, and wait for the output):
Code:
Select Code
umount /storage
parted /dev/block/mmcblk0
print
These commands unmount all drives, launch parted utility for mmcblk0 (onboard flash storage), and display the partition table on your screen.
12. Write down the info from the following columns for partitions Userdata and SDCard (or Media). Usually, they are the last 2 partitions.
Column 1 - Number, Column 2 - Start, Column 3 - End, Column 5 - File system, Column 6 - Name. The start of the first partition and the end of the second partition are the limits, within which your new partitions will be created. The numbers are in megabytes (MB) unless specified. Make sure the name is recorded just as it appears in the partition table - Andorid is case-sensitive.
13. Remove the 2 partitions by executing the following commands:
Adjust the numbers according to your system.
Code:
Select Code
rm 14
rm 15
14. Calculate the new start and end point for both partitions.
For the first partition, the start point will be the same. For the second partition, the end point will be the same. The end point of the first partition is the start point of the second partition.

Take the end number for the first partition you recorded in step 12, add more space to get the new end. Alternatively, if your first partition is actually the emulated storage, subtract the reallocated space to get the new end point. I advise to add at least 2GB (2048MB) to Userdata feel safe about having enough storage for apps. DON'T TRY TO REMOVE EMULATED STORAGE ALTOGETHER BY ALLOCATING ALL OF THE AVAILABLE SPACE TO USERDATA! Emulated storage is coded into OS environment and requires additional modifications to work properly.
15. Create and name new partitions by executing the following commands (don't copy the text in parentheses):
The system might throw several errors in the process. When prompted, just type ignore and hit ENTER.
Code:
Select Code
mkpartfs logical ext2 OLD_START NEW_END (change ext2 to fat32 if the first partition had that file system)
name 14 Userdata (change the number and the name according to your environment)
mkpartfs logical ext2 NEW_START OLD_END (change ext2 to fat32 if the second partition had that file system; make sure to include GB as the designation of the end point in order to stretch the partition to the end of the onboard storage)
name 15 SDCard (change the number and the name according to your environment)
quit
These commands create the partitions with ext2 file system and given beginning and end parameters, rename them as required, and close parted.
16. "Damage" the internal, emulated SD card so that it could be formatted properly later. REMOVE YOUR PHYSICAL SD CARD BEFORE THIS STEP TO AVOID WIPING THE WRONG CARD!!!
Tap Mounts and storage -> Format /storage/sdcard0 -> default and confirm the operation.
17. Insert the physical SD card (sdcard1) that you removed in step 2 back into the device.
Make sure it's mounted by going to Mounts and storage and checking its status (it should say unmount /storage/sdcard1/). If not, mount it by executing on the appropriate option.
18. Execute the following commands one-by-one in the ADB command prompt:
Code:
Select Code
cd /storage/sdcard1/fs-utils (the directory name will be different if you didn't follow my conventions)
tune2fs -j /dev/block/mmcblk0p14 (change the number in mmcblk0pXX according to your environment - that's the partition that need to have file system ext4 - refer to your notes from step 12)
tune2fs -O extents,uninit_bg,dir_index /dev/block/mmcblk0p14 (change the number in mmcblk0pXX according to your environment)
e2fsck -fpDC0 /dev/block/mmcblk0p14 (change the number in mmcblk0pXX according to your environment)
These commands convert Userdata partition into the appropriate ext4 filesystem, which is not supported natively in the recovery environment. If you receive any errors while executing these commands, reboot recovery.
19. Reboot the device into full Android.
19.1 Remove the physical SD card for safety.

19.2 Go to the top menu level of recovery. Then select the top option Reboot the device.
20. When Android loads fully, you'll notice a notification about storage file system. Tap it and follow the prompts to format it.

21. Insert the physical SD card and reboot into the recovery to restore the backup from step 2.
Backup and Restore -> Restore from /storage/sdcard1.
22. Reboot back into full Android and copy the files saved from internal storage back into it. Then reboot again so that apps recognize the data.

DONE!

Short guide/list of ADB commands and other events (*enclosed in asterisks*) if you know the safety drill & bash-based parted utility:
 
Code:
Select Code
*flash 4.1.2 & install recovery*
*boot recovery*
adb shell
umount /storage
parted /dev/block/mmcblk0
print
*record start point of Userdata and end point of SDCard*
rm 15 (change the number according to your environment)
rm 14 (change the number according to your environment)
mkpartfs logical ext2 1621 7865 (change the numbers according to your environment)
name 14 Userdata (change the number and the name according to your environment)
mkpartfs logical ext2 7865 15.6GB (change the numbers according to your environment)
name 15 SDCard (change the number and the name according to your environment)
*remove physical SD card*
*Mounts and storage -> Format /storage/sdcard0 -> default -> confirm*
*insert physical SD card*
*Mounts and storage -> Mount /storage/sdcard1*
cd /storage/sdcard1/fs-utils
tune2fs -j /dev/block/mmcblk0p14 (change the number in mmcblk0pXX according to your environment)
tune2fs -O extents,uninit_bg,dir_index /dev/block/mmcblk0p14 (change the number in mmcblk0pXX according to your environment)
e2fsck -fpDC0 /dev/block/mmcblk0p14 (change the number in mmcblk0pXX according to your environment)
*remove physical SD card*
*reboot*
*format emulated SD card*
*reboot recovery*
*restore backup*
*reboot*
*restore sdcard0/*
*reboot*

Attached Files
File Type: zip fs-utils.zip - [Click for QR Code] (431.3 KB, 2 views)
I do UX design - PM me for information architecture & workflow help.

People like when you THANK them.

My open questions:
Why do many developers host their downloads on spammy file hosting sites?

My devices:
Sony Xperia TL on PureXT 4.3
HP TouchPad 32GB on JCSullins's CM11
Microsoft Surface 2 RT 32GB

My guides:
Upgrading Xperia TL to 4.3 to keep root, data, and LTE
Resizing internal partitions on Xperia T/TL/V (and others)
 
bsined
Old
(Last edited by bsined; 17th April 2014 at 06:17 AM.)
#2  
bsined's Avatar
Senior Member - OP
Thanks Meter 79
Posts: 198
Join Date: Mar 2013
Location: Washington, DC
Sign FAQ

Will it work with Android 4.2/4.3/4.4 or an older version of recovery?
 

So far I have tested with the versions mentioned in the guide. You can test whether this method will work for your setup without jeopardizing any data by completing step 7 of requirements and executing the following commands in ADB shell after booting into your recovery:
Code:
Select Code
parted /dev/block/mmcblk0
print *wait for output*
quit
cd /storage/sdcard1 *change if your physical sdcard is sdcard0*
tune2fs *no parameters*
e2fsck *no parameters*
No errors indicate the method works for you. Please make sure to tell me about your setup in the comments - I'll update the compatibility list.

I do UX design - PM me for information architecture & workflow help.

People like when you THANK them.

My open questions:
Why do many developers host their downloads on spammy file hosting sites?

My devices:
Sony Xperia TL on PureXT 4.3
HP TouchPad 32GB on JCSullins's CM11
Microsoft Surface 2 RT 32GB

My guides:
Upgrading Xperia TL to 4.3 to keep root, data, and LTE
Resizing internal partitions on Xperia T/TL/V (and others)
 
bsined
Old
(Last edited by bsined; 17th April 2014 at 06:10 AM.)
#3  
bsined's Avatar
Senior Member - OP
Thanks Meter 79
Posts: 198
Join Date: Mar 2013
Location: Washington, DC
Phone Tested devices

Did it work on your device or did you fail? Leave a comment and I'll update the list!

Barnes & Noble
- Nook Tablet 16GB

Sony
- Xperia T/TL/TX
I do UX design - PM me for information architecture & workflow help.

People like when you THANK them.

My open questions:
Why do many developers host their downloads on spammy file hosting sites?

My devices:
Sony Xperia TL on PureXT 4.3
HP TouchPad 32GB on JCSullins's CM11
Microsoft Surface 2 RT 32GB

My guides:
Upgrading Xperia TL to 4.3 to keep root, data, and LTE
Resizing internal partitions on Xperia T/TL/V (and others)
 
bsined
Old
#4  
bsined's Avatar
Senior Member - OP
Thanks Meter 79
Posts: 198
Join Date: Mar 2013
Location: Washington, DC
Default Links to tools and recoveries

Reserved
I do UX design - PM me for information architecture & workflow help.

People like when you THANK them.

My open questions:
Why do many developers host their downloads on spammy file hosting sites?

My devices:
Sony Xperia TL on PureXT 4.3
HP TouchPad 32GB on JCSullins's CM11
Microsoft Surface 2 RT 32GB

My guides:
Upgrading Xperia TL to 4.3 to keep root, data, and LTE
Resizing internal partitions on Xperia T/TL/V (and others)
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes