[Samsung Galaxy S (4G Model)] jeffsf:
As this application of the Hefe Hook kernel is likely to generate more questions that "just an ICS kernel" would have, please use the Q&A Thread.

So, you want to have a nice, big, fast data partition so you don't have to worry about running out of space, or wait for all your apps to be mounted, one-by-one, off your SD. You want to be able to try a new ROM without worrying about your data at all as well, eh?

Oh, you're not on Team Acid CM9 or a similar ICS ROM? You can read along, but I don't know of any other SGS4G ROMs with a boot image / kernel that lets you do this the same way.

OK, all that said, breathe deeply and consider that you might lose all your data if things go awry. Breathe easier in that there are some great backup tools out there!

For this to work well, you'll need a good microSD. One that is at least "Class 10" and from a reputable manufacturer is highly recommended. I've had good luck with SanDisk and Transcend. I'm currently using the SanDisk Ultra 64 GB microSDXC Class 10 UHS-1 Memory Card 30MB/s with Adapter SDSDQU-064G-AFFP-A

Today's prices are not as bad as they were a year ago:

16 GB - $13

32 GB - $22

64 GB - $47

These 64 GB cards work just fine in my experience, being able to address all 64 GB in our phones.

These instructions assume that you have a blank card in your hands and aren't going to mess with the one you are presently using in your phone. You'll have to juggle a bit if you are going to "reuse" your current card.

Format your new card

First, we need to prepare that new card. I suggest four partitions, though you can get away with just the first three.

1) "sdcard" -- FAT

2) "sd-ext" -- ext4

3) "data" -- ext4

4) (spare) -- ext4

Here is how I think about partition sizes:

3) "data" -- 2 GB seems reasonable. I'm using about 1 GB and it would probably double if I installed the apps I've pulled off over the time I've had the phone since I didn't have enough space

4) (spare) -- 6 GB -- Why? I can do two full-image, uncompressed backups of 2 GB of data and 1 GB of internal storage. I can use rsync to very, very quickly do a backup as it only had to copy the added/changed files, not the whole thing. (More later on this.)

2) "sd-ext" -- 1 GB -- What do I do with this? All my apps and data are already on the microSD. I need something here so that scripts that grab the second partition don't grab our data partition. It could be smaller, but I figure I've got 1 GB in my pocket in case I fill everything else up.

1) "sdcard" -- 64 GB - 9 GB = 54 GB left. If you have a 16 GB card, it would be 7 GB, pretty tight, and I'd probably sneak some off of sd-ext and the fourth parition. Well, no, I'd spend a couple more dollars and at least buy a 32 GB card.

I do all of my partitioning on machine running Ubuntu. If you run Windows, you can boot into Ubuntu and run it without installing it.

Apologies here that there aren't a lot of details here yet on how to run the disk tool on Ubuntu. I wanted to get this up sooner than later.

Format the drive with a Master Boot Record (MBR) partition table

Add partitions (my 64 GB sizes shown):

1) FAT, 54 GB, "SD64-2-sdcard"

2) ext4, 1 GB, "SD64-2-sd-ext"

3) ext4, 2 GB, "SD64-2-data"

4) ext4, 6 GB (the remainder), "SD64-2-p4"

I name the partitions so that they are easier to manage on desktop machines. Unfortunately, I don't see the kernel picking up the names on the phone. My naming convention is the "SD64-2" identifies a chip -- a SanDisk 64 GB chip that I've scrawled the number "2" on with a marker. I've got a bunch of them and can't remember which is which without marking them.

Now, put that "new" chip somewhere safe, not in the phone!

You've still got your "old" microSD in the phone.

Power it off, remove your SIM card.

Boot it up and plug it in to your computer, if it isn't already. You don't want to run out of battery half-way through something important. Some things are easier through adb than on the phone. You do have adb up and running on your computer, right?

Get Backups

1) Turn off WiFi (yes, really -- you don't want anything changing your data after you've backed it up)

2) Backup with TitaniumBackup

2) Reboot to recovery

3) Run a full backup in recovery

4) Remove your day-to-day microSD

Get your information over to the "new" microSD

There are a lot of ways to do this, the easiest is probably to get both the old and the new chip mounted on a Linux machine and use rsync, along the lines of

rsync -avihP /media/jeff/SD64-1-sdcard/ /media/jeff/SD64-2-sdcard/
rsync -avihP /media/jeff/SD64-2-sd-ext/ /media/jeff/SD64-2-sd-ext/

Be careful with the trailing slashes! Especially if they are missing on the source, you'll get a very different result. The "-a" option is the important one, "-vihP" are all about getting some verbose output that supposedly a human can read as it is copying everything.

Grab a beer, cup of coffee, whatever. There is no magic if you are copying over a bunch of GB from one chip to another, especially over USB.

You now have a copy of your old card on your new card, with the new card having the right partitions.

You can run it again to convince yourself that the two have the same files. I do it myself. If it doesn't copy anything, it should be all good. It is a lot faster when you don't have anything to copy!

Put away your old card somewhere safe. Really. Take it out of your computer.

Get utilities on microSD

Before you take the new chip install a couple things. I use the 4th partition for this as "scratch" space. You want a copy of rsync for your phone, Hefe Hook kernel (2103-12-18 or later), and a version of init-on-fs.sh that mounts your microSD for /data (instead of the internal flash). Do not push init-on-fs.sh to the phone yet!

Get your old /data onto the new card

5) Put the new microSD in your phone. Leave the SIM out!

6) Boot to recovery -- I do this by having the phone connected and hitting "return" on

adb reboot recovery

as soon as I see the Team Acid logo ger replaced my the CyanogenMod boot animation. If it gets to be running, don't panic! No SIM, no WiFi remember? You won't get calls, SMS, push updates, new mail, nothin' Just reboot into recovery and continue.

7) Fire up adb shell, mount the partitions, and get rsync available

mount -a
cp /mmc0p4/rsync /system/xbin/
chmod 755 /system/xbin/rsync

8) Copy over your /data to the new partition!

rsync -avihP /data/ /mmc0p3/

Same warnings on trailing slashes, as well as making yourself confident that everything was copied over by running the rsync command twice.

9) Install init-on-fs.sh that will mount your microSD as /data

cp /mmc0p4/init-on-fs.sh /system/etc/
chmod 755 /system/etc/init-on-fs.sh

My /system/etc/init-on-fs.sh is chatty, but works for me:

#!/system/bin/sh

/system/xbin/busybox mount
/system/xbin/echo
/system/xbin/busybox mkdir /sd-ext
/system/xbin/busybox mount -t ext4 -o noatime /dev/block/mmcblk0p2 /sd-ext
/system/xbin/echo
/system/xbin/busybox mount
/system/xbin/echo
/system/xbin/busybox umount /data
/system/xbin/busybox mount -t ext4 -o noatime /dev/block/mmcblk0p3 /data
/system/xbin/echo
/system/xbin/busybox mount

10) Reboot to Android

Woo hoo!! Check your system space, you should have a bunch of free space on internal now!

Get everything "internal"

You want your stuff off "android secure" since the way that it works is that Android creates a file that is a filesystem for each and every app you've moved to SD. At boot time, it reads the file, mounts it, checks the filesystem, then "hooks up" the app inside. It can take a couple minutes for this to complete! Putting them on "internal" storage does away with that. They are "just there" like your internal apps used to be. That means you get all the widgets and everything too.

(No, I don't know how to turn off notifications when you move the XDA app to "internal" -- the settings don't seem to do anything.)

Don't rush this. You want to be able to get back to /data on the internal flash later if you need to. We haven't erased /data -- it is a handy "backup" there right now.

This assumes you have TitaniumBackup, perhaps Pro is required. If you don't own it already, I think it is a solid product. If you use something else to manage your apps and backups, take this as an outline.

This looks like a lot to do -- but if you ever have to restore to your internal storage, you'll know what you already had on SD so you can restore it there!

11) Mark your on-SD apps -- this is a pretty-well hidden feature, so stick with me

Launch TiB

One it gets going and "all application information has been loaded"

Go to the Backup/Restore tab

Click on "Click to edit filters"

Clear any existing filter and set

Filter by type: User

Filter by location: External

Click the green checkmark in the top right

It should return to the list of apps, all your on-SD apps should be shown

Click on "Click to edit filters" again

Click on the "Create label..." button

Enter a name, "Apps on SD, December 2013" or whatever makes sense to you

Click on "Add/Remove elements..." button

Click on "Select shown elm." button

You should now see only the "filtered" elements

Click the green checkmark in the top right

Click the "Save" button on label dialog

Click the green checkmark in the top right

You should see your on-SD apps tagged. Phew!!

12) Move all your on-SD apps and data to internal storage

Click the grey checkmark in the top right

You should see the Batch actions screen

Run "Move user apps to internal memory"

Run "Move app data to internal memory" (if you have it)

13) Kick back -- you've done it

I'd reboot to recovery at this point and backup your new data partition. The partions you will want to backup now are labeled

boot (mtd)

recovery (mtd)

system (mtd)

efs (mtd) -- once in a while is fine

cache (mtd) -- can skip, it's cache after all

Android Secure -- should be 0 MB, if so, can skip

sd-ext (p2) -- backup if you have important stuff here

data (p3) -- <== this is all your stuff now!

You can skip "userdata (mtd)" now as it is your "old" internal data partition.

You should also see that TWRP will let you put your backup on your choice of partitions on your microSD:

sdcard (p1)

sd-ext (p2)

mmc0p4