Wanting to automatically move files off of internal storage - Android Q&A, Help & Troubleshooting

I have found myself repeatedly moving the downloads and photos folders to my external SD card, so I decided to try and make a small script or binary that can automate this task without consuming much space. I tried a plethora of "compilers" that run in android, and only Termux with clang could create a file transfer binary, but it can only write to one folder in the external storage, in its app data.
So, I'm asking, is there any way to automate moving folders into the external storage that won't require a large app?

@psychoreactor
Take note that you can't move directories/files if FS of source location and target location is different: hence you have to use copy instead
A small shell script like this example
Code:
#!/system/bin/sh
cp -ar /sdcard/Photos /ext-sdcard/Photos /
rm -rf /sdcard/Photos
mkdir -p /sdcard/Photos
cp -ar /sdcard/Downloads /ext-sdcard/Downloads/
rm -rf /sdcard/Downloads
mkdir -p /sdcard/Downloads
does the job
You run such a script at pre-set time by means of Android's crond service, preferredly when Android boots + 20 seconds
IMHO a far better method ( what doesn't impact internal SD-card's lifespan ) is to format the external SD-card as EXT4 ( this is particularly important, as the file system used on the external SD-card is usually FAT or FAT32 ), create there folders Photos & Downloads, delete original folders, then symlink original folders to these new folders: This way all photos & downloads automatically land on external SD-card.
Code:
ln -s /ext-sdcard/Photos /sdcard/Photos
ln -s /ext-sdcard/Downloads /sdcard/Downloads

Related

[Q] Download App info to internal memory instead of SD

I have an app on my rooted NT called IMAIOS. It's installed already. The thing is, it downloads more information to view the anatomy more in detail, like images of the cranial, chest cavity, etc. Those files that get downloaded, gets saved into my external memory which is only 1gb, so it fills up fast. I have about 10gb free on my nook.
How can I have the app save the data onto the nook instead of the SD card?
Is this an APP issue or an android issue that it can only download into the SD?
Get adb working, backup what is inside your app "IMAIOS" folder in sdcard
$ cd path-to-adb-drivers
$ adb shell
# cd /sdcard
# rm -r IMAIOS
# mkdir /mnt/media/IMAIOS
# rmdir IMAIOS
# ln -s /media/IMAIOS IMAIOS
ctrl+c to exit shell more
$ adb kill-server
$ exit
* Where IMAIOS is the folder that your app created, if it has a different name then just follow the instructions with the correct name.
The aboive should create a symbolic link named IMAIOS to the directory you just created. It's like a shortcut in windows and it should redirect everything to the new location.
Let me know if t works
Edit: Just realized won't work as symlinks can't be done in fat32 partitions . Ill think in something else...
~ Veronica

[Q] How to move obb data from internal SD to internal storage?

I have a xperia u, which has not external SD card slot..
Data partition is MUCH bigger than what I need (I'm using 500mb of 2gb) and I want to move obb files to data partition to free some space in SD partition..
Is that possible?
You might try to move the file to the data partition and then create a symlink where the file was originally.
From a shell with root access:
# ln -s /your/data/partition/filename.obb /original/place/filename.obb
I'm doing the same moving apk and dalvik-cache but I have the problem that after reboot files are still there but the app is disabled.
You can check it here: http://forum.xda-developers.com/showthread.php?t=2597924
I would suggest to try it on an app that it's not important for the system and I don't assume any responsability
P.S.
partition where you create symlink must be ext2/3/4
I think I understand how this works.. Lets say symlinks are some kind of 'windows direct access' for files that can be recognized by the system.. Am I right?
How can I figure out what format are my partitions?
I want to move /mnt/sdcard/Android/obb/com.package.name/file.obb to /data/data/com.package.name/file.obb
Assuming that partitions are in the correct format, I'll have to move files with a root file browser, then connect phone with debug on and type this:
-adb shell
-su
-ln -s /data/data/com.package.name/file.obb /mnt/sdcard/Android/obb/com.package.name/file.obb
Is that ok?
Yest that's the use, I don't know about "windows direct access" because I'm linux user
To check how is your partition formatted there are different ways from console but I just tried this app and it works:
https://play.google.com/store/apps/details?id=com.cls.partition
If both partitions are ext2/3/4 remember also to set the same user, group and permissions, you can do that copying the file from shell.
The whole sequence should look like this:
Code:
$ adb shell
$ su
# cp -a /mnt/sdcard/Android/obb/com.package.name/file.obb /data/data/com.package.name/file.obb
# rm /mnt/sdcard/Android/obb/com.package.name/file.obb
# ln -s /data/data/com.package.name/file.obb /mnt/sdcard/Android/obb/com.package.name/file.obb
cp - a to copy preserving permissions and rm to remove the file.
/data is ext4.. /mnt/sdcard is vfat D=
No symlink then
I never used it but you can still mount bind folders (not files) in fat, something similar to symlink:
Code:
$ adb shell
$ su
# mkdir /data/data/com.package.name/obb/
# cp -a /mnt/sdcard/Android/obb/com.package.name/* /data/data/com.package.name/[B]obb/[/B]
# rm -r /mnt/sdcard/Android/obb/com.package.name/*
# mount -o bind /data/data/com.package.name/[B]obb/[/B] /mnt/sdcard/Android/obb/com.package.name/
if it works you need to find a way to excute that on boot maybe with a init script.
And if there is not crucial data you could even bind all the obb folder together like:
Code:
# mount -o bind /data/data/com.package.name/[B]obb/[/B] /mnt/sdcard/Android/obb/
You can also check this thread:
http://forum.xda-developers.com/showthread.php?t=1410262
Double check everything because I never tried it
Is it possible to add init.d support to my current rom and execute a sh file from it to initialize bind on boot?
No idea sorry
You can try asking in your phone section: http://forum.xda-developers.com/xperia-u
I found how to add init.d support!
Not sure if it works for any device/rom/kernel, but it worked for my Xperia U with GingerBeanSS v3.5 (Sony GB based)..
If anyone is interested, go to this link: http://forum.xda-developers.com/showthread.php?p=32716432
Now I suppose I can create a "BindOBB.sh" with the script you mentioned before in any place of /system, and make a "bindobb" file in /system/etc/init.d/ to execute that script..
So theoretically binding folders should work on every boot!
I used windows my entire life.. I'm not completely sure about linux scripts..
Sorry about making so much questions!
I really appreciate your help!
No problem I'm glad if I can help.
Init script is usually named starting with two numbers like: 00script, 20script, 99script that should give the order scripts are excuted.
For the script itself you need to follow the sample you donwloaded so it will be something like this:
Code:
#!/system/bin/sh
#Comment
busybox mount -o bind /data/data/obb/ /mnt/sdcard/Android/obb/
This is to mount all obb folder or, if you want to mount only some, you can write them all in the script or keep a list of packages in another file and make the script read that.
Remember to make a backup and you might try first with only one package
Ok, I've understood everything (thanks google! ) and done it..
mount -o bind[...] isn't executed by init script.. Maybe a syntax error as it is my first time doing it..
The same command (without 'busybox' at first, of course) seems to work via ADB, because in SolidExplorer when I go to obb folder BEFORE running the script it is empy, but after running it all packages' folders and files appear!
Now problem is that when running a game that need obb data, it closes by itselfs (no FC nor 'missing data' warning)..
Same problem with a 3rd party TTS engine that needs obb data too..
The first problem could be that when you try to execute the command partitions are not mounted yet. Check 00 script used to test if init is enabled to mount them.
Another solution could be to use a sleep command to make the script wait some seconds but the first one should do the trick.
For the second problem check permissions. You copied files as root so you need to be sure the apps can access those files as well, in fat system there is no use of users, group and permissions but moving to ext you need to check that.
To be sure you can set obb folder and all files an directories inside as 777 (rwx for all)
Let me know if it's working
Sent from my ZP980 using Tapatalk
NeriL said:
I want to move /mnt/sdcard/Android/obb/ to /data/data/
Click to expand...
Click to collapse
you can easy create a directory bind using luckypatcher with the folder with obb and the folder where you would like to put it
remember to reboot or rescan your sd else it wont work
i use it to play asphalt and fifa
MrCrayon said:
The first problem could be that when you try to execute the command partitions are not mounted yet. Check 00 script used to test if init is enabled to mount them.
Another solution could be to use a sleep command to make the script wait some seconds but the first one should do the trick.
For the second problem check permissions. You copied files as root so you need to be sure the apps can access those files as well, in fat system there is no use of users, group and permissions but moving to ext you need to check that.
To be sure you can set obb folder and all files an directories inside as 777 (rwx for all)
Let me know if it's working
Sent from my ZP980 using Tapatalk
Click to expand...
Click to collapse
I deleted my custom init script and wrote following command at the last line of '00test' script:
busybox mount -o bind /data/obb/ /mnt/sdcard/Android/obb/
Mount then worked fine
(By the way, my custom script was named '99bindobb', so it was supposedly executed after everything else)
Also checked permissions: /data/obb/ and com.package.name folders inside it were rwxrwxrwx, but files inside were rw-------!
Changed permission of files to rwxrwxrwx..
Now everything works flawlessly at each boot!
Thank you so much! =D =D
You saved about 500Mb of my 4Gb!
And also I learned a lot about linux scripts, busybox and file system permissions!
You are welcome
For the 99 script that only define the order between the user init scripts so it still depends when they are called during boot.
Enjoy the power of Linux
Sent from my ZP980 using Tapatalk
Hi MrCrayon..! I'm here again
I changed rom and did the same as before to use /data insted of /mnt/sdcard for apps files..
This is exactly what I did:
I copied the script I used to sd (my edited 00test), changed rom (switched from Sony based GB rom to Sony Stock ICS rom), added init.d support (/data/Test.log indicates that it works), copied script to /system/etc/init.d/, changed script permissions to 777, created folders /data/AndroidData/ and /data/obb/ with 777 permissions and moved files from sd folders to custom folders in /data..
Finally updated busybox just in case
Script doesn't work, but executing 'mount -o bind' commands from ADB does! How can I fix that?
This is my init script:
#!/system/bin/sh
#Init.d Test
if [ -e /data/Test.log ]; then
rm /data/Test.log
fi
echo Ryuinferno @ XDA 2013 > /data/Test.log
echo Init.d is working !!! >> /data/Test.log
busybox mount -o bind /data/obb/ /mnt/sdcard/Android/obb/
busybox mount -o bind /data/AndroidData/ /mnt/sdcard/Android/data/
busybox set_perm_recursive(0, 0, 0777, 0777, /data/AndroidData, /data/obb)

[Q] Moving files on start up

OK I admit this is somewhat of a n00b question, to a person who knows how Droids works with storage anyway.
The original issue I have is I changed from a phone with no internal memory to one with internal + micro SD. Without too much hacking/modding/customization outside of built in settings or simple file path edits, I want to keep as much of my stuff on the micro SD rather than internal mem incase the phone goes kaput suddenly (like my ol' Droid 3). Unfortunately a few apps here and there point to the internal "sdcard" and can not be changed to the external.
In the end, I was quite happy to simply have a little script that ran on start up (i.e. regularly enough) that moved files from particular folders from to the external sd card. By no means is it the most fancy solution but initially something I could script up myself and be simplistic in the sense that it was just simple file operations and used existing stuff (e.g. no ext apps).
However it's not working and from my logging of things it looks like because at the time userinit.sh runs not all storage has yet been mounted (file/folder not found)?
Here is my simple script cut down to just one path example.
Code:
#!/system/bin/sh
ULOG=/data/local/test.log
date >> $ULOG
cp -R /mnt/sdcard/Pictures /mnt/external_sd 2>> $ULOG
if [ "$?" -eq "0" ]
rm -R /mnt/sdcard/Pictures/* 2>> $ULOG
fi
(and I tried /storage/sdcard0 and /storage/sdcard1 instead of /mnt's with no difference, FWIW)

Cannot write in internal storage

Hello
I have weird problem, I cannot write in internal storage ; all apps functions that requires write access doesn't work.
I installed file explorer with root access. when I navigate to internal storage from " storage/emulated/0" I cannot create new folder (operation failed). but when I navigate to internal storage from "data/media/0" I have write access!
Every folder in the path have write access property.
I tried different solutions with no avail:
I formatted every thing and re-flashed the rom. same problem.
I tried:
Code:
su
echo mkdir /storage/sdcard0 > /data/local/userinit.sh
chmod 700 /data/local/userinit.sh
reboot
Code:
su
restorecon -v -R /data/media
Galaxy note II N7100
android 5.1
exodus-5.1 (cm-12)

Creating Symlink to ext SDCard, so internal has enough space left

Hello Everyone,
I want to create a folder symlink from my internal to my external sdcard, because my whatsapp folder takes too much space on my internal sdcard.
However when i put the ln command into the adb shell, i get an error, even though i am on the root user:
Code:
land:/ # ln -s /storage/self/primary/WhatsApp/ /storage/BECE-1BF7/WhatsApp/
ln: cannot create symbolic link from '/storage/self/primary/WhatsApp/' to '/storage/BECE-1BF7/WhatsApp//WhatsApp': Operation not permitted
Why can't i create the symlink?
Apps like FolderMount do also not work, because they rely on SuperSU and i am using the LineageOS root binary.
I am running LineageOS 14.1
Best regards
Typhoon

Categories

Resources