5,597,198 Members 43,465 Now Online
XDA Developers Android and Mobile Development Forum

[How-to] How I expanded my app storage (repartitioning)

Tip us?
 
eldarerathis
Old
(Last edited by eldarerathis; 28th December 2011 at 02:39 PM.)
#1  
Senior Member - OP
Thanks Meter 299
Posts: 154
Join Date: Jun 2010
Default [How-to] How I expanded my app storage (repartitioning)

I took some time today to play with the partition layout on my Kindle Fire and I decided I wanted to share my method in case anyone else found it interesting. The reason I did this is because I know that I'm not going to be putting much of anything onto the KF's /sdcard directory. Instead of having 1 GB for data/apps (and books?) and 5 GB for media, I wanted to more-or-less reverse those numbers. What I settled on was 4.5 GB for data/apps and about 1.7 GB of "external" storage. In other words, I can install 4 times as many apps as I could have on a stock layout, but can only store about 1/3 as much music/pictures/etc.

BIG HONKING DISCLAIMER: I have ONLY tested this on my own personal Kindle Fire. There is some very real potential that you could render your system unbootable if you're not careful, so if you want to try this or something similar, please BE CAREFUL, and please don't try to hold me responsible if something gets messed up. You've been fairly warned! You also stand the chance of losing your data partition by doing this. If you have anything you don't want to lose, please make a backup of some sort. That being said, as long as you're careful when doing this it should be fairly safe and you shouldn't lose your data, either.

1. Preparation

1.1 Installing a custom bootloader (FIREFIREFIRE)

Strictly speaking, this is somewhat "optional", but it makes things a whole lot easier. I strongly suggest that you head on over to pokey9000's thread and install his custom bootloader. Not only will this get you into recovery much more easily, but it will give you access to fastboot on every boot up (which will be very helpful if something goes wrong). I won't repeat the installation instructions here, just head over there and follow the instructions!

1.2 Installing a custom recovery (ClockworkMod)

The second thing you'll need is ClockworkMod recovery. Again, the heavy lifting is mostly done, and you can jump over to JackpotCalvin's installation and info thread to get it. Don't worry about the fact that you can't navigate the recovery menu - we won't be using that. The only purpose of the recovery is that it gives us an environment to safely work in with the /data and /cache partitions unmounted (i.e. not being used).

1.3 Root your Kindle Fire

You could do most of this (maybe all of the partitioning, in fact) without rooting, but at best you would lose everything on your /data partition. I'm not even positive if you could do the partitioning without root since...well, I was already rooted when I tried this. In any case, head over to this thread, get SuperOneClick, and root your KF. You'll be voiding your warranty by doing the rest of this anyway

1.4 ADB connection

Make sure you have ADB set up on your computer. You can follow the rooting guide to get this working. You can't do anything else in this post without working ADB.

1.5 (Optional) The parted and e2fsprogs binaries

This is somewhat optional since CWM has the utilities you need already, but it's not a bad idea to have a backup copy of the parted utility and the various e2fsprogs binaries (e2fsck, tune2fs, etc). You can grab this zip file and set it aside somewhere in case you need it. Here is the documentation for parted (applies to both the CWM binaries and the standalone ones).

2. Repartitioning your device

2.1 Backup your data

I cannot stress this enough: backup anything you don't want to lose. And don't just back it up to the external storage, either - move it to your computer or dropbox or something. I also highly recommend following the instructions in the FIREFIREFIRE thread to pull images of your various partitions in their current layout, in case you need to restore through fastboot (or you need them later down the line). Backing up your external data is as simple as copying it to your computer. To backup your /data partition, you can do the following:

Code:
C:\> adb shell
$ su
# cd /data
# tar -cvpzf /sdcard/data.tar.gz .
Note the "." at the end of the last line (in *nix this means "the current directory"). This will create an archive on your external storage named data.tar.gz. You should copy this to your computer for now, to make sure nothing happens to it. This could take a few minutes depending on how much stuff you already have on your /data partition, of course (mine was ~500 MB compressed).

Once you've backed up everything you want, reboot your Kindle by turning off and back on again. You should land at the FIREFIREFIRE bootloader (a yellow triangle with a flame in it). When you see the bootloader come up, press the power button (I had to hold it for a few seconds) to boot into ClockworkMod.

3. Repartitioning

3.1 External storage (/sdcard)

Time for the fun part

Use adb to shell into your device, and then run 'mount' with no parameters to see what's already mounted. You should see /cache has been mounted, and since we'll be moving it later we'll go ahead and unmount it now:

Code:
C:\> adb shell
~ # umount /cache
At this point, your /cache, /data and /sdcard partitions should all be unmounted. Now you need to start up the parted partition manager, which should be included with CWM (it's in /sbin). Fire it up and check your current partition layout by doing the following. Note that
Code:
(parted)
is the prompt that parted gives you after you start it up.

Code:
~ # parted /dev/block/mmcblk0
GNU Parted 1.8.8.1.179-aef3
Using /dev/block/mmcblk0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
print
print
Model: MMC M8G2FA (sd/mmc)
Disk /dev/block/mmcblk0: 7734MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name        Flags
 1      131kB   262kB   131kB                xloader
 2      262kB   524kB   262kB                bootloader
 3      524kB   11.0MB  10.5MB               dkernel
 4      11.0MB  212MB   201MB   ext4         dfs
 5      212MB   229MB   16.8MB               recovery
 6      229MB   296MB   67.1MB  ext4         backup
 7      296MB   307MB   10.5MB               boot
 8      307MB   312MB   5243kB  ext4         splash
 9      312MB   849MB   537MB   ext4         system
10      849MB   2041MB  1192MB  ext4         userdata
11      2041MB  2309MB  268MB   ext4         cache
12      2309MB  7690MB  5381MB  fat32        media       msftres

(parted)
I highly recommend that you store this in a text file somewhere. I saved a copy to my Dropbox to make sure I don't lose it. The reason I say this is because I don't know how a custom partition layout will affect things like OTA updates. If you ever want to go back to the default layout, you'll need these numbers handy.

Now you can go ahead and resize your external partition, which is block 12 ("media"). Make sure you don't try to make it smaller than its contents, or else it will probably error out. For example, if you have 2 GB of music on your /sdcard storage, you won't want to shrink it to 1 GB. What you want to do to shrink the partition is increase the start value. If you were looking at this graphically, it would be equivalent to moving the start of the partition to the right. So, for example, I moved the start of my external partition from the default 2309 to 5809 (5809 - 2309 = 3500, so I made it 3.5 GB smaller). You can choose whatever size you want, and then set it like this:

Code:
(parted) resize 12 5809 7690
This says "resize partition 12 so that it starts at 5809 and ends at 7690 (same as the current end point, which is the end of the disk). As long as you don't see any errors, this should not affect your sdcard's data. I did not lose any of my data by doing this. If you want, you can reboot now to test and make sure everything is in good shape, but it's not required.

3.2 The /cache partition

Since data is partition 10, cache is 11, and media is 12, we now have a gap between the end of cache and the beginning of media. In order to expand the data partition to fill that gap, we need to move the cache partition so that it is next to media again. Unfortunately, parted doesn't support moving an ext4 partition, so we have to make some magic happen first. Basically, we're going to erase the current cache partition, create a new one that is ext2 in the proper spot, and then "upgrade" it to an ext4 partition.

To erase the cache partition (which will erase /cache's data - no big deal), do the following in parted:

Code:
(parted) rm 11
(parted) mkpartfs primary ext2 <begin> <end>
(parted) name 11 cache
To figure out the "begin" value, take the beginning value you used for your external partition and subtract 268. This will be the beginning of the cache partition (assuming you want it to stay the same size as before - this is what I recommend). For the "end" value, use the same number that you entered for the beginning of your media partition. Using my example, 5809 - 268 = 5541, so I used 5541 for the beginning and 5809 for the end. If you enter the "print" command again, you should now see that your cache partition has effectively been moved so that it's right next to your media partition again. Now we need to exit parted to "upgrade" the partition to ext4 by enabling some filesystem features and letting e2fsck run a check on the filesystem. It may say that it's fixing some group descriptor checksums - don't worry, this is normal.

Code:
(parted) quit
~ # tune2fs -j /dev/block/mmcblk0p11
~ # e2fsck -fDp /dev/block/mmcblk0p11
~ # tune2fs -O extents,uninit_bg,dir_index /dev/block/mmcblk0p11
~ # e2fsck -fDp /dev/block/mmcblk0p11
If e2fsck complains that it needs to be run manually, you should omit the -p flag. This happened to me the second time I ran through this process, but the first time it did not. I'm not entirely sure why. In that case, the e2fsck commands simply become:

Code:
~ # e2fsck -fD /dev/block/mmcblk0p11
Which will cause it to ask if you want to fix the group descriptors. Just answer 'Y' and let it run through.

3.3. The userdata partition (/data)

The last thing we need to do is expand the userdata partition to use up the space we freed up by shrinking media. Once again, since we can't resize an ext4 partition directly, we're going to have to delete it, re-create it as an ext2 partition, and then "upgrade" it.

STOP. DO NOT PASS GO. DO NOT COLLECT $200
This will wipe your /data partition. Double check to make sure you have a copy of your backed up data, because it's going to be gone after this.

Code:
~ # parted /dev/block/mmcblk0
(parted) rm 10
(parted) mkpartfs primary ext2 849 <end>
(parted) name 10 userdata
Here the value of <end> should simply be the same as the beginning of your cache partition (in my case this was 5541). This creates the new partition between system and cache, and it takes up all of the available space. Next we need to enable the ext4 features, so we'll do the same thing we did with cache:

Code:
(parted) quit
~ # tune2fs -j /dev/block/mmcblk0p10
~ # e2fsck -fDp /dev/block/mmcblk0p10
~ # tune2fs extents,uninit_bg,dir_index /dev/block/mmcblk0p10
~ # e2fsck -fDp /dev/block/mmcblk0p10
At this point you can fire up parted again and use print to see your shiny new partition layout:

Code:
# parted /dev/block/mmcblk0
parted /dev/block/mmcblk0
GNU Parted 1.8.8.1.179-aef3
Using /dev/block/mmcblk0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
print
print
Model: MMC M8G2FA (sd/mmc)
Disk /dev/block/mmcblk0: 7734MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name        Flags
 1      131kB   262kB   131kB                xloader
 2      262kB   524kB   262kB                bootloader
 3      524kB   11.0MB  10.5MB               dkernel
 4      11.0MB  212MB   201MB   ext4         dfs
 5      212MB   229MB   16.8MB               recovery
 6      229MB   296MB   67.1MB  ext4         backup
 7      296MB   307MB   10.5MB               boot
 8      307MB   312MB   5243kB  ext4         splash
 9      312MB   849MB   537MB   ext4         system
10      849MB   5541MB  4692MB  ext4         userdata
11      5541MB  5809MB  268MB   ext4         cache
12      5809MB  7690MB  1881MB  fat32        media       msftres
As you can see, the userdata partition is now 4692 MB You'll also notice that Titanium Backup will report the new size, so you can keep track of how much space you've used up.

4. Restoring your data from the archive

Don't reboot your Kindle Fire yet! Remember the data we backed up earlier into the data.tar.gz archive? Now we need to restore it to your nice new data partition. First mount your /data partition so you can get at it from the recovery shell:

Code:
~ # mount /dev/block/mmcblk0p10 /data
Now push your backup to your phone. From a command shell on our computer, just use adb push to move it over:

Code:
C:\> adb push /path/to/data.tar.gz /data
Now you can go back to your adb shell and extract everything you backed up earlier. Once it finishes extracting you can go ahead and remove the backup from your /data partition and reboot:

Code:
~ # cd /data
/data # tar -xvpzf data.tar.gz
/data # rm data.tar.gz
/data # reboot
And that's it! Now you should have a larger /data partition, and you can go on an app installation spree.

5. Credits/Thanks/Etc

Just want to give a quick thanks to JackpotCalvin and pokey9000 for CWM and the custom bootloader, since I obviously needed those to make this happen. Also thanks to all the other devs working on the KF for all the great work so far!

If something doesn't work, feel free to drop a reply here. I'll see what I can do to help, but bear in mind that this is intended to be for power users or extreme tweakers. I'd definitely be interested in hearing some success stories if anybody else decides to give this a try.

I also want to add a shoutout/plug for the Android Enthusiasts website, hosted by StackExchange. It's a Q&A site dedicated to power users of Android devices. Stop by if you have a question, I'm always hanging around!

Got an Android question? Stop by Android Enthusiasts!
The Following 31 Users Say Thank You to eldarerathis For This Useful Post: [ Click to Expand ]
 
SikYou
Old
#2  
SikYou's Avatar
Senior Member
Thanks Meter 61
Posts: 389
Join Date: Oct 2010

 
DONATE TO ME
Very impressive tuto! I haven't tried it because I haven't run out of space yet but sounds great and I'm glad to know that it is here when I need it. Thanks!

Sent from my Kindle Fire using Tapatalk
I love you!
 
eldarerathis
Old
#3  
Senior Member - OP
Thanks Meter 299
Posts: 154
Join Date: Jun 2010
Quote:
Originally Posted by SikYou View Post
Very impressive tuto! I haven't tried it because I haven't run out of space yet but sounds great and I'm glad to know that it is here when I need it. Thanks!

Sent from my Kindle Fire using Tapatalk
Thanks! I got motivated to play around with it today when I realized I'd already eaten through 500 MB of my internal storage. All those "wifi only" game downloads really add up...

Also, here's a screenshot of Ti after I repartitioned. Note that my internal storage is at 3.73GB out of 4.61GB at the bottom
Attached Thumbnails
Click image for larger version

Name:	shot_000001.jpg
Views:	2370
Size:	24.6 KB
ID:	814649  

Got an Android question? Stop by Android Enthusiasts!
The Following 2 Users Say Thank You to eldarerathis For This Useful Post: [ Click to Expand ]
 
foxdog66
Old
#4  
Senior Member
Thanks Meter 43
Posts: 406
Join Date: Jul 2010
Sweet! Made me double check my space and yeah.... Those games do eat up a lot of space
 
stocaprimo
Old
#5  
stocaprimo's Avatar
Senior Member
Thanks Meter 5
Posts: 102
Join Date: Jan 2008
Location: Rome
I don't know if I'll ever change the partitions layout, but this guide is absolutely impressive.
 
renegade027
Old
#6  
renegade027's Avatar
Member
Thanks Meter 19
Posts: 99
Join Date: Jul 2010
Location: Wimbledon, UK
WOW!!! Great!

I was thinking of what would it take to go the other way, actually. I mean,

1) I don't care about any future OTA updates from Amazon, so I definitely don't need a 500+ Mb /system partition.

2)/512 Mb will be more than enough for me on /data - anything I can't fit in that, I'll be able to just move to the /media partition.

