• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Mods [script] Move Game/App data to external SD (Bind) [Root only]

SUroot

Extreme Android User
May 25, 2010
23,907
5,306
Riddlesden, West Yorkshire, UK
This is very much a work in progress so would appreciate some input on this please.

For those who have an internal and external sdcard, its a shame that large games download their data to /sdcard/Android/data which is actually the internal SD on devices with both. This is no good as we may have really big microsd cards, but not so much internal SD space and games can be 1 - 1.5 GB in size.

There is an app called Directory Bind on XDA for this, but it doesn't work on 4.2.1 so I am hoping this will work instead. It isn't very elegant though, so would appreciate any input that could make it cleaner.

Code:
#!/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

Main_Menu='Please enter your choice: '
echo "

Main Menu

"
optionsa=("Set Defaults                          "
"Bind using existing defaults          "
"Quit")
select opta in "${optionsa[@]}"
do
    case $opta in
        "Set Defaults                          ")
	echo "

Set Defaults Menu


"
Defaults_Menu='Please enter your choice: '
optionsb=("Select the ExternalSD Mount point" 
"Set Default ExternalSD location (The new location)" 
"Select the InternalSD Mount point" 
"Return to Main menu")
select optb in "${optionsb[@]}"
do
    case $optb in
        "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 "

Set Defaults Menu

1) Select the ExternalSD Mount point
2) Set Default ExternalSD location (The new location)
3) Select the InternalSD Mount point
4) Return to Main menu

"
            ;;
        "Set Default ExternalSD location (The new location)")
	echo "

Set Default ExternalSD location (The new location)

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

echo -e "

Set Defaults Menu


1) Select the ExternalSD Mount point
2) Set Default ExternalSD location (The new location)
3) Select the InternalSD Mount point
4) Return to Main menu

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

Select the InternalSD Mount point

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

echo -e "

Set Defaults Menu

1) Select the ExternalSD Mount point
2) Set Default ExternalSD location (The new location)
3) Select the InternalSD Mount point
4) Return to Main menu

"
            ;;
        "Return to Main menu")
echo -e "1)  Set Defaults 
2)  Bind using existing defaults 
3)  Quit"
break
            ;;
        *) echo invalid option;;
    esac
done
            ;;
        "Bind using existing defaults          ")
	echo "

Bind using existing defaults

"
extdirfile=$def/extdir
extfile=$def/ext
intfile=$def/int
ext=$(<"$extfile")
extdir=$(<"$extdirfile")
int=$(<"$intfile")


# Select the App location to move
printf "

Select the directory to move data FROM: 

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


# Select the location to move to
echo -n "

Create a name for the new directory to move data TO (HINT - Use something descriptive): 

"
read AppN

echo -e "

Main Menu

1) Set Defaults                          
2) Bind using existing defaults          
3) Quit

"

# Create the new location
mkdir $extdir/$AppN

# Move the data to the new location
mv $AppO/* $extdir/$AppN/ 2>/dev/null

# Write this data to the bind script.
echo 'mount -o bind '$extdir'/'$AppN' '$AppO'' >> $DIR/bind.sh
sh $DIR/bind.sh
echo -e "

Now use script manager to set bind.sh to run as root on boot

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

Yes I know I can use loops etc, but I'm a bash novice so I haven't looked at that yet :)

So this is "mounter.sh" which can be run via Script manager with the root option

It assumes you want to move stuff FROM /sdcard/Android/data

It gives menu options so you can set the default location of /sdcard, /extSdCard and a default directory to bind all your stuff in (eg /extSdCard/bind).

You can name the new location through the process too. It moves the stuff then mounts it at the end of the process. It also echos that using >> to bind.sh which you have to set in script manager to run as root and at boot.

Instructions

  • Download the script and put it in a (non symlinked, non bound) directory on internal sdcard. Remove .txt from the filename
  • Install Script manager
  • Browse to your script, press it and press the "SU" button (to run it as root)
  • Press "Run"
  • Go through the menu to "Set Defaults" and set your default locations (may need to turn into landscape mode here)
  • Then go through the Bind menu and set up your binds.
  • Set the bind.sh as root and boot
 

Attachments

  • mounter.sh.txt
    3.3 KB · Views: 297
  • Like
Reactions: Lateralus138
OK so my latest is that I can mount using my script with some modifications. To mount across all applications, we need something with even more elevated permissions than su. People are using the debugger daemon, which is ugly but it works. That;s what StickMount uses too.

So you can simply use the mount commands, but they must be in /system/bin/debuggerd and the process must be started (at boot) or after a new mount is created, for the mounts to be visible.

The problem is, debuggerd is unstable if left as the mount commands. The phone seriously freezes, goes black and goes all kind of crazy, so you have to stop the daemon and put it back as it was. You need to do all this every time.

I've pretty much got it scripted here....

It's still Work in progress, so not everything that must be done, is scripted yet. There are some manual steps...

As already mentioned, you need script manager.

Instructions:

  • rename your existing /system/bin/debuggerd to debuggerd.bak (exactly this)
  • from the zip attached to this post, put debuggered.mnt in /system/bin
  • put the mounter.sh and remount.sh in a directory on your internal SD card somewhere
  • browse to this directory in script manager and set mounter.sh as "SU" then run it.
  • Go through the menu (in landscape preferably) and set the defaults (internal lists /data/media - for me in here, I select 0)
  • Then set up a bind through the menu

The script *should" now run the remount (which takes 14 seconds) but I haven't tested this yet. It can be run manually via Script manager too. Just set it as "SU" but also you want it set at boot.

***NOTE, remember, my script assumes you want to bind FROM /sdcard/Android/data/com.appname You can just manually bind using "mount -o bind /mnt/extSdCard/whereveryouwant /data/media/0/whereverelseyouwant and put it in the debuggerd.mnt then just use the remount.sh to do the necessary starting, stopping and debuggerd binary file management.
 

Attachments

  • mounts.zip
    1.4 KB · Views: 136
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones