[Sony Tablet S] Bazoocaze:
This is a framework to help "boot" Android from the external SD card.

[size=+3]Motivation:[/size]

I started this because I would like to have Xposed Framework installed in my STS, but I do not want to take ANY risks of bootloop modifying internal system partition. This way I made this framework to allow me to "boot" a copy of Android resident in the external SD card, so that in case of bootloop, I simple eject the SD card and boot from internal Android.

[size=+3]News:[/size]

{new} - 2014/07/29 - New Sys2sdManager V2, supporting ROM ramdisks (custom ROMs), and some bugfixes. Please install, "unhook" and then "hook" again the sys2sd framework for the changes to take effect. There is a new recovery too, so choose the menu option to install the recovery package.

{new} - 2014/07/29 - First CM9 ROM for the STS (alpha stage). Please read the #2 topic for details.

{new} - 2014/07/28 - I am working on a port of CM9 for the Sony Tablet S using the sys2sd framework.

[size=+3]How it works[/size]

First, you must partition your external SD card, and then clone system and data from internal to external sdcard.

Next, during the normal boot process, the framework intercepts the process, test for the existence of the previously prepared external SD card, and if found it pauses the internal boot process, mounts /data and /system partition from the SD card, and then resumes the boot process.

[size=+3]Features[/size]

- Boot Android from external SD card (mount SYSTEM and DATA from external SD card).

- Functional recovery framework, using adapted TWRP from Motorola Xoom tablet.

- The recovery package can reside in internal or external storage.

- Recovery wait time with LED notification and triggering via hardware keypress.

- Can boot other versions of Android compatible with the stock STS ramdisk (custom ROMs).

- (work in progress): can boot other versions of Android with alternative ramdisk.

[size=+3]Bootloop Safety[/size]

- Only hook into 1 internal system script: /system/etc/install-recovery.sh (or install-recovery2.sh if present)

- With no external SD card present, the internal boot process takes precedence unmodified.

- /data and /system residing in external SD card, so if one mess the external /data ou /system directory, the bootloop will be limited to booting from the external sdcard.

- Working recovery: you can apply zip or backup and restore (tested!) your external SD card data and system partion. All modifications in data and system will be limited to the external SD card.

[size=+3]Limitations[/size]

- All modifications must work with the stock STS kernel. No custom kernels until kexec or unlocked bootloader.

- Write speed of the SD card.

[size=+3]Requisites[/size]

- Rooted Android 4.0.3 Sony Tablet S.

- busybox installed in /system/xbin, containing the functions: mount, tar, gzip, awk, sed. I recommend Stericson Busybox Installer on the Play Store. {new} If you do not have buysybox, the installer will install one for you.

- External SD card of size 8Gb or more, SD or Microsd. See the Drawbacks section for speed class information.

- Partitioning software to partition the external SD card. I recommend Mini Tool Partition Wizard for Windows, or GParted for Linux.

[size=+3]Drawbacks[/size]

[size=+2]Speed[/size]

Because the STS will be running Android from the external SD card (system and data), this framework heavly depends on the SD card read and write speed for disk IO.

I have tested the framework with the following SD card classes:

App loading, closing, and file IO:

Microsd class 4: damn slow browsing

Microsd class 6: slow

Microsd class 10: fast, like internal storage

Gaming:

Microsd class 4: slow loading times, gaming normal

Microsd class 6: slow loading times, gaming normal

Microsd class 10: normal

Boot process:

+20 to 40 seconds delay

[size=+3]How it works - Technical details[/size]

[size=+1]The framework executes the following steps during the boot from sd process[/size]

- Intercepts the internal Android boot process via the /system/etc/install_recovery script, then looks for the special partitioned external sdcard, and if not found resumes the normal Android boot process. Otherwise, keep executing.

- Stops the normal Android boot process, stopping all init services.

- Try to soft boot into recovery (explained bellow) if got user keypress. If the recovery process was not started, the framework resumes execution.

- Umount /data and /system from the internal flash storage.

- Mount /data and /system from the external SD card partitions.

- Restart all services and resume boot

[size=+1]The framework executes the following steps during the recovery start process[/size]

- Searches for a recovery package (recovery.tgz), in the external and internal storage system partition. If not found, cancels the recovery start process.

- If recovery package found, blinks the notification LED (blue color) and waits for user keypress to enter recovery. The recovery can also be triggered by a special recovery file present in the /cache/recovey directory (boot, command or extendedcommand files).

- If the user press some key in the wait interval or any special file are found then the recovery process continues. Otherwise, cancels the process.

- Stop all init services

- Decompress the recovery package, like a recovery ramdisk

- Umount all file systems, including internal and external storage, DM and Vold volumes.

- Soft boot the recovery Ramdisk using CHROOT busybox command

- Note: if you want to build your own alternative recovery package, special care must be taken for the /system and /data partitions in the /etc/recovery.fstab recovery file.

[size=+1]External SD card partitioning[/size]

- I recommend that the partitions in the external SD card be aligned to 4MB boundaries (8192 blocks).

- The internal /data and /system can be mirrored manualy using the following commands:

#### mount external /system in /mnt/newsys
#### mount external /data in /mnt/newdat
busybox mount -o remount,rw /
busybox mkdir -p /mnt/newsys
busybox mkdir -p /mnt/newdat
busybox mount /dev/block/mmcblk1p2 /mnt/newsys
busybox mount /dev/block/mmcblk1p3 /mnt/newdat
#### copy files
cd /system ; busybox cp -a * /mnt/newsys
cd /data ; busybox cp -a * /mnt/newdat
busybox umount /mnt/newsys
busybox umount /mnt/newdat

[size=+3]Getting started[/size]

1) Get an external SD Card and partition/format it

2) Install sys2sd into STS

3) Clone internal data and system to external SD card

4) Boot STS with external SD card inserted

5) Identify the internal and external system (important)

6) Install recovery in external SD card

[size=+1]1) Get an external SD Card and partition/format it[/size]

You must parition your external SD card before using this framework. I recommend you to use "Mini Tool Partition Wizard" for Windows, or "GParted" for Linux. I like to use fdisk for Linux, too.

I recommend that the partitions in the external SD card be aligned to 4MB boundaries (8192 blocks) for maximal write speed.

All partitions must be primary partitions. You must create 3 partitions:

- 1: Type fat32/vfat. This will be your "external sdcard" by the point of view of the Android or Recovery. The "internal sdcard" will stay the same, at the internal flash storage.

- 2: Type ext4 (without journal if you have the option). This will be your "/system" partition (system apps and Android core). For your information, the internal system for 4.0.3 Sony firmware takes about 300Mb, so this must be somewhat bigger, like 400Mb or more. I use 1Gb, in preparation for custom ROMs.

- 3: Type ext4 (without journal if possible). This will be your "/data" partition (user apps and data). Mine is 4Gb larger.

Do not forget to format the partitions after partitioning. Do not forget to save modifications in the Partitioning software (press the apply button).

Performance tips:

- If your Partitioning software has the option, use partitions starting/aligned in 4Mb boundaries (multiple of 8192 blocks), for maximal write speeds. In the Mini Tool Wizard, use MB alignment.

Disk /dev/block/mmcblk1: 15.9 GB, 15931539456 bytes
Device Boot Start End Blocks Id System
/dev/block/mmcblk1p1 8192 2105344 1048576+ 83 Linux
/dev/block/mmcblk1p2 2113536 10510336 4198400+ 83 Linux
/dev/block/mmcblk1p3 10518528 12615680 1048576+ 83 Linux

- Avoid to use ext2, because it was so damn slow in my tests.

- If your Partitioning software has the option, disable ext4 journaling, because it makes the external SD card wears fast.

- If possible, mark the ext4 partitions with stripe-write=1024 blocks and stride=256 blocks.

In linux, you can use:

mkfs.ext4 -E stride=256,stripe-width=1024 -O ^has_journal /dev/mmcblk0p2

[size=+1]2) Install sys2sd into STS[/size]

Get the Sys2sd Manager, decompress it in a folder, put the partitioned SD Card in the tablet, and then run run_windows.bat (run_linux.sh is work in progress).

In the menu, choose:

- Install / Install Sys2sd and busybox

- Install / Unhook sys2sd (if previusly hooked)

- Install / Hook sys2sd into System

[size=+1]3) Clone internal data and system to external SD card[/size]

With the partioned SD Card inserted into the Tablet, enter the Sys2sd Manager, and choose:

- Clone / Clone System and Data

[size=+1]4) Boot STS with external SD card inserted[/size]

In the Sys2sd Manager, choose:

- Advanced / Reboot device

[size=+1]5) Identify the internal and external system[/size]

- If you successfuly cloned the internal Android to external SD card, it will be hard to guess if you are running the internal or external Android, because it will apear the same.

- The best way to avoid this is to change something (wallpaper, icons disposition, etc) to help identify internal and external SD card boot

- Boot into internal Android and take note of the changes (icons, wallpaper)

- Boot into external Android and compare the changes

- Take care to uniquely identify booth systems, to help prevent unwanted changes to the internal system

[size=+1]6) Install recovery in external SD card[/size]

Boot into the external Android, and in the Sys2sd Manager, choose:

- Recovery / Install Recovery

[size=+3]FAQ - Frequently Asked Questions[/size]

(Q) What is this?

(A) This is a framework to help soft boot Android from the external SD card on the Sony Tablet S (STS)?

(Q) What is soft boot?

(A) It means that it is a hook in the booting process of the internal Android, using the same Kernel e RAMDRIVE. It is not a "boot from the SD card" like supported on some devices.

(Q) How to unninstall?

(A) Remove /system/xbin/sys2sd file.

(Q) Can I boot a custom Kernel?

(A) No, until we have kexec, unlocked bootloader, or other way of executing/flashing a custom kernel.

(Q) Can I boot a custom ROM?

(A) Yes, but the ROM must be made compatible to the STS hardware, and use the stock Kernel. Simply flash the ROM into the external SD card system partition using recovery.

(Q) How secure is the Recovery module?

(A) Totaly secure. It is bounded to the external data and system partitions presents in the external SD card, so it is impossible to make changes to the internal data and system partitions. The cache, primary SD card and secondary SD card partitions will be shared between the Android versions.

(Q) How about the "Android SD card"?

(A) The "Android SD card" (do not confuse this with the internal or external storage), also know as /sdcard directory, will be the same for the internal and SD card Android versions. You can keep your books, music, videos and other data here, like you do now. Also you can place your Recovery backups here.

(Q) How about the "Android second SD card"?

(A) The "Android second SD card" will be stored on the first partition of the external SD card, and it will be visible to booth internal and SD card Android versions, depending of the Apps support for a secondary SD card. You can place your Recovery backups here also.

(Q) On Android, will apps transfered to SD card work?

(A) Probably not, because you will have two Android versions running on the same device using a shared "Android SD card". Keep the apps installed on the data partition of each Android version.

(Q) How about the Sony extra partitions?

(A) All the /configs, /dataapp, /vendor and other Sony partitions are necessary to boot the Internal stock Android. DO NOT wipe, format, clean, exclude none of the internal partitions, on the risk of a bootloop and device brick.

(Q) Can I copy the contents of the data and system in the external SD card back to the internal storage?

(A) No. It is too risk.

(Q) The Android running from the SD card is too slow.

(A) Take a faster, or class 10 SD card. Mine is running fine.

(Q) Your recovery sucks. Can I create an alternative recovery?

(A) Take my Recovery as a template.

(Q) Can I start recovery from the command line?

(A)

sys2sd recoveryctl start /path/to/recovery.tgz

(Q) Can I make a dual recovery?

(A) Yes.

File: /system/recovery/start_recovery
-----
#!/system/bin/sh

# $1 can be: vol_down, vol_up, power, internal

if [ "$1" = "vol_down" ] ; then
/system/xbin/sys2sd recoveryctl start /system/recovery/twrp.tgz
exit $?
fi

if [ "$1" = "vol_up" ] ; then
/system/xbin/sys2sd recoveryctl start /system/recovery/cwm.tgz
exit $?
fi

/system/xbin/sys2sd recoveryctl start /system/recovery/default.tgz
exit $?

(Q) How to enter Recovery?

(A) See the next question.

(Q) What is the blinking blue LED during boot?

(A) It is the notification to enter Recovery. During the blue LED blinking, press a key (volume or power) to enter Recovery - after this, the LED will pulse green to indicate it will enter Recovery, or pulse red to indicate it will NOT enter Recovery.

(Q) The clone command fails with a message of "target device not found"?

(A) Is the SD Card inserted into the tablet, partitioned and formated? Are the partitions primary partitions? Have you pressed the apply button on the partitioning software?

[size=+3]TODO[/size]

- run_linux.sh in the Sys2sd Manager

- Guide on how to make custom recovery module

- Guide on how to make custom ROM ramdisk and entry points

- (done) Guide on how to make a dual recovery