3) Since I won't be flashing any OTA updates, I don't need this huge /cache partition either - I have 2Mb on my phone, but I think there's a script in the ROM that actively avoids using the cache partition for anything really.

4) What is /dfs and why do we need 200 Mb there...

This all adds up to nearly 2GB more space I can definitely use in the /media partition....

Do you guys think this could work? I.e - apply the same approach to /system - back up/shrink/restore?
Currently tinkering with:
Galaxy Note 3 (SM-N9005) Radio:XXUBMI6 Recovery:CWM (by Xiaolu) 6.0.4.4 20131017 Kernel:Stock MJ6 SELinux: Enforcing ROM:X-Note v4 (MJ6)
Galaxy S4 (GT-I9505) Radio:XXUDMI1 Recovery:CWM 6.0.4.4 PhilZ Touch 5 Kernel:faux123-007u-MEA_r2ck SELinux: Permissive ROM: Omega v12 (MI1)
Nexus 7 (2012) Bootloader:4.18 Recovery:TWRP 2.5.0.0 Kernel:LeanKernel 1.7 (20130614) ROM:SmoothROM v5.2 (Android 4.2.2)
 
eldarerathis
Old
#7  
Senior Member - OP
Thanks Meter 299
Posts: 154
Join Date: Jun 2010
Quote:
Originally Posted by renegade027 View Post
WOW!!! Great!

