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


  1. SUroot

    SUroot Well-Known Member Developer

    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 (Text):
    1. #!/system/bin/sh
    2.  
    3. # Set Default Script location
    4. DIR="$(dirname "$0")"
    5.  
    6. if [ ! -d $DIR/mounter_defaults ];
    7. then
    8.     mkdir $DIR/mounter_defaults
    9. fi
    10. def=$DIR/mounter_defaults
    11.  
    12. Main_Menu='Please enter your choice: '
    13. echo "
    14.  
    15. Main Menu
    16.  
    17. "
    18. optionsa=("Set Defaults                          "
    19. "Bind using existing defaults          "
    20. "Quit")
    21. select opta in "${optionsa[@]}"
    22. do
    23.     case $opta in
    24.         "Set Defaults                          ")
    25.     echo "
    26.  
    27. Set Defaults Menu
    28.  
    29.  
    30. "
    31. Defaults_Menu='Please enter your choice: '
    32. optionsb=("Select the ExternalSD Mount point"
    33. "Set Default ExternalSD location (The new location)"
    34. "Select the InternalSD Mount point"
    35. "Return to Main menu")
    36. select optb in "${optionsb[@]}"
    37. do
    38.     case $optb in
    39.         "Select the ExternalSD Mount point")
    40.     echo "
    41.  
    42. Select the ExternalSD Mount point
    43.  
    44. "
    45.             select extl in /mnt/*; do test -n "$extl" && break; echo ">>> Invalid Selection, please select a number"; done
    46. echo $extl > $def/ext
    47.  
    48. echo -e "
    49.  
    50. Set Defaults Menu
    51.  
    52. 1) Select the ExternalSD Mount point
    53. 2) Set Default ExternalSD location (The new location)
    54. 3) Select the InternalSD Mount point
    55. 4) Return to Main menu
    56.  
    57. "
    58.             ;;
    59.         "Set Default ExternalSD location (The new location)")
    60.     echo "
    61.  
    62. Set Default ExternalSD location (The new location)
    63.  
    64. "
    65.             select extldir in $extl/*; do test -n "$extldir" && break; echo ">>> Invalid Selection, please select a number"; done
    66. echo $extldir > $def/extdir
    67.  
    68. echo -e "
    69.  
    70. Set Defaults Menu
    71.  
    72.  
    73. 1) Select the ExternalSD Mount point
    74. 2) Set Default ExternalSD location (The new location)
    75. 3) Select the InternalSD Mount point
    76. 4) Return to Main menu
    77.  
    78. "
    79.             ;;
    80.         "Select the InternalSD Mount point")
    81.     echo "
    82.  
    83. Select the InternalSD Mount point
    84.  
    85. "
    86.             select intl in /mnt/*; do test -n "$intl" && break; echo ">>> Invalid Selection, please select a number"; done
    87. echo $intl > $def/int
    88.  
    89. echo -e "
    90.  
    91. Set Defaults Menu
    92.  
    93. 1) Select the ExternalSD Mount point
    94. 2) Set Default ExternalSD location (The new location)
    95. 3) Select the InternalSD Mount point
    96. 4) Return to Main menu
    97.  
    98. "
    99.             ;;
    100.         "Return to Main menu")
    101. echo -e "1)  Set Defaults
    102. 2)  Bind using existing defaults
    103. 3)  Quit"
    104. break
    105.             ;;
    106.         *) echo invalid option;;
    107.     esac
    108. done
    109.             ;;
    110.         "Bind using existing defaults          ")
    111.     echo "
    112.  
    113. Bind using existing defaults
    114.  
    115. "
    116. extdirfile=$def/extdir
    117. extfile=$def/ext
    118. intfile=$def/int
    119. ext=$(<"$extfile")
    120. extdir=$(<"$extdirfile")
    121. int=$(<"$intfile")
    122.  
    123.  
    124. # Select the App location to move
    125. printf "
    126.  
    127. Select the directory to move data FROM:
    128.  
    129. "
    130. select AppO in $int/Android/data/*; do test -n "$AppO" && break; echo ">>> Invalid Selection, please select a number"; done
    131.  
    132.  
    133. # Select the location to move to
    134. echo -n "
    135.  
    136. Create a name for the new directory to move data TO (HINT - Use something descriptive):
    137.  
    138. "
    139. read AppN
    140.  
    141. echo -e "
    142.  
    143. Main Menu
    144.  
    145. 1) Set Defaults                          
    146. 2) Bind using existing defaults          
    147. 3) Quit
    148.  
    149. "
    150.  
    151. # Create the new location
    152. mkdir $extdir/$AppN
    153.  
    154. # Move the data to the new location
    155. mv $AppO/* $extdir/$AppN/ 2>/dev/null
    156.  
    157. # Write this data to the bind script.
    158. echo 'mount -o bind '$extdir'/'$AppN' '$AppO'' >> $DIR/bind.sh
    159. sh $DIR/bind.sh
    160. echo -e "
    161.  
    162. Now use script manager to set bind.sh to run as root on boot
    163.  
    164. "
    165.             ;;
    166.         "Quit")
    167.             break
    168.             ;;
    169.         *) echo invalid option;;
    170.     esac
    171. done
    172.  
    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

    Attached Files:


    Advertisement
    :
    Lateralus138 likes this.
  2. SUroot

    SUroot Well-Known Member Developer

    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.

    Attached Files:

  3. SUroot

    SUroot Well-Known Member Developer

    Ok I am going to mark this thread as deprecated.
  4. downthemachine

    downthemachine Developer Incognito VIP Member

    Or appreciated:beer:
  5. SUroot

    SUroot Well-Known Member Developer

    Well the "0 views" said it all really ;)

    Same in the S3 ATR. 150 views+ on XDA though :(
  6. Lateralus138

    Lateralus138 Well-Known Member

    Thanx for this, will check it out on 2 old Lg Apex's I have.
  7. SUroot

    SUroot Well-Known Member Developer

    It was for android 4.2, do they have that? It doesn't work well with some AOSP roms.
Loading...

Share This Page