[Asus Transformer TF700] _that:
Tired of backup, wipe, flash, backup, wipe, restore, ... just to try a different ROM?

Today we will cook a nice tasty dual-boot for the TF700T. You will have two separate environments with different ROMs, apps and data that share only the common Linux kernel binary.

Difficulty: medium. No programming skills required, but not for noobs.

Ingredients

1 TF700T running a rooted stock-based ROM with busybox and a kernel with preinit support (hint: -that kernels work fine :))

1 PC running Linux with a microSD card reader

1 fast microSD card with at least 4 GB

1 CyanogenMod 10.2 nightly ZIP (should also work for other ROMs - post your results)

1 seasoned chef

Time required: about 30 to 45 minutes.

Directions

Preheat oven to 220 degree celsius ... oops, wrong recipe. :)

If done right, the internal ROM and its data are perfectly safe. But I assume you have a backup nevertheless - don't blame me if anything goes wrong.

Prepare the microSD card

Insert microSD card into PC card reader. Using gparted, create and format 3 primary partitions:

p1: fat32, this will be your external sdcard as before.

p2: ext4, this will become /data

p3: ext4, this will become /system

Make sure to align the partitions to MiB, or even better multiples of 4 MiB. This may improve I/O performance.

In most cases you can simply shrink the existing FAT32 partition and then create the remaining ext4 partitions.

Partition 3 should be 700 to 800 MB - anything bigger is a waste of space, and anything smaller than 500 MB might cause problems.

Partition 2 will be your whole "internal storage" for the second operating system, so size it according to your storage needs for apps, app data and the emulated /sdcard.

I am using a Samsung 16 GB card with the following partition sizes:

p1: ~ 8 GB

p2: ~ 6 GB

p3: ~ 800 MB

Prepare the new ROM

Before installing the second ROM to the microSD card, the ZIP file must be slightly modified. I assume you know how to unpack and repack a ZIP file and how to use a text editor - if not, find a tutorial elsewhere. :).

Note: This step can now be automated, see http://xdaforums.com/showpost.php?p=47333729&postcount=31

To do it manually:

First, extract boot.blob and set it aside for later. Then carefully remove it from the ZIP. Second, find META-INF/com/google/android/updater-script and modify it:

Replace all occurrences of mmcblk0p1 with mmcblk1p3. I had 3 occurrences in CM's updater-script - make sure you modify all of them, otherwise your internal ROM might not survive the installation. This change will redirect the installation to the external microSD card. Finally, remove the line that says package_extract_file("boot.blob", ...) near the end - it would overwrite the kernel and we don't want that.

Now we need to add the WiFi modules. These are compiled directly into the CM kernel, but separate modules in the stock kernel.

Get the kernel modules from your running ROM - they are in /system/lib/modules (e.g. using adb pull /system/lib/modules), and copy at least these two into the ZIP into /system/lib/modules:

cfg80211.ko

bcmdhd.ko (note: for TF300, I think you need bcmdhd_29.ko instead)

Finally, repack the ZIP, mount the first partition of your microSD card and copy the ZIP file there.

Extract the ramdisk files

Note: This step can now be automated, see http://xdaforums.com/showpost.php?p=47333729&postcount=31

To do it manually:

Here comes the tricky part. You need to extract the ramdisk from the boot.blob you saved from the ZIP file in the previous step.

To do that, you need tools that may not be in every household, but should be easy to find using your favorite search engine. In case you have trouble finding and/or compiling them, you can find the result of this step in post #2.

First we need to unpack the blob (https://github.com/AndroidRoot/BlobTools):

blobunpack boot.blob

This will create boob.blob.LNX. This is the boot image, from which we need to extract the ramdisk (https://github.com/huaixzk/unpackbootimg):

unpackbootimg -i boot.blob.LNX

This will create several files, we are interested in boot.blob.LNX-ramdisk.gz - copy this one to your tablet, e.g. into /sdcard. For example:

adb push boot.blob.LNX-ramdisk.gz /sdcard/

Prepare the preinit script and the ramdisk files

Note: This step can now be automated, see http://xdaforums.com/showpost.php?p=47333729&postcount=31

To do it manually:

On the tablet, open a shell in a terminal app or use adb shell and become root (su). Run the following commands:

mount -o remount,rw /system
cd /system
mkdir boot
cd boot
mkdir rootfs_cm
cd rootfs_cm
gzip -d -c /sdcard/boot.blob.LNX-ramdisk.gz | cpio -i

The first line makes /system writable until the next reboot. The next few lines are self-explanatory. The last line uncompresses the ramdisk image we created in the previous step and extracts the contained files. We are doing this on the tablet itself to preserve the file permissions.

Now modify the file fstab.cardhu (one of the files just extracted).

Replace mmcblk0p1 with mmcblk1p3 and mmcblk0p8 with mmcblk1p2.

mmcblk0p2 can stay as it is, it's the /cache partition that is only used to communicate with the recovery.

Next we need to make sure the WiFi modules that we added are loaded at boot time. Edit init.cardhu.rc and find the "on boot" line. Add below (indentation is important):

insmod /system/lib/modules/cfg80211.ko
insmod /system/lib/modules/bcmdhd.ko

Near the end of init.cardhu.rc is another reference to mmcblk0p8 that needs to be modified to mmcblk1p2 - near "service setup_fs".

Finally create the file /system/boot/preinit with the following content:

#!/system/bin/sh

# preinit: only /sys and /system are mounted (ro), / is still rw

PATH=/sbin:/system/bin:/system/xbin

# auto-detect rom2sd
if [ -d /sys/block/mmcblk1/mmcblk1p3 ]; then
echo "\nsystem/boot/preinit: mmcblk1p3 detected, setting up for ROM2SD.\n"
cp -a /system/boot/rootfs_cm/* /
fi

Make sure to make it executable:

chmod 744 /system/boot/preinit

This script is run by the kernel before the real Android init. It. detects if a microSD card with 3 partitions is inserted, and if yes, it copies the files for the CM root filesystem into the ramdisk. The following Android boot procedure will then mount /system and /data to the partitions on the microSD card and the whole operating system will run from the microSD card. If no card is inserted, nothing is modified and the normal internal ROM is started.

Flashing the ROM

Insert your microSD card into the tablet, boot to TWRP and flash your modified ZIP as usual - but disable signature checking because we didn't sign the modified ZIP.

Recovery

The recovery doesn't know about the external ROM, so you can't use the recovery to backup or restore its system or data. I prefer using the PC for that anyway.

Booting

To boot from internal storage, make sure the microSD card is not inserted when you start the tablet (you can insert it as soon as the boot animation appears). To boot from the microSD card, make sure it is inserted before you turn the tablet on.

That's all. Add more microSD cards for triple-boot, quad-boot, etc.