I was thinking of what would it take to go the other way, actually. I mean,

1) I don't care about any future OTA updates from Amazon, so I definitely don't need a 500+ Mb /system partition.

2)/512 Mb will be more than enough for me on /data - anything I can't fit in that, I'll be able to just move to the /media partition.

3) Since I won't be flashing any OTA updates, I don't need this huge /cache partition either - I have 2Mb on my phone, but I think there's a script in the ROM that actively avoids using the cache partition for anything really.

4) What is /dfs and why do we need 200 Mb there...

This all adds up to nearly 2GB more space I can definitely use in the /media partition....

Do you guys think this could work? I.e - apply the same approach to /system - back up/shrink/restore?
I would think you could do this as long as you make sure you get a good backup of /system and it restores properly, but I've never tried. You'd just need to be a little careful since you would have to erase and repartition it since parted doesn't understand ext4, although as long as you can get into recovery and fastboot you could partition back to normal and flash a stock system image if something went wrong (at least you should be able to). I'm probably not going to try that since I'm fine with this layout and I've only got my personal KF, but it doesn't sound unreasonable.

I'm not sure what /dfs, /dkernel or /backup are, either. I thought I saw a thread somewhere that had some talk about them, but I don't remember where it was. /dkernel is actually the same size as the /boot partition - which made me suspicious - but I can't unpack the image with my usual unpack/repack scripts so I'm not sure what it really is and I don't want to mess with it

Got an Android question? Stop by Android Enthusiasts!
 
rmagruder
Old
#8  
Senior Member
Thanks Meter 22
Posts: 241
Join Date: Aug 2009
Assuming you do everything right, how long would you expect this process to take?
 
californiarailroader
Old
#9  
californiarailroader's Avatar
Senior Member
Thanks Meter 403
Posts: 3,867
Join Date: Mar 2006
Location: Redwood Valley, Northwestern California (Previous-Pocatello, Idaho(90-97)/Southern California(71-90)
WOW, that's a lot of work for just a little bit more space! Good write up though, thanks!
 
eldarerathis
Old
(Last edited by eldarerathis; 13th December 2011 at 03:59 PM.)
#10  
Senior Member - OP
Thanks Meter 299
Posts: 154
Join Date: Jun 2010
Quote:
Originally Posted by rmagruder View Post
Assuming you do everything right, how long would you expect this process to take?
I'd wager you could probably knock this out in about 20-30 minutes, depending on how much stuff is on your /data partition.

The longest part, by far, was archiving and unarchiving /data. All of the partitioning commands together would only take, like, 10 minutes or so (they execute very fast). Archiving the /data partition alone took about 4 or 5 minutes for me and my archive was ~500 MB. Unzipping the archive later was another 3-5 minutes.

Altogether it probably took me about 45 minutes of actual time since I was playing with numbers and writing stuff down periodically.

I know it looks like it would take a lot longer, but I just have a tendency to write very, uh, "thorough" documentation. It's mostly out of habit (I'm a software developer).

Got an Android question? Stop by Android Enthusiasts!

The Following User Says Thank You to eldarerathis For This Useful Post: [ Click to Expand ]
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes