[Q] Configure a permanent mount -o bind in init.d - Android Q&A, Help & Troubleshooting

I want to set the cache folder of Google Music to the external sdcard using mount -o bind command
I created a file (without extension) that contains the following
Code:
#!/system/bin/sh
mount -o bind /emmc/Android/data/com.google.android.music/ /sdcard/Android/data/com.google.android.music/
I made sure the target folder exists and saved the file to /system/etc/init.d, but in fact it looks like the script isn't executed.
P.S. the script file's properties are: -rwxr-xr-x, Owner: 00000 root, Group: 02000 shell.

Storing permanent data
How?

Related

[EXPANDSD] Join your external SD with internal SD!

WARN: For developer only.
attachment is the EXPANDSD script.
Why use it?
So many applications use /sdcard for mass data storage(gameloft, navigation...),
but I9100's internal_sd size is limit to 11G, so we need external_sd's space.
But these applications dosen't know how to use external_sd, old method is hack the apk for external_sd, but this will change apk's signature, and need smali/baksmali to work. My method work in system level, don't need change any apk file.
How to use:
1.make expandsd.ownhere dirctory in external_sd root directory.
2.move internal_sd's directory(for example:/gameloft) to expandsd.ownhere
3.run init_expandsd.sh
Theory:
use 'mount --bind' feature, bind external_sd's dir to internal_sd.
Because the sd card using fat32 partition format, the 'ln -s' command does not work, so the "mount --bind" is the only way to dynamically change the directory content.
Hi mate,
Thks for your shares. I have a question. How run init_expandsd.sh?
I tried gscript and init.d, but doesn't seem to be working
woohoo a great dev has come. glad you got here mate! love your work on Desire section.
harrynghiem said:
Hi mate,
Thks for your shares. I have a question. How run init_expandsd.sh?
Click to expand...
Click to collapse
you can try to use terminal emu, just type su then navigate to folder where the script located, then type sh init_expandsd.sh then enter. this might do the trick to execute .sh
dexterdave said:
you can try to use terminal emu, just type su then navigate to folder where the script located, then type sh init_expandsd.sh then enter. this might do the trick to execute .sh
Click to expand...
Click to collapse
Does it work for you?
It's a great idea thanks a lot for your work. I was wondering why ln was not working.
But too bad it does not work for me, i get the following error :
[1] Segmentation fault
Do you have any idea why ?
Thanks again
problems when connecting phone to pc
hi,
tried the "mount --bind" in order to try your script.
works fine. the directory contents is shared between the 2 path's,
but i have a problem when i connect the phone to a pc.
when i try to disconnect, the sdcard and external_sd are not
available anymore until i reboot the phone
note: the commands that i have executed are:
Code:
mkdir /mnt/sdcard/external_sd/foo
echo "test" > /mnt/sdcard/external_sd/foo/test
mkdir /mnt/sdcard/foo
mount --bind /mnt/sdcard/external_sd/foo /mnt/sdcard/foo
Can this script be placed in init.d folder for autorun at boot?
Edit: sorry, already answered above: no, it cannot.
Sent from my GT-P1000 using Tapatalk
Seems abandoned by @ownhere
Sent from my GT-I9100
Idan73 said:
Seems abandoned by @ownhere
Sent from my GT-I9100
Click to expand...
Click to collapse
too bad, it could be very useful..
TheFirstBen said:
It's a great idea thanks a lot for your work. I was wondering why ln was not working.
But too bad it does not work for me, i get the following error :
[1] Segmentation fault
Do you have any idea why ?
Thanks again
Click to expand...
Click to collapse
got the same problem please help
How to use?
ownhere said:
WARN: For developer only.
attachment is the EXPANDSD script.
Why use it?
So many applications use /sdcard for mass data storage(gameloft, navigation...),
but I9100's internal_sd size is limit to 11G, so we need external_sd's space.
But these applications dosen't know how to use external_sd, old method is hack the apk for external_sd, but this will change apk's signature, and need smali/baksmali to work. My method work in system level, don't need change any apk file.
How to use:
1.make expandsd.ownhere dirctory in external_sd root directory.
2.move internal_sd's directory(for example:/gameloft) to expandsd.ownhere
3.run init_expandsd.sh
Theory:
use 'mount --bind' feature, bind external_sd's dir to internal_sd.
Because the sd card using fat32 partition format, the 'ln -s' command does not work, so the "mount --bind" is the only way to dynamically change the directory content.
Click to expand...
Click to collapse
thanks,
this is genius
I'm not using your script (have myself some ux & scripting skills) but did not know about the -bind option on android
Ridiculously simple and efficient
Did it my own way and it works great
Thanks a lot for this
dawabz94 said:
thanks,
this is genius
I'm not using your script (have myself some ux & scripting skills) but did not know about the -bind option on android
Ridiculously simple and efficient
Did it my own way and it works great
Thanks a lot for this
Click to expand...
Click to collapse
Then why not share with us please !
Let us know how you did
Yes I'd like to know another method also.!
Sent from my GT-I9100 using XDA
Chairmansaab said:
Then why not share with us please !
Let us know how you did
Click to expand...
Click to collapse
Hi,
it's very easy indeed, once you got the point.
I do most of my stuff using an "adb shell" session so I'll post here my steps to get it working.
Also I like simple implementation so my script is the strict minimum needed to mount necessary folders
I assume you have a rooted device with working busybox and a kernel that supports /etc/init.d/
I suggest you do the test on a dummy folder before applying on a real folder.
So start by creating a folder called /sdcard/dummy
Do it the way you want , I do it with an "adb shell" session
Code:
cd /sdcard
mkdir dummy
Then copy some files in it (photos for examples)
Code:
cd /sdcard
cd DCIM
cd Camera
cp `ls -1 |tail -5` /sdcard/dummy
From now on, we consider we want to move transparently /sdcard/dummy to the external SD
1. move the folder to the external sd
CAUTION : I'm running a CM9 rom => my external sd is mounted on /mnt/emmc
Standard samsung sdcard mount is /sdcard/external_sd
The path might be different according to your brand and rom
Moving the folder code
Code:
cd /sdcard
mv dummy /mnt/emmc/
2. Create the mount point in the indernal SD
Code:
cd /sdcard
mkdir dummy
3.a Check the mount is successful by manually doing it
Code:
mount --bind /mnt/emmc/dummy /sdcard/dummy
3.b Check you see exactly the same thing on both folders
Both commands should return exactly the same output
Code:
ls -l /sdcard/dummy
Code:
ls -l /mnt/emmc/dummy
If everything is fine, then you're good to go
4. Automate mount at boot time
Create a script in /etc/init.d to automate the mount at boot time
I personally use "vi" but most people prefer graphical UIs, I can't recommend any here, do it your own way
So basically you would go root,remount /system in read/write mode and create the file
Code:
su
mount -o remount,rw /dev/block/mmcblk0p9 /system
cd /etc/init.d
vi 90binds
Insert following lines, save and exit
Note that the "sleep 60" is to let the system boot up before mounting partitions (thanks to the initial script shared here)
Code:
#!/system/bin/sh
sleep 60
mount --bind /mnt/emmc/dummy /sdcard/dummy
Change owner and permissions, flush disk cache and remount /system in read only
Code:
su
mount -o remount,rw /dev/block/mmcblk0p9 /system
cd /etc/init.d
chown root:shell
chmod 6755 90binds
sync
mount -o remount,ro /dev/block/mmcblk0p9 /system
To check, run
Code:
su
cd /etc/init.d
ls -l 90binds
The output should look like this :
Code:
-rwsr-sr-x 1 root shell [I]0 MMM D HH:MM[/I] 90binds
5. Now you can reboot and check - after reboot - that the mount is done
Both commands should return exactly the same output (always ran in an "adb shell" session)
Code:
ls -l /sdcard/dummy
Code:
ls -l /mnt/emmc/dummy
6. Now you're good to move other folders
Basically, you move the folder to external SD
Create the mount point on the internal SD
Append the mount command in the 90binds script
And that's it
Hope this helps
---------- Post added at 11:09 AM ---------- Previous post was at 11:04 AM ----------
benc88 said:
Yes I'd like to know another method also.!
Sent from my GT-I9100 using XDA
Click to expand...
Click to collapse
Just posted
Take time to read and understand the idea

[Q] Changes made in "/" directory lost after reboot

Hi, Everyone
I want to create a folder in the "/" directory and make some symbolic link to the frequently used folders inside the sdcard , everyone know the top directory of the sdcard is a mess.
My phone rooted, and I successfully create a directory named "storage" in the "/" directory and do some "ln -s" things . it works fine . I can access the folders in the sdcard by the link I create. by the way I use "mount -o rw,remount -t rootfs /" to gain the write permission.
But when i reboot the phone ,the "storage" folder is gone !
Does anyone have the same issue?

[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] Hosts file ressetting on reboot

Does anybody know why my hosts file gets reset after a reboot no matter whether I change with adaway or adblock or if I manually replace the hosts file myself and set to read only. Have searched about and only solution I read about was get a custom kernel. Although I am already on a custom kitkat ROM and using dorimanx kernel for galaxy s2. Also never had problems with hosts resetting on jb or ICS. Even creating a symlink to data/data/hosts doesn't work. On reboot the symlink just gets replaced with the original useless hosts file.
Sorry to bump but it is irritating and can't find a solution.
just some hints,
hosts file is located on /system partition which should be read only mounted during runtime.
check:
Code:
# mount | grep /system
/dev/block/mmcblk0p9 /system ext4 ro,seclabel,relatime,user_xattr,barrier=1,data=ordered 0 0
ro is ok. If so, the file can be changed only during boot (some init script) or later by app with root permission.
check if some init script is not involved:
Code:
# grep hosts /init*
Code:
#grep hosts /system/etc/init.d/*
Is there any output of the commands? I'm on i9100/CM10.2 and there is no output.
Then would be good to revoke root permissions to all apps (not unroot) and see if the issue is still there.
and also check the time of last change of the file:
Code:
ls -l /system/etc/hosts
is it realy during boot?
After spending entirely too much time on this I finally have a working solution. Save the contents of this script to your internal SD card. Ensure the last line is a blank carriage return.
Code:
#!/system/bin/sh
sleep 10
mount -o rw,remount /system
cp /storage/emulated/0/Download/working/hosts /system/etc
Install Script Manager (SManager), and set this script as: on boot, executable, as root. This will then copy your custom "hosts" file under your SDcard to /system/etc after 10 seconds.
Using this script through init.d didn't work for me, which I guess means whatever was over-writing my "hosts" file was doing after the init.d process.
Definitely remount system partition to read only again. Append following line to your script:
Code:
mount -o ro,remount /system
d0gd3v said:
Definitely remount system partition to read only again. Append following line to your script:
Code:
mount -o ro,remount /system
Click to expand...
Click to collapse
good call, thanks

Mount ext4 formatted SD card

Requirements:
Rooted device
SD card formatted to ext4/3/2
Terminal app installed
Optional: A file explorer (I use ES file explorer)
Basic command line knowledge
Step 1: Run as root
Open the terminal app and execute this:
Code:
su
This is necessary for the next commands to be executed with root privilege.
Step 2: Identify SD card partition(s)
Execute:
Code:
blkid
or
Code:
cat /proc/partitions
This will spit out a bunch of partitions but we're looking for a device that reads something like "/dev/block/mmcblk1".
In my case there's two of those, because I have two partitions on my SD card. One reads "mmcblk1p1", which is ExFat and the other reads mmcblk1 and is ext2. We'll be mounting the second one, so my partition is /dev/block/mmcblk1p2. It isn't ext4 but the the process is the same.
Step 3: Create folder to mount to
We will need to create a folder to mount the partition to and I will go along with the "/storage/sdcard0" directory and choose "/storage/sdcard1". You can however choose any name you want.
So run this:
Code:
mkdir /storage/sdcard1
or replace sdcard1 with a different name if desired.
Step 4: Mounting
The command syntax for mounting is as follows:
Code:
mount -t ext4 partition path
My device is "/dev/block/mmcblk1p2" and my path is "/storage/sdcard1" so this is what I'll run:
Code:
mount -t ext4 /dev/block/mmcblk1p2 /storage/sdcard1
(I used ext4 with an ext2 partition but it works regardless.)
If there were no issues the command will run without an output.
Now you can test if it's mounted by going into the folder with
Code:
cd /storage/sdcard1
and making a folder:
Code:
mkdir test
If you list the files:
Code:
ls
you should see "test".
Step 5: Gaining read/write permission
Execute:
Code:
chmod -R 777 /storage/sdcard1
obviously with your own path and now you should be able to open the directory in a file manager and write into it.
Works, but no file managers recognise its mounted.
Spaceboy60 said:
Works, but no file managers recognise its mounted.
Click to expand...
Click to collapse
Check the folder you made with mkdir, it should be there.

Categories

Resources