[HD2 Android NAND Development] ph03n!x:
The Solution

…is what this thread is all about. Like we saw, /data directory is mounted to a storage device pretty early in the boot process – so early that it is only Linux at the time /data gets mounted and Android is still yet to be loaded. The storage device that is traditionally mounted to /data directory is the internal NAND’s userdata partition.

The simple solution I have for unrestricted and reliable internal space is to directly mount the EXT partition of the SD Card to /data during the Linux init process (instead of first mounting the NAND’s userdata, loading Android, and moving the /data mount point or some contents within /data to the EXT partition while Android is loading).

How is this done?

The Easy way - Thanks to @Kokotas

(Note that I have not updated Kokotas' .zip file to include the recent changes (20th October 2012) (See The Long Way below)

Visit the post (quoted below), thank @Kokotas, download the .zip from the post, flash it in recovery and lets us know how it goes. Did I tell you to make sure you have a NANDROID backup?

This .zip can be used to install DataOnEXT mod on the fly - your ROM will be the same when you reboot after flashing this .zip, except that /data will be mounted from the EXT partition with all your apps, settings, etc. intact.

The Long Way (or this is how I started off doing this mod :) )

The following steps show how to modify a ROM’s boot process to mount the EXT partition as /data.

IMPORTANT: THIS PROCESS INVOLVES USING DISXDA’s KITCHEN in CYGWIN. I EXPECT YOU TO BE ABLE TO SETUP CYGWIN AND USE DSIXDA KITCHEN. EVEN WHILE I AM TRYING TO GIVE A STEP-BY-STEP HERE, I WILL NOT ANSWER QUESTIONS ON HOW TO SETUP AND TROUBLESHOOT DSIXDA’s KITCHEN OR CYGWIN.

Assumption:

For the sake of simplicity, I am going to assume that you have a ROM that is installed in your phone, and you want to modify the same ROM for natively mounting EXT to /data.

I am also going to assume that your HD2 has a SD Card in it, and the SD Card has been partitioned in such a way that the first partition is the FAT partition that Windows sees, and the second partition is a EXT2/3/4 partition. You may or may not have a Swap partition, but I strongly recommend NOT enabling Swap.

Prerequisites:

Take a NANDROID backup using ClockWorkMod

Back up all user apps and system app data using Titanium Backup

Install Cygwin

Install @dsixda’s Kitchen

Install Notepad++ (or any other UNIX compatible text editor)

@dsixda’s Kitchen – Setting up a working folder

While these steps will involve the entire ROM, note that you will only using the boot directory or boot.img for this mod.

You need a rom.zip file that has at least these three directories when you open the .zip – META-INF, system, boot (or boot.img)

If your rom.zip file has a different structure, just extract the three directories alone from it and create a new zip. Essentially, when open the rom.zip you should see only these three directories

An Example:

Place this zip file in the original_update directory under Kitchen. A sample directory structure of the Kitchen is as follows:

From Command Prompt, run cygwin.bat, browse to the directory where you have installed the kitchen and run it using ./menu

Select option 1 for setting up a Working Folder, follow instructions. Congratulation! You should have a working folder now. After the Working Folder is setup, navigate to the WORKING_091712_123456 directory. Make sure you have a directory named boot, or a boot.img here. To be double sure, you can replace the boot directory or boot.img with the one from the ROM you want to modify and flash.

Steps for mounting EXT to /data

Back in the Kitchen Menu, select 0 for Advanced Options

Select 20 for Tools for boot image

Hit z for Extract kernel+ramdisk from NAND boot folder (or w for Extract kernel+ramdisk from boot.img)

Now navigate to the BOOT-EXTRACTED directory that got created under the directory where you installed the kitchen. You will see something similar to this:

Edit init.rc and init.htcleo.rc to find all mentions of sd-ext and comment them out with # in the begining. This step is to ensure there is no directory called sd-ext when your phone boots, avoiding any confusions

In init.rc, look for the on fs part. Under this part there will be a line that reads mount yaffs2 mtd@system /system noatime nodiratime. Below this will be another line that reads mount yaffs2 mtd@userdata /data nosuid nodev noatime nodiratime. Comment this line out with a # (#mount yaffs2 mtd@userdata /data nosuid nodev noatime nodiratime). Also, if you have mount yaffs2 mtd@system /system ro remount, comment that out too (make it #mount yaffs2 mtd@system /system ro remount)

Do all the following changes

AFTER

mount yaffs2 mtd@system /system noatime nodiratime, else the process will fail.

# Wait to ensure SD Card is available, and scanning file system of EXT
wait /dev/block/mmcblk0p2
wait /dev/block/mmcblk0p2
wait /dev/block/mmcblk0p2
wait /dev/block/mmcblk0p2
exec /system/xbin/busybox sh -c "/system/bin/e2fsck -f -p -t -t -v /dev/block/mmcblk0p2 > /system/fsck.log"

# Native Mount DataOnEXT
mount ext4 /dev/block/mmcblk0p2 /data wait nosuid nodev noatime nodiratime barrier=0 data=writeback

Leave everything else in this section as is - you will have another line to mount cache, do not remove or modify it.

Next, scroll down to the section that reads on boot. Add the following like under it:

# SD Card Cache
write /sys/devices/virtual/bdi/179:0/read_ahead_kb 2048

Build the NAND boot folder (for Magldr yboot) or boot.img (for cLK / Magldr rboot) as per your requirements

Head back to the Working folder, copy the boot directory or the boot.img and include it in your original ROM’s zip file (not the one you created for the kitchen, in case you had to). Check the init.d directory of the ROM’s zip to ensure there is no script that mounts the EXT partition to sd-ext directory, or has a move2sd/ app2sd/ int2sd script – delete such scripts!. Also make sure that your ROM's inatallation does not copy anything to /data during Installation. If it does, move those parts to /system. Or use the instructions I had given under Note to ROM Makers on ClockWorkMod Updater Script to mount the EXT partition as /data in Recovery.

Format your phone’s /system, /data, / sd-ext and /boot from clockworkmod and flash this modified rom.zip

Let your phone boot into Android and settle down.

Configure your Google Account

Download and install Titanium Backup

In Titanium Backup, restore all apps and their data from the backup you had taken earlier

You phone must now have an internal storage that is roughly equal to the size of your SD Card

Note:

I have tested this method with CM7, CM9, CM10 (ParanoidAndroid JB) and Sense ROMs. There has also been feedback that this is working on other AOSP based ROMs like MIUI.

The mount wait command is available in the init binary from CM7 onwards (not sure if it is there in CM6). If you are not sure (or cannot check the source code for init.c)