[Sony Tablet S][CM9] Sys2sd - Start Android from the SD Card

Bazoocaze

Senior Member
Aug 13, 2011
371
857
0
Porto Alegre
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:
Code:
#### 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.
Code:
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:
Code:
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)
Code:
sys2sd recoveryctl start /path/to/recovery.tgz
(Q) Can I make a dual recovery?
(A) Yes.
Code:
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
 

Attachments

Last edited:

Bazoocaze

Senior Member
Aug 13, 2011
371
857
0
Porto Alegre
[size=+3]Introduction[/size]
This is an Unofficial CyanogenMod 9.0 port for the Sony Tablet S.


[size=+3]Working[/size]
- Display (hw accelerated)
- Touch screen
- Lock screen
- Power button
- Adjustable display brightness
- Settings App (some parts are not working)
- ADB


[size=+3]Not working[/size]
- Front camera
- Rear camera
- Volume buttons
- Audio
- GPS
- Sensors
- Wifi
- Internal SD Card
- External SD Card
- USB mtp / storage
- USB host


[size=+3]How to install[/size]
1) Install the latest sys2sd framework and get it working on an SD Card
2) Install the recovery on sys2sd
3) Download the latest flashable zip on this thread and put it on the Internal or External SD Card on the Sony Tablet S
4) Reboot into recovery (sys2sd Recovery, NOT Stock recovery)
5) {optional} Make a backup of system and data
6) Flash the downloaded zip
7) Wipe data
8) Reboot system

Please note that the changes will be limited to the Android present on the external SD Card. No changes will be made to the internal Android. Reboot and eject the SD Card to boot into internal Android.


[size=+3]Downloads[/size]

This is the flashable zip for the CM9 version:

{latest} cm9-20140729T212846.zip, 144MB
http://www.mediafire.com/download/9wha2vgie4cbqro/cm9-20140729T212846.zip


[size=+3]Warnings[/size]

DO NOT flash any of this zip using the Stock Recovery, on the risk of a device brick.
Use always the sys2sd recovery (press a key during the flashing blue LED).
 
Last edited:

Bazoocaze

Senior Member
Aug 13, 2011
371
857
0
Porto Alegre
limax182 said:
Hi,

I am glad you are trying to use the framework.

1) "without journal" is only available if you format ext4 using the command line mkfs.ext4 on a Linux system. I am working on a way to format from the Sys2sdManager, so do not worry about this option for now.
2) Same problem. For now, choose to align to MB in the Mini Tool Parition Wizard and you will be ok.

Clone System:
Sorry for the incomplete instructions. The clone option expects the SD card to be inserted into the tablet sdcard slot.

ERROR: Target device /dev/block/mmcblk1p2 not found
- Is the SD Card inserted into the tablet?
- Is the SD Card really partitioned? Have you pressed the "apply" button in Mini Tool Partition Wizard?
 
  • Like
Reactions: Dillenger

Bazoocaze

Senior Member
Aug 13, 2011
371
857
0
Porto Alegre
Oh, my. I completely forgot to say that the partitions need to be primary. I will update the first post. Thank you.


About the fault in the Xposed installer, that is a know issue in the Xposed FAQ.

This post have the workaround for that:
http://forum.xda-developers.com/showpost.php?p=52292102&postcount=7


Finally installed the external Android. The problem was I made all the 3 partitions as Logical but today I made them Primary and it worked!
Now when I tried to install Xposed it gives me this message:


:confused:
Thanks for your help!
Sorry for bad english
 

smgdev

Senior Member
Jan 13, 2013
321
48
0
Ankara

CoolApps

Senior Member
May 12, 2011
3,384
609
113
muffin.cloud
Do you think it will soon be possible to put CM9 on the internal storage after getting kexec worked on with a few fixes? This is just way too awesome to handle and we're finally going somewhere.

Funny enough, this isn't in the development thread. :p
 

CoolApps

Senior Member
May 12, 2011
3,384
609
113
muffin.cloud
I've tried this framework but I seem to be getting issues.
I've got around some errors regarding mounting but it seems that the recovery can touch the /cache partition causing it to have the wrong permissions or something, I had to factory reset to get the /cache partition to be reformatted.

Anyway, after all of the things after and before, I've finally got this thing working, the only problem now is that the ROM is stuck in a bootloop or something (staying in the boot animation, I think it did dim slightly after 10-20 minutes).

I'm using an 8GB class 4 SD card.
 
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone