Android 4.2.2 Jelly Bean – How to run games from external sdcard

My 16GB Nexus 7 runs out of space again. Previously, we have many scripts to help us overcome this limitation which use the built-in mount -o bind command. It’s nice (especially for games) to be able to move the data to external micro sdcard and later bind it to the original directory as needed. But since Android version 4.2.2, none of the directory bind scripts from previous version seems to work due to the added multiuser feature and adb security. Fortunately after some time searching the net, I’ve found the right script for the job.

First, the requirement:

1. root
2. Busybox – installed in /system/xbin
3. Stickmount
4. $cripter

Create new directory in internal storage as our script placeholder. Open $cripter –> menu –> settings and enter path to the new directory just created. Still in $cripter, select New Script and enter a name for your script. In the new windows, select Run as root? and copy the lines below:

#!/system/bin/sh

adb_status=`getprop init.svc.adbd`
adb_port=`getprop service.adb.tcp.port`

if [ -z "$adb_port" ]; then
 adb_port=-1
fi

adb_use_port=$adb_port
adb_connected=0
adb_sysroot=`getprop persist.sys.root_access`

if [ -z "$adb_sysroot" ]; then
 $adb_sysroot=''
fi

adb_use_root=$adb_sysroot
adb_rsa_keyed=0
adb_key_at_connect=0

trap "adb_reset" EXIT

adb_send_cmd() {
 adb_start_flex
 adb -s localhost:"$adb_use_port" shell su -c "$*"
}

adb_start_flex() {
 local adb_restart=0
 if [ "$adb_use_root" != "3" ]; then
 setprop persist.sys.root_access "3"
 adb_use_root=3
 fi

if ! [ "$adb_use_port" -gt 0 ]; then
 adb_use_port=5556
 setprop service.adb.tcp.port "$adb_use_port"
 adb_restart=1
 fi

if [ "$adb_connected" -eq 0 ]; then
 if ! [ -f "$ANDROID_DATA/.android/adbkey.pub" ]; then
 adb kill-server
 HOME="$ANDROID_DATA" adb start-server
 fi

grep -Fxq "$(cat $ANDROID_DATA/.android/adbkey.pub)" "$ANDROID_DATA/misc/adb/adb_keys"

if [ "$?" -ne 0 ]; then
 cat $ANDROID_DATA/.android/adbkey.pub >> $ANDROID_DATA/misc/adb/adb_keys
 adb_rsa_keyed=1
 adb_restart=1
 fi

if [ "$adb_restart" -eq 1 ]; then
 adb kill-server
 stop adbd
 start adbd
 sleep 5
 fi

HOME="$ANDROID_DATA" adb connect localhost:$adb_use_port
 adb_connected=1

 fi
}

adb_reset() {
 local adb_restart=0

 if [ "$adb_connected" -ne 0 ]; then
 adb disconnect localhost:$adb_use_port
 adb_connected=0

if [ "$adb_rsa_keyed" -ne 0 ]; then
 sed -i "\|$(cat $ANDROID_DATA/.android/adbkey.pub)|d" $ANDROID_DATA/misc/adb/adb_keys
 adb_restart=1
 fi

if [ "$adb_port" -le 0 ]; then
 setprop service.adb.tcp.port "$adb_port"
 adb_restart=1
 fi

if [ "$adb_restart" -eq 1 ]; then
 stop adbd
 start adbd
 fi
 fi

if [ "$adb_use_root" -ne "$adb_sys_root" ]; then
 setprop persist.sys.root_access "$adb_sys_root"
 fi

if [ "$adb_status" == "stopped" ]; then
 adb kill-server
 stop adbd
 fi
}

adb_send_cmd "/system/xbin/busybox mount -o bind /data/media/0/usbStorage/sda1/MC4/obb /data/media/obb/com.gameloft.android.ANMP.GloftM4HM"

adb_send_cmd "/system/xbin/busybox mount -o bind /data/media/0/usbStorage/sda1/MC4/data /data/media/0/Android/data/com.gameloft.android.ANMP.GloftM4HM/files"

exit

Save and exit from $cripter. As we can see, the above script is for binding data and obb directory for Modern Combat 4: Zero Hour. For other games or apps, just replace the name and path accordingly. ONLY modify the line that start with adb_send_cmd to suit whatever you’re mounting, leave the rest alone.

Follow the steps below to run Modern Combat 4 from external micro sd card:

1. Insert your usb OTG cable into usb port
2. Stickmount will mount the sdcard to usbStorage/sda1
3. Create new directory MC4. Inside this directory create 2 new directory data and obb.
4. Copy all content in Android/obb/com.gameloft.android.ANMP.GloftM4HM to usbStorage/sda1/MC4/obb
5. Copy all content in Android/data/com.gameloft.android.ANMP.GloftM4HM/files to usbStorage/sda1/MC4/data
6. Delete the original data and obb file
7. Open $cripter and run the script

Caveat:
1. If $cripter output says something about device offline, add more delay to adbd before attempting to connect to it. To do this, increase the sleep value at line 60 from 5 to a higher value (in seconds).

2. If your’re running a custom rom on your device, it might have a different directory structure than the stock rom. Some will find that their /data/media directory is empty or the entire /data itself is empty or worst no /data directory at all.  The simplest way to find the correct path is by executing mount command in terminal after you’ve mounted your external drive via OTG cable. Look at the path used by your external drive and use the same path for your data and obb directory.

Done.

About these ads

3 comments

    1. I’ve tried but it didn’t work for my N7. Don’t know why. I think maybe it got something to do with debuggerd file which I replace during the last update or maybe because I’m using non-stock kernel.

  1. yoborider · · Reply

    Hi, Adam!

    Good work ! thk u very much!

    Few modification to make it works for me :

    +Replace == with = in line 96 :
    if [ “$adb_status” == “stopped” ]; then
    become
    if [ “$adb_status” = “stopped” ]; then

    +remove empty lines 2 and 5

    +convert script sh file in UNIX/Ansi editing it with notepadd++ (Edit>EOL conversion>Unix)

    Yobo

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: