[Galaxy S III Android Development] danarama:
Tested with...

Fully working

-TouchWiz based 4.2.x

Experimental*

-CM 10.1 (Nighlies)

-ParanoidAndroid 3+ (Official)

-AOKP (Official)

*requires Siyah, Yank or Devil kernel

What is this?

Hi all,

This is a script that will allow you (with your 4.2.x ROM) to bind the data from any app or game from /sdcard/Android/data to extSdCard. This means, your internal memory is no longer being filled by a handful of Games (and their respective data) on the 16 GB versions of the S3. You can move game or app data from any app that uses the internal sdcard to your external sd card, to save precious space.

We can also use the script to bind folders like DCIM and Downloads.

Hasn't this been done before?

Yes and no. Back in the 4.0.4, 4.1.1 and 4.1.2 days, we could all use an app called "Directory Bind" but this no longer works in 4.2.x because Google have changed the way this works (Permissions). What happens now, is only the app that creates the bind can see it. So if you bind in "Directory Bind", only that app can see it, NOT the app that "owns" the data.

So this script works?

Yes it does. It uses what is unfortunately an "ugly" work around, by hijacking a system processes (debugger daemon) to achieve elevated permissions (Above and beyond that of su).

Does it work for everyone? Any pre-requsites or requirements?

It should work for most S3 users on 4.2 now. The latest releases have experimental support for CM, AOSPA and AOKP roms as well as full support for TouchWiz roms.

All ROMs must have busybox installed. Non-TouchWiz ROMs may need to change the kernel to Siyah 1.9.1 (CM 10.1 kernel doesn't work)

Any limitations?

Some AOSP ROMs mount the extSdCard with fmask=0702,dmask=0702 which doesn't give full access to non-root users (Apps). We can work around this - see EXPERIMENTAL

It assumes that for app data, you will have one named directory you bind everything to. For example, I have the default set as /extSdCard/bind. The script creates my new app directories within there, then binds the original over to it.

It uses script manager to run and manage the scripts.

There is not yet a way of reversing a bind through the script. It can be done manually however. Scope for future.

The option to select defaults, in the terminal display is not a single column, which makes it tricky to see. You need to go to landscape mode for a better view.

How does it work?

We have in the attached zip, 2 scripts. 1 manages the set up of your defaults and mounts. The other does the daemon hijacking. The 1st calls the second script when a new mount is added

Script manager to be used to call the primary script but also it can be used to call the secondary too. The hijack needs to occur at every boot too.

Instructions

***Take a full Nandroid backup before moving forward***

Firstly, create a folder on your internal SD card. Called it something like "mounter".

Download the "mounter.zip" file attached to this post.

Unzip the contents of the zip file and put inside the "mounter" folder you just created

Now you should have:

/sdcard/mounter/mounter.sh

/sdcard/mounter/remount.sh

/sdcard/mounter/remount_delayed.sh

/sdcard/mounter/debuggerd.mnt

Tip > never try to bind this directory

Now, download Script Manager and install it.

Open script manager and go to the /sdcard/mounter directory

Press "mounter.sh" to open up its options. Press the "Su" button (turns green)

Press the run button. You are now running the script.

So first things first, you are presented with the main menu. The first time you run the script, you MUST go into 1) Set-up Menu

In the Set-up Menu, you MUST set the following options before first time use:

1) Initial Install (Choose Either TouchWiz or AOSP, whichever is appropriate)

- This manages all your debuggerd files for you. Puts them in your /system partition, sets permissions etc.

2) Select the ExternalSD mount point

- This tells the script now (and moving forward) where you ExternalSD is.

3) Set Default ExternalSD location (The new location)

- As stated in "limitations", this script assumes you want to keep all your /sdcard/Android/data/game that you bind, in one single folder on extSdCard. This option tells the script what folder that is. This option does not create the folder for you. Personally, I have /extSdCard/bind set as my folder

4) Select the InternalSD Mount point.

- This tells the script now (and moving forward) where you InternalSD is. For me (on the S3) this is /data/media/0 (by default this option lists everything in data/media)

Once all these 4 options are set, you can go back to the main menu where you see the options to actually do the binding:

2) App Data: End-to-End Bind Wizard

- This is a menu that will take you through step-by-step, moving the data files of an app and binding it to the default externalSD folder

3) App Data: Bind only (Data Already Moved)

- Perhaps the data is already where you want it. From another app in the past that no longer works. This will simply add the missing bind

4) Move Obb data (for ALL games) to extSdCard

- This menu takes the obb directory (where all games with obb data keep their obb data) and mounts the entire directory in a folder of your creation (creates during this process)

5) Bind /sdcard/* to extSdCard/* End-to-end Wizard

- This is a menu that will take you though step-by-step taking a folder on /sdcard (Downloads for example) and creating a folder to bind to on the external sd

6) Bind /sdcard/* to extSdCard/* (Already moved)

- As above, but the data is already there.

Once selecting whichever option you want and finishing that menu, the script will tell you to set remount.sh* as "Su" and "Boot" in script manager.

That's it. Done.

Please note, if you do have problems with not being able to manually create / delete files on either sdcard, set remount_delayed.sh to run at boot instead of remount.sh - DO NOT DELETE remount.sh however, it is still required.

Tip > debuggered.mnt is backed up in /sdcard/mounter/mounter_defaults - If you have reflashed your ROM, you can simply do the "Initial Install" option again. The other set up options are not required. The mounts will remain.

How to remove?

1) In Script manager, reset remount.sh to not run at boot.

2) Run mounter.sh and run through Set-up menu > Remove All binds and restart clean

3) Reboot (important)

4) You will manually be responsible for moving your moved data back to where it needs to be.

The Scripts

mounter.sh

#!/system/bin/sh

# Set Default Script location
DIR="$(dirname "$0")"

if [ ! -d $DIR/mounter_defaults ];
then
mkdir $DIR/mounter_defaults
fi
def=$DIR/mounter_defaults

# Set vold mount for AOSP based ROMS
VOLD="$(mount | grep -E -o -m 1 ".{0,0}179:.{0,2}")"

Main_Menu='Please enter your choice: '
echo "

=======================================================
********************** Main Menu **********************
=======================================================

"
optionsa=("Set-up Menu "
"App Data: End-to-end Bind Wizard "
"App Data: Bind Only (Data already moved) "
"Move obb data (for ALL games) to /extSdCard"
"Bind /sdcard/* to /extSdCard/* End-to-end Wizard"
"Bind /sdcard/* to /extSdCard/* (already moved)"
"Quit")
select opta in "${optionsa[@]}"
do
case $opta in
"Set-up Menu ")
echo "

=======================================================
********************* Set-Up Menu *********************
=======================================================

"
Defaults_Menu='Please enter your choice: '
optionsb=("Initial Install and repair - TW"
"Initial Install and repair - AOSP"
"Select the ExternalSD Mount point"
"Set Default ExternalSD folder to bind app data"
"Select the InternalSD Mount point"
"Remove all binds and restart clean"
"Return to Main menu")
select optb in "${optionsb[@]}"
do
case $optb in
"Initial Install and repair - TW")
echo -e "

If you have not taken a FULL Nandroid of your device, reboot and do so now. You have 45 Seconds before this process starts.... Take a Nandroid NOW!!!

"
sleep 60
echo -e "

Initial install or repair starting. Please be patient whilst magic happens.... This will take several minutes.

"
mount -o remount,rw /system
chmod 777 /system/bin/debuggerd > /dev/null 2>&1
cp -fr /system/bin/debuggerd /system/bin/debuggerd.bak > /dev/null 2>&1
cp -fr /system/bin/debuggerd.bak $DIR/ > /dev/null 2>&1
cp -fr $DIR/mounter_defaults/debuggerd.mnt $DIR/debuggerd.mnt > /dev/null 2>&1
cp -fr $DIR/debuggerd.mnt /system/bin/ > /dev/null 2>&1
cp -fr $DIR/debuggerd.bak /system/bin/ > /dev/null 2>&1
chmod 777 /system/bin/debuggerd.mnt > /dev/null 2>&1
chmod 777 /system/bin/debuggerd.bak > /dev/null 2>&1
sh $DIR/remount.sh

echo -e "

Initial install or repair.....complete

>

=======================================================
********************* Set-Up Menu *********************
=======================================================

1) Initial Install and repair (TouchWiz)
2) Initial Install and repair (AOSP)
3) Select the ExternalSD Mount point
4) Set Default ExternalSD folder to bind app data
5) Select the InternalSD Mount point
6) Remove all binds and restart clean
7) Return to Main menu

"
;;
"Initial Install and repair - AOSP")
echo -e "

If you have not taken a FULL Nandroid of your device, reboot and do so now. You have 45 Seconds before this process starts.... Take a Nandroid NOW!!!

"
sleep 60
echo -e "

Initial install or repair starting. Please be patient whilst magic happens.... This will take several minutes.

"
echo 'umount /storage/sdcard1
mount -t vfat -o rw,uid=1023,gid=1023,dmask=0002,fmask=0002 /dev/block/vold/'$VOLD '/storage/sdcard1' >> $DIR/debuggerd.mnt
mount -o remount,rw /system
cp -fr /system/etc/permissions/platform.xml $DIR/mounter_defaults/platform.xml > /dev/null 2>&1
cp -fr $DIR/platform.xml /system/etc/permissions/platform.xml > /dev/null 2>&1
chmod 777 /system/etc/permissions/platform.xml > /dev/null 2>&1
chmod 777 /system/bin/debuggerd > /dev/null 2>&1
cp -fr /system/bin/debuggerd /system/bin/debuggerd.bak > /dev/null 2>&1
cp -fr /system/bin/debuggerd.bak $DIR/ > /dev/null 2>&1
cp -fr $DIR/mounter_defaults/debuggerd.mnt $DIR/debuggerd.mnt > /dev/null 2>&1
cp -fr $DIR/debuggerd.mnt /system/bin/ > /dev/null 2>&1
cp -fr $DIR/debuggerd.bak /system/bin/ > /dev/null 2>&1
chmod 777 /system/bin/debuggerd.mnt > /dev/null 2>&1
chmod 777 /system/bin/debuggerd.bak > /dev/null 2>&1

echo -e "

Initial install or repair.....complete

>

Please now reboot your device

=======================================================
********************* Set-Up Menu *********************
=======================================================

1) Initial Install and repair (TouchWiz)
2) Initial Install and repair (AOSP)
3) Select the ExternalSD Mount point
4) Set Default ExternalSD folder to bind app data
5) Select the InternalSD Mount point
6) Remove all binds and restart clean
7) Return to Main menu

"
;;
"Select the ExternalSD Mount point")
echo "

Select the ExternalSD Mount point

"
select extl in /mnt/*; do test -n "$extl" && break; echo ">>> Invalid Selection, please select a number"; done
echo $extl > $def/ext

echo -e "

ExternalSD Mount point.....set

=======================================================
********************* Set-Up Menu *********************
=======================================================

1) Initial Install and repair (TouchWiz)
2) Initial Install and repair (AOSP)
3) Select the ExternalSD Mount point
4) Set Default ExternalSD folder to bind app data
5) Select the InternalSD Mount point
6) Remove all binds and restart clean
7) Return to Main menu

"
;;
"Set Default ExternalSD folder to bind app data")
echo "

Set Default ExternalSD folder to bind app data

"
select extldir in $extl/*; do test -n "$extldir" && break; echo ">>> Invalid Selection, please select a number"; done
echo $extldir > $def/extdir

echo -e "

ExternalSD default bind directory.....set

=======================================================
********************* Set-Up Menu *********************
=======================================================

1) Initial Install and repair (TouchWiz)
2) Initial Install and repair (AOSP)
3) Select the ExternalSD Mount point
4) Set Default ExternalSD folder to bind app data
5) Select the InternalSD Mount point
6) Remove all binds and restart clean
7) Return to Main menu

"
;;
"Select the InternalSD Mount point")
echo "

Select the InternalSD Mount point

"
select intl in /data/media/*; do test -n "$intl" && break; echo ">>> Invalid Selection, please select a number"; done
echo $intl > $def/int

echo -e "

InternalSD mount.....set

=======================================================
********************* Set-Up Menu *********************
=======================================================

1) Initial Install and repair (TouchWiz)
2) Initial Install and repair (AOSP)
3) Select the ExternalSD Mount point
4) Set Default ExternalSD folder to bind app data
5) Select the InternalSD Mount point
6) Remove all binds and restart clean
7) Return to Main menu

"
;;
"Remove all binds and restart clean")
echo "

Data will NOT be moved back to it's original location. Only the binds will be removed.

"
echo ' ' > /system/bin/debuggerd.mnt

echo -e "

debuggerd.mnt.....cleaned

>

>

=======================================================
********************* Set-Up Menu *********************
=======================================================

1) Initial Install and repair (TouchWiz)
2) Initial Install and repair (AOSP)
3) Select the ExternalSD Mount point
4) Set Default ExternalSD folder to bind app data
5) Select the InternalSD Mount point
6) Remove all binds and restart clean
7) Return to Main menu

"
;;
"Return to Main menu")
echo -e "

=======================================================
********************** Main Menu **********************
=======================================================

1) Set Defaults
2) App Data: End-to-end Bind Wizard
3) App Data: Bind Only (Data already moved)
4) Move obb data (for ALL games) to /extSdCard
5) Bind /sdcard/* to /extSdCard/* End-to-end Wizard
6) Bind /sdcard/* to /extSdCard/* (already moved)
7) Quit"
break
;;
*) echo invalid option;;
esac
done
;;
"App Data: End-to-end Bind Wizard ")
echo "

App Data: End-to-end Bind Wizard

"
extdirfile=$def/extdir
extfile=$def/ext
intfile=$def/int
ext=$( /dev/null 2>&1
rm -rf $AppO/*

# Write this data to the bind script.
mount -o remount,rw /system
echo 'mount -o bind '$extdir'/'$AppN' '$AppO'' >> /system/bin/debuggerd.mnt
cp -fr /system/bin/debuggerd.mnt $DIR/mounter_defaults > /dev/null 2>&1
sh $DIR/remount.sh
echo -e "

Operation completed sucessfully!!!!

If you have not done so already, please now use script manager to set remount or remount_delayed to run as root on boot

=======================================================
********************** Main Menu **********************
=======================================================

1) Set Defaults
2) App Data: End-to-end Bind Wizard
3) App Data: Bind Only (Data already moved)
4) Move obb data (for ALL games) to /extSdCard
5) Bind /sdcard/* to /extSdCard/* End-to-end Wizard
6) Bind /sdcard/* to /extSdCard/* (already moved)
7) Quit

"
;;
"App Data: Bind Only (Data already moved) ")
echo "

App Data: Bind Only (Data already moved)

"
extdirfile=$def/extdir
extfile=$def/ext
intfile=$def/int
ext=$(> /system/bin/debuggerd.mnt
cp -fr /system/bin/debuggerd.mnt $DIR/mounter_defaults > /dev/null 2>&1
sh $DIR/remount.sh
echo -e "

Operation completed sucessfully!!!!

If you have not done so already, please now use script manager to set remount or remount_delayed to run as root on boot

=======================================================
********************** Main Menu **********************
=======================================================

1) Set Defaults
2) App Data: End-to-end Bind Wizard
3) App Data: Bind Only (Data already moved)
4) Move obb data (for ALL games) to /extSdCard
5) Bind /sdcard/* to /extSdCard/* End-to-end Wizard
6) Bind /sdcard/* to /extSdCard/* (already moved)
7) Quit

"
;;
"Move obb data (for ALL games) to /extSdCard")
echo "

Move obb data (for ALL games) to /extSdCard

... This may take several minutes, please be patient....

"
extdirfile=$def/extdir
extfile=$def/ext
intfile=$def/int
ext=$( /dev/null 2>&1
rm -rf /data/media/obb/*

echo "

obb data moved successfully!

...binding...

"

# Write this data to the bind script.
mount -o remount,rw /system
echo 'mount -o bind '$extdir'/obb /data/media/obb' >> /system/bin/debuggerd.mnt
cp -fr /system/bin/debuggerd.mnt $DIR/mounter_defaults > /dev/null 2>&1
sh $DIR/remount.sh
echo -e "

Operation completed sucessfully!!!!

If you have not done so already, please now use script manager to set remount or remount_delayed to run as root on boott

=======================================================
********************** Main Menu **********************
=======================================================

1) Set Defaults
2) App Data: End-to-end Bind Wizard
3) App Data: Bind Only (Data already moved)
4) Move obb data (for ALL games) to /extSdCard
5) Bind /sdcard/* to /extSdCard/* End-to-end Wizard
6) Bind /sdcard/* to /extSdCard/* (already moved)
7) Quit

"
;;
"Bind /sdcard/* to /extSdCard/* End-to-end Wizard")
echo "

Bind /sdcard/* to /extSdCard/* End-to-end Wizard

"
extfile=$def/ext
intfile=$def/int
ext=$( /dev/null 2>&1
rm -rf $DirO/*

# Write this data to the bind script.
mount -o remount,rw /system
echo 'mount -o bind '$ext'/'$DirN' '$DirO'' >> /system/bin/debuggerd.mnt
cp -fr /system/bin/debuggerd.mnt $DIR/mounter_defaults > /dev/null 2>&1
sh $DIR/remount.sh
echo -e "

Operation completed sucessfully!!!!

If you have not done so already, please now use script manager to set remount or remount_delayed to run as root on boot

=======================================================
********************** Main Menu **********************
=======================================================

1) Set Defaults
2) App Data: End-to-end Bind Wizard
3) App Data: Bind Only (Data already moved)
4) Move obb data (for ALL games) to /extSdCard
5) Bind /sdcard/* to /extSdCard/* End-to-end Wizard
6) Bind /sdcard/* to /extSdCard/* (already moved)
7) Quit

"
;;
"Bind /sdcard/* to /extSdCard/* (already moved)")
echo "

Bind /sdcard/* to /extSdCard/* (already moved)

"
extfile=$def/ext
intfile=$def/int
ext=$(> /system/bin/debuggerd.mnt
cp -fr /system/bin/debuggerd.mnt $DIR/mounter_defaults > /dev/null 2>&1
sh $DIR/remount.sh
echo -e "

Operation completed sucessfully!!!!

If you have not done so already, please now use script manager to set remount or remount_delayed to run as root on boot

=======================================================
********************** Main Menu **********************
=======================================================

1) Set Defaults
2) App Data: End-to-end Bind Wizard
3) App Data: Bind Only (Data already moved)
4) Move obb data (for ALL games) to /extSdCard
5) Bind /sdcard/* to /extSdCard/* End-to-end Wizard
6) Bind /sdcard/* to /extSdCard/* (already moved)
7) Quit

"
;;
"Quit")
break
;;
*) echo invalid option;;
esac
done

remount.sh

#!/system/bin/sh

mount -o remount,rw /system
stop debuggerd
sleep 2
rm /system/bin/debuggerd
sleep 2
cp /system/bin/debuggerd.mnt /system/bin/debuggerd
chmod 777 /system/bin/debuggerd
sleep 5
start debuggerd
sleep 2
stop debuggerd
sleep 2
rm /system/bin/debuggerd
sleep 2
cp /system/bin/debuggerd.bak /system/bin/debuggerd
sleep 2
start debuggerd