[DEV][19NOV] Native Mount DataOnEXT with DalvikOnNAND (Test #2)

Search This thread

ph03n!x

Senior Member
Dec 18, 2010
2,177
1,615
I am sure securecrt will reveal his secret soon, m8.. I wouldn't 'waste' my time on it since he is already running it and knows how to do it ;)

Maybe you can send him a PM if the wait is killing you ?
It indeed is killing me :D I don't want to bother him with a PM, am sure he will get to it soon :)
Anyways, it is stuff like this that'd make you learn some, isn't it?!!
 

Xylograph

Senior Member
Sep 2, 2009
1,825
7,708
It indeed is killing me :D I don't want to bother him with a PM, am sure he will get to it soon :)
Anyways, it is stuff like this that'd make you learn some, isn't it?!!

Yes m8, I am also very curious on how that stuff will perform compared to nand ;)
Anyway have you checked this ROM/Ramdisks.. Features int2sd/d2ext which I think is the same thing you are trying to archieve ?

That ROM features a lot of different a2sd methods to choose from via aroma and I think there are 2 boot.img files included.. 1 with and 1 without the d2ext method.. compare them and see/check how it's done ;)
 
  • Like
Reactions: ph03n!x

NYLimited

Inactive Recognized Contributor
Jan 5, 2008
3,825
2,286
New Hampshire, USA
CWM Recovery will back up SD-EXT as /sd-ext, but Android will load it as /data after this mod. So if you are going to try this mod, you need to titanium backup all you system/ user app+data, install the modified mod or initrd.gz, make sure you have a ext partition, boot to Android and restore the backup from titanium.

Yeah, I could use a second device just for playing! :D

Right, I got the above. I figure that CWM recovery could be used with it as long as the mods are made before flashing. And, it could also be used to restore a previous (different) installation. I like to play but I also need my phone on a regular basis. It is so sad when work gets in the way of having fun!
 

rikusuicide

Senior Member
Oct 6, 2011
405
17
Mayen
I have an question I am using paranoid android ics with an T-Mobile htc hd2. Getting an 32 gb class 10 next week. Will this mod boost user experience? Faster loading for apps and so on? And does it means when I settled everything after reboot it wont work anymore?

Sent from my HTC HD2 using xda premium
 

ph03n!x

Senior Member
Dec 18, 2010
2,177
1,615
Alright, this experiment is a success. Lookup the first three posts for details!
 
Last edited:
  • Like
Reactions: Burag

ph03n!x

Senior Member
Dec 18, 2010
2,177
1,615
I have an question I am using paranoid android ics with an T-Mobile htc hd2. Getting an 32 gb class 10 next week. Will this mod boost user experience? Faster loading for apps and so on? And does it means when I settled everything after reboot it wont work anymore?

Sent from my HTC HD2 using xda premium
In T-Mobile HD2, if you do this modification you will not be limited to the 800 or so MB or internal /data partition and can use space in an EXT partition in your SD Card instead. And yes you will see some improvements in the system's performance if you have a fast SD Card. As of today, I have gotten this modification to work reliably across multiple reboots and ROM Updates.
 

Xylograph

Senior Member
Sep 2, 2009
1,825
7,708
Great stuff m8,

Thanks for the time you put into it to write this up with so much detail !

My compliments,
Xylo

ps. I suppose we can also do this with the (whole) system partition ?
 
  • Like
Reactions: ph03n!x

ph03n!x

Senior Member
Dec 18, 2010
2,177
1,615
Great stuff m8,

Thanks for the time you put into it to write this up with so much detail !

My compliments,
Xylo

ps. I suppose we can also do this with the (whole) system partition ?
Yes, this is how that should be done-
  • SD Card has to be partitioned as 1 FAT, An EXT4 (Meant for /system) and another EXT4 (Meant for /data)
  • Modify the wait4ext script to remove e2fsck (It loads from /system/bin, and we are mounting system from EXT!)
  • Mount /dev/block/mmcblk0p2 for /system and /dev/block/mmcblk0p3 for /data
  • Modify updater-script to mount /system correctly before installing ROM- this I am not sure, might need changes to CWM recovery's initrd too

That said, I have left mounting /system out of this experiment purposefully - once we write the ROM to /system and after the first reboot is completed (Dalvik is created), the /system is read only a few time, that too for build.prop, properties.prop (PA), gps.conf, host, etc. I do not believe there will be substantial performance gains.Moreover installing ROM using current CWM or other recovery may not work like expected.
 
  • Like
Reactions: Burag

rikusuicide

Senior Member
Oct 6, 2011
405
17
Mayen
Also I nerd 2 ext partitions? And can I use the attached file for paranoid ics too?

Sent from my HTC HD2 using xda premium
 

Spaqin

Senior Member
Oct 5, 2010
398
95
Stupid question maybe, but I had to. Would it work with SD builds? And if it would, would it improve speed of those builds? I guess EXT4 partition would be faster than EXT image on FAT partition, right?


rikisuicide said:
Also I nerd 2 ext partitions? And can I use the attached file for paranoid ics too?
No and no. Only one EXT partition is needed and files are for 1.99 JB Paranoid, as stated there.
 

ph03n!x

Senior Member
Dec 18, 2010
2,177
1,615
Also I nerd 2 ext partitions? And can I use the attached file for paranoid ics too?

Sent from my HTC HD2 using xda premium
No, to use the modifications from the first three posts of this thread, you need only one fat and one EXT partition in the SD Card. The 2 ext4 requirement is my answer to Xylograph, and does not concern the modifications I had done.

I do not know how different the PA ICS initrd.gz is from JB (Xylo?). Why don't you post your initrd.gz here, I will do the modifications for you.
Stupid question maybe, but I had to. Would it work with SD builds? And if it would, would it improve speed of those builds? I guess EXT4 partition would be faster than EXT image on FAT partition, right?
To be honest, I don't know if it would give you any difference. Also SD Card is a serial interface - if you have multiple copy or read activities concurrently, all activities tend to slow down - this is one of the reason why I did not try putting /system in the SD Card...
 
Last edited:
  • Like
Reactions: rikusuicide

Kameirus

Senior Member
Feb 5, 2010
5,912
2,355
Akron Ohio
awesome work ph03n!x
i was gonna post my initrd.gz from Xylos aokp jb rom
but gonna wait just in case a update is coming for it hehehehehe
would hate to have to do it twice
 

Xylograph

Senior Member
Sep 2, 2009
1,825
7,708
awesome work ph03n!x
i was gonna post my initrd.gz from Xylos aokp jb rom
but gonna wait just in case a update is coming for it hehehehehe
would hate to have to do it twice

Are you peaking through my window or something ??
Keep checking m8... you could be right ! ;)

Anyway you can also use the PA ramdisk for AOKP as long as it's jellybean.
 
  • Like
Reactions: Kameirus

NYLimited

Inactive Recognized Contributor
Jan 5, 2008
3,825
2,286
New Hampshire, USA
No, to use the modifications from the first three posts of this thread, you need only one fat and one EXT partition in the SD Card.

Why don't you post your initrd.gz here, I will do the modifications for you.

Thanks for your efforts and the instructions!

You got me curious enough to order another sd card. :)

I will play with the mods you outlined and see how far I can get once I have the extra card.

This seems like fun! :)


---
One can never know for sure what a deserted area looks like .. (via Tapatalk)
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 119
    Index

    Thanks to quite a lot of inputs, ideas, testing and feedback, I have been able to give a working solution to reliably mount /data to the EXT partition in our HD2’s SD Card before Android initializes. I am redoing the first three posts of this thread to give a complete info that answers the what, why, how questions.

    Before I even start, let me make my objectives clear:
    • Have a system partition that is as big as I want in NAND, so that I can install any bloated ROM I want without chopping down anything, and yet have a /data partition for all my apps and their bloated data
    • Avoid using internal (NAND) userdata partition completely, so that if the day comes where my /system is full of bad blocks, I will still be able to create a system partition in the ~900+ MB internal NAND my TMoUS HD2 has

    With this method, this is how I am using my phone:
    • Device - TMoUS HD2
    • Boot Loader - cLK 1.5.0.9
    • Partitions (in order) and Sizes - Recovery - 10 MB, Boot - 10 MB, System - 500 MB, Userdata - <I didn't bother :D>, Misc - 1 MB, Cache - 2 MB.
    • Recovery - CWM Based Touch Recovery B8
    • SD Card - 16GB Transcend Class 6 with 4 GB EXT4 Partition (mounted as /data, of course!)

    My idea for this setup is that a user should not be having to get into the boot loader or changing partition sizes for every ROM. With this setup, I am having a close-to-native-Android device setup and can flash any ROM I want, without worrying if my partitions will accommodate it.

    So what exactly does this method do? Before I answer that, a brief on the Android booting process – Note that this is simplified to meet this thread’s requirement, and not necessarily completely accurate. When you power on the phone the following actions happen…

    The Android Boot Process

    1. Bootloader – In HD2’s case, Magldr or cLK – loads the kernel based on how you have configured the phone.
    2. Kernel – The kernel (zImage) is loaded into RAM along with an initial ramdisk (initrd.gz), which initializes various devices (IO, memory, GPU, etc.), interrupts, and mounts the root file system (/). After this, the first user-space process called init is started.
    3. Init – this is a binary file that is contained within the initrd.gz. The init binary processes init.rc and init..rc , along with other .rc files that are called by these two .rc files. Some of the key functions (from this thread’s perspective) in the order of their initialization/ execution are:

      1. The init process follows the instructions in the init.rc and init.xyz.rc files and creates empty directories including /data. It then mounts the storage devices (partitions in the internal NAND (MTD)) to these empty directories. The NAND partition for system is mounted to /system, followed by the partitions specified for data, cache, etc. The directories for dalvik-cache (/data/dalvik-cache) are also created by the init process after mounting the specified device to /data.
      2. The init process then starts various services including adb, service manager, Volume Daemon (vold) for media like SD Card (FAT partition). Most importantly, the zygote service which initiates the Dalivk-Cache is loaded in this sequence.
      3. As we all know, Android is based on Linux. The boot sequence described above is common for all Linux machines – until the zygote stage. Core Android file like core, framework, services, IME, policy, etc. are executed from the Dalvik-Cache and hence Initialization of the Dalvik Cache is pretty much where Android comes into the picture
      4. The sysinit/ run-parts part, which runs scripts from the /system/etc/init.d later the Zygote stage. No matter how this is done, Android has already started loading by the time the boot process comes to executing scripts in /system/etc/init.d

    Now that you know what happens when Android boots, you may also have realized that mounting a device to /data happens early in the boot process.

    Space Restriction in HD2, and the twist with bad blocks

    The 'normal' way to store all OS data (dalvik-cache, Configurations & Settings, Accounts, etc.) and User data (Apps, app data, mails and messages, call logs, etc.) is to have a partition named userdata in the HD2’s NAND, and have it mounted to /data during the init process. The drawback in using the userdata partition is that the space you can have for userdata is inversely affected by the size of your system partition, and whether your phone is an EU/ International HD2 or a TMoUS HD2.

    Best case is, if you have a ~100 MB system partition for a really scaled-down, space-optimized OS, you will get about 800+ MB for userdata partition on TMoUS and ~400 MB on an International/ EU HD2. This space might be good enough for a lot of us who only have light-to-medium use of our phones. But for quite a lot of us, this is a bottleneck. As if that is not enough, we have these villainous bad-blocks that creep up slowly, determined to swallow up the internal NAND completely, though it would be several years down the line before that happens :)

    The Workaround

    The workaround for this method is to have a script in the /system/etc/init.d that mounts the EXT partition in the SD Card to sd-ext, moves a part of /data from the userdata (NAND) to the EXT partition (sd-ext) and creates symlinks (symbolic link) in /data (userdata) to point to the new location in the EXT partition. In this method you will not see an increase in what the phone shows for internal space. The apps you install and then some more will be installed in the EXT partition, which will be symlinked as /data/app and so on.

    The other way is to move the mount point (and the contents) for the /data directory from userdata (NAND) to the EXT partition in the SD Card, mount the userdata (NAND) as sd-ext or some other directory, create dalvik-cache (and maybe /data/data - where all user apps' data are stored) in the userdata and symlink that location back to the EXT partition (which is now /data). In this method, you will get the size of your EXT partition as the internal space. Moving parts of /data to NAND will in theory give you better performance, as the most read/ written part of the phone resides in NAND.

    The benefit of these methods is that it is very simple and easy to install on any rooted ROM through the recovery. This method balances performance by moving the static part of /data (like the .apk you install) to the EXT partition, keeping the dynamic part (/data/data – where all app data are stored, or /data/dalvik-cache – from where all apks are executed) in NAND.

    The drawbacks with this workaround:
    This method is initiated AFTER Android boots. No matter how it is executed or what it does, anything that loads from /system/etc/init.d is executed only after at least some parts of Android loading process is initialized. This leads to weird outcomes – low sound issues, unpredictable behavior of the OS or some apps (Notification Widget toggles not working, etc.), and then some more. There is no reasonable way to predict what issues you may get. In fact you cannot be sure if the issue is with the ROM or if the issue is occurring because of the move2sd script you are using. If you are facing an issue that none others are facing and if you have a move2sd script, then you MUST undo what the script does before you can start troubleshooting.

    In some cases, an in place upgrade (upgrading from one version of the same ROM to a higher/ newer version, or upgrading from one ROM to another ROM of the same Android version/ build) will corrupt the apps' data as well as configuration, etc.

    Moreover, one move2sd script that works fine with one ROM will not work exactly the same way with another ROM or even an updated version of the same ROM.

    There is always some amount hit or miss involved in this workaround!!!
    63
    All - I just got a great news from @kokotas. Migrating to DataOnEXT has just become extremely easy - wait for it :)

    If you have a normal NAND installation(and an ext2/3/4 partition on your card) and want to give ph03n!x's DataOnEXT method a try,
    BUT you think it is difficult THEN you can try the attached recovery package.
    It follows all the steps of the described process AND at the end it copies all of your /data to the ext2/3/4 partition. <= This means that after rebooting, you'll have your system set up as before but with DataOnEXT!

    And if you want to go back to your previous setup (that is a normal NAND installation without DataOnEXT),
    either flash the original kernel to your device or check out the 2nd version(see edit2).

    Have in mind that I have only tested it on my phone. If you do try it, please leave a comment. Especially MAGLDR users! Cause it is not tested with MAGLDR. (edit1: Confirmed working with MAGLDR too)

    Thank you ph03n!x for a great concept!

    edit2: Attaching a revised 2nd version.
    Cleaned up a bit and added an option to revert: At the end of the process a new recovery package (revert_initrd_patch.zip) will be created on the root of your sdcard in order to use it if you wish to revert any changes made by the 1st patch.
    WARNING: The package revert_initrd_patch.zip will DELETE files/folders in /sd-ext ONLY IF they were previously copied from /data using the initrd_patcher.zip. Anything other than that will stay intact (i.e. a folder with a NativeSD Rom;))!
    59
    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.
    If you have a normal NAND installation(and an ext2/3/4 partition on your card) and want to give ph03n!x's DataOnEXT method a try,
    BUT you think it is difficult THEN you can try the attached recovery package.
    It follows all the steps of the described process AND at the end it copies all of your /data to the ext2/3/4 partition. <= This means that after rebooting, you'll have your system set up as before but with DataOnEXT!
    And if you want to go back to your previous setup (that is a normal NAND installation without DataOnEXT), just flash the original kernel to your device.

    Have in mind that I have only tested it on my phone. If you do try it, please leave a comment. Especially MAGLDR users! Cause it is not tested with MAGLDR.

    Thank you ph03n!x for a great concept!

    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:
    image.jpg


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


    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

    1. Back in the Kitchen Menu, select 0 for Advanced Options
      image.jpg


    2. Select 20 for Tools for boot image
      image.jpg


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


    4. 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:
      image.jpg


    5. 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
    6. 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)
    7. Do all the following changes AFTER mount yaffs2 mtd@system /system noatime nodiratime, else the process will fail.

      Code:
      	# 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:
      Code:
      	# SD Card Cache
      	write /sys/devices/virtual/bdi/179:0/read_ahead_kb 2048
    8. Build the NAND boot folder (for Magldr yboot) or boot.img (for cLK / Magldr rboot) as per your requirements
      image.jpg


    9. 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.
    10. Format your phone’s /system, /data, / sd-ext and /boot from clockworkmod and flash this modified rom.zip
    11. Let your phone boot into Android and settle down.
    12. Configure your Google Account
    13. Download and install Titanium Backup
    14. 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)
    41
    Misc & Changelog

    Credits
    • All the Devs who are contributing their valuable time to get Android working on our phones
    • Proz0r for implementing something very similar to what I had wanted. He has essentially implemented the same thing, I am implementing this in a slightly different way, that's all. (To be clear, I did not borrow the idea even though a few others have had the same brainwave that I thought I got first :D - I only borrowed the part where we have the phone wait until the sd-ext partition is ready for being mounted)
    • Rick_1995 for the first hint to get this modification to work
    • Securecrt for showing that this modification is indeed possible
    • Xylograph for pointing me to another thread where this modification is already done
    • marco.palumbi - for showing me that I need not have an elaborate script to ensure /dev/block/mmcblk0p2 is available, and a mount... wait option is available in the CM source for init. Also for doing away with the need for extprep script and including the e2fsck routine complete with a fsck.log in init.rc itself.
    • kokotas - For the recovery-flashable version of this mod that simplifies migrating to DataOnEXT

    Some of the benefits of this mod are:
    • Space - Obvisiouly. The 1GB/ 2GB/ 4GB sd-ext partition will be mounted as internal memory, instead of the usual /data partition from NAND
    • Reliability - EXT4 partition is arguably more reliable than YAFFS2
    • Working around Bad Blocks - Most of our phones would be having a bunch of bad blocks by now (lucky you, Hynix NAND folks!). With this method, the /data partition is mounted directly to the EXT partition in your SD Card, and the internal userdata NAND partition is untouched. This means you can create bigger system partitions to work your way around bad blocks. Incidently all the bad blocks my phone has is in the userdata partition - this might be so because that is the area that is written to the most.
    • Performance - A fast SD Card gives better transfer speeds than NAND (My ParanoidAndroid build is noticeably faster after this modification, with my Class 6 Transcend SD Card with 4GB sd-ext partition)
    • Simplicity - Don't have to worry about hoards of the a2sd scripts and their variants, and carry-out trial and error as to which ones work reliably with your ROM of choice. /data is transparently and natively mounted to sd-ext, so no more low-sound or other odd issues
    • /data/data can be in the sd-ext partition, and ROM updates will not corrupt it like in some a2sd scripts
    • Hassle-free - Whether an EU HD2 or TMoUS HD2, you set a large size (445 MB?!!) for /system and forget about partitioning, as the internal userdata partition is not used at all and can be of whatever size. I am using 300 MB system in both my phones. This is close to native Android phones, where we do not keep changing the system partition size for every ROM that is installed.
    • A proper multi-user setup - if you had to share the phone with someone else, all you have to do is swap out the SD Card you usually have in the phone to a fresh one that has the required FAT and EXT partitions. The other user will see a fresh Android install and configure whatever they want. When you get the phone back, all you have to do is put your usual SD Card back in, and voila! you have all your stuff just the way it was :D (Thanks to @teemoo for the tip!)
    • Trying a new ROM? Make sure you do not botch up your data! Just remove the SD Card you usually use and place one for testing. You can always mod the initrd.gz of your new ROM, flash the boot image or place the initrd,gz in /boot and replace your usual SD Card when you want all your apps, data and settings!

    A Note on Cache
    As many may remember (and some have pointed out), I had the initial trial with 8 MB of cache for SD Card interface. Over a period of time, I tried various sizes from 512 KB to 16 MB and found out that the cache size is dependant on the phone AND the SD Card that is in it. This experiment involves:
    1. Setting a cache size in the extprep script
    2. Booting from the boot.img using fastboot boot command
    3. Waiting for my phone to connect to Google servers
    4. Opening Root Explorer and confirming the cache size
    5. Running SD Tools, testing the SD Card Read/ Write speeds thrice in a row
    6. Changing the cache size in extprep script, recreating a boot,img, and starting from fastboot boot...

    And here are my test results:
    Cache.jpg



    As you can see, the higher the cache, higher the difference between the Minimum and Maximum values for Reads. While this test does not consider ALL aspects (like random reads), this gives a good idea of what is the cache size that is the best for my phone and my SD Card. Note that I have two HD2 with 2 different brand/ class of SD Cards, and bot gave pretty different results. You may have to find the right cache size for your phone! Once you got the right cache, even a Class 2 card (the stock Sandisk 16 GB Class 2 that comes with the TMoUS HD2) performa pretty well - no deal-breaking lags even in games like Temple Run or Ninjump.

    Also, you should be worried more about read speeds - that is what the phone does most of the time. Write speeds comes into picture mostly when you are installing something. All writes that happen after that are mostly incremental, and never something a major as what happens when you install an app.

    Note to ROM Makers on ClockWorkMod Updater Script
    While one of the benefits of this mod is that you can set a huge /system partition and forget trimming down anything, some ROMs mounts /data during CWM install to copy certain apps or parts of /system to the /data partition. For such a setup to work well with this mod, the /data partition should be mounted to the EXT partition in the SD Card. I am not sure if there is a straightforward mount command that can be used in updater-script to mount an MMC partition. Thanks to Looki75's post, I have made the script simpler...

    The code in updater-script...
    Code:
    package_extract_dir("work", "/tmp");
    format("MTD", "system");
    format("MTD", "boot");
    mount("MTD", "system", "/system");
    mount("ext4","/dev/block/mmcblk0p2","/data");
    ui_print("Copying files to /system");
    package_extract_dir("system", "/system");
    ...
    ...
    ui_print("Copying files to /data");
    package_extract_dir("data", "/data");

    FAQ
    I will try and compile some sensible Questions from this thread in the FAQ Section. I request all to read the first three posts at least before asking any questions.

    Q: I have an EXT2/ EXT3 partition. You are mounting it as EXT4. What gives?
    A: Mounting as EXT4 is backwards compatible with EXT2/3 :)

    Q: Where are the initrd.gz that you had posted earlier?
    A: I have moved them to this post

    Q: Will you modify the initrd.gz from the <name of ROM>?
    A: I took more than 6 Hours on a Sunday Night to re-do the first three posts, and give a step-by-step guide. Do you still want me to modify the initrd.gz for you?!! I might post the initrd.gz of ROMs I use or try from time to time, but please don't post requests for modding <name of your ROM>'s initrd.gz. What is that saying about giving a man a fish vs. teaching how to fish...??!

    Q: Is ClockWorkMod or 4EXT or TWRP compatible with this mod?
    A: Before I answer, note that almost all Recovery tools available for HD2 will mount the SD Card's EXT partition to the sd-ext directory. After doing this mod, /data (in Android) = /sd-ext (in Recovery)
    • Any backup that includes the sd-ext partition will backup your /data.
    • At least CWM based recovery will delete dalvik-cache from NAND's data and /sd-ext. After this mod, /data/dalvik-cache (Android) = sd-ext/dalvik-cache (Recovery), so yes deleting Dalvik Cache works
    • CWN Recovery's Fix Permissions runs in both internal data and sd-ext, so yes that works too

    Q: Will installing <name of script/ mod for ROM>, which involves flashing something in Recovery, work after this mod?
    A: If whatever you are flashing is limited to modifications in /system, no problems - it will work.
    If what you are flashing involves changing or adding content to any part of /data then it will probably not. The reason is when you mount data in Recovery, you will by default mount the internal NAND. After this method, the internal NAND is untouched. You must either modify the updater-script (See Note to ROM Makers on ClockWorkMod Updater Script), or use QtADB/ ADB shell to do what the flashing is supposed to do.


    Q: I am getting stuck at boot animation/ getting "Encryption Unsuccessful" message when Android boots...
    A: Your ROM's init binary may not support the mount... wait option that I am using. There are other variants like wait <device>, and then mount <device>, see if you can find what it is from the source code of your ROM's init binary (init.c). If all else fails, you may have to include a copy of busybox in sbin, point all commands in extprep script to that busybox, and increase the sleep time using /sbin/busybox sleep 25 (that is an example). In any case, you DO NOT HAVE TO WIPE DATA or WIPE ANYTHING AS SUGGESTED BY THE INSTRUCTIONS IN "Encryption Unsuccessful" message

    Q: Can I move part of /data from EXT partition to NAND?
    A: You don't have to move anything - that is the beauty of this mod. If, for example, you want dalvik-cache to be in NAND, all you have to do is create a directory, mount NAND to that directory, and symlink /data/dalvik-cache to that directory. Example: In init.rc, make sure /data/dalvik-cache is NOT getting created (comment that line out with a #)
    Code:
    mkdir /dalvik 0771 system system
    mount yaffs2 mtd@userdata /dalvik nodev nosuid noatime nodiratime
    symlink /dalvik /data/dalvik-cache

    Q: How do I improve performance?
    SD Card interface by design cannot handle multiple read/ write activities simultaneously. An example: Put the SD Card in a card reader attached to your computer. Copy a ~500MB file to it, see what write speeds your get (Win 7 shows an approx value). Now, while the first file is still being copied, copy another similar sized file - what happens to the write speed? It crawls, right?

    When you have DataOnEXT, the SD Card is continuously being read from and written to because all your apps, their data, system data and configuration, etc. resides in the EXT partition. You SHOULD NOT expect the same speeds like a full-NAND setup. That said, there a few things you can do to improve performance:
    • Get a performance SD Card like SanDisk Ultra® microSDXC™UHS-I card
    • ODEX your ROM
    • See the previous question's answer for moving dalvik cache to NAND
    • Increase the NAND's read ahead cache from 4KB to 128 ot 256KB (in init.htcleo.rc)
    • Set your IO Scheduler to Deadline (use No frills CPU Control)

    Q: My ROM slows to a crawl after installing this mod when I install or remove an app...
    A: That is normal behavior, let it be for a min or two and it will get back to the usual speeds. This is because installing or removing an app involves creating the DEX file in the dalvik cache, extracting the components (lib files, config files, etc.) for the app and placing them in appropriate locations in /data and so on. This will slow down the system responsiveness because all of these are in the EXT partition, and the SD Card interface is a serial interface that will slow down with multiple simultaneous read/ write requests. However, doing what I have said for the previous question will improve performance quite a bit

    FAQ is still WIP, I will keep adding to this section as and when...
    15
    Update:

    Have been trying to install and boot a ROM from entirely a single EXT partition that contains a directory for /system and one for /data, with dalvik cache in nand, just like Rick had suggested.

    Have partially succeeded- the ROM installs fine, but can't get /system to mount to the directory (init.rc). Will try to figure it out later, pretty pressed for time with work stuff :)

    Swyped from my HTC HD2 using XDA Premium