DarkTremor a2sd

simon.ponder

Well-known member
Dec 3, 2010
444
46
0
Visit site
Slightly cornfused

I do my own sort of apps2sd by adding some userinit scripts to the sd-ext partition of my sdcard. It works great, no lag, plenty of internal storage. As a matter of fact, installing new apps doesn't even use and internal storage until I use the app and it creates user data.

1. create sd-ext partition (assuming you have already done this, but easiest way for me it to use CWM 3.0.0.6 under the advanced menu)
2. create "userinit.d" directory in sd-ext
3. create "app" dir in sd-ext
4. create script in sd-ext/userinit.d to move /data/app/* to /sd-ext/app and bind mount /sd-ext/app as /data/app
Example :
mv /data/app/* /sd-ext/app
mount -o bind /sd-ext/app /data/app

5. chmod the script to 755
6. chown the script to root:system

That's it. All apks installed will go to sd-ext/app, but it will appear as /data/app. This way, you won't wear out the sdcard with tons of read/writes because once the apks are cached in dalvik-cache, they are no longer used unless it is uninstalled/updated or has to build a new cache. All user data is still written to the internal /data partition

You can put as many scripts s you want in /sd-ext/userinit.d and they will get executed in order at boot time (before the boot animation)
I also use this method to move my /data/dalvik-cache to /cache/dalvik-cache (bind mount).
Another use is to put the market fix if you need it.

EDIT : I have over 70 apps installed and my internal storage only has 23MB used ;-)

I do live in Indiana.

So I created a userinit.d directory and an app directory in sd-ext by way way of command line. I created a script called a2d.sh with the commands you gave as an example and placed that file in the userinit.d directory.

I did chmod and chown to the script. I received no errors while doing this through adb shell. I assumed it was gpoing to work correctly, but after uninstalling my apps and then re-installing them with titanium backup, they all went to internal storage, and the ext3 partition was not touched. As far as I could tell, at least.

My sd card ha about 14 g as the first primary fat32 partition, and a 1 g second primary ext 3 partition. How do I ensure that the ext3 partition is exactly what sd-ext is referencing, and does the scripts placed in userinit.d only work for the reboot following when the commands are issued or what?

Maybe a little more explanation would help. If you want me to contact you another way, like a phone call, just pm me.
 

mercrapper

Well-known member
Mar 4, 2011
88
11
0
Visit site
I do live in Indiana.

So I created a userinit.d directory and an app directory in sd-ext by way way of command line. I created a script called a2d.sh with the commands you gave as an example and placed that file in the userinit.d directory.

I did chmod and chown to the script. I received no errors while doing this through adb shell. I assumed it was gpoing to work correctly, but after uninstalling my apps and then re-installing them with titanium backup, they all went to internal storage, and the ext3 partition was not touched. As far as I could tell, at least.

My sd card ha about 14 g as the first primary fat32 partition, and a 1 g second primary ext 3 partition. How do I ensure that the ext3 partition is exactly what sd-ext is referencing, and does the scripts placed in userinit.d only work for the reboot following when the commands are issued or what?

Maybe a little more explanation would help. If you want me to contact you another way, like a phone call, just pm me.

Sorry, I forgot to mention that I run CM7 and it has support for userinit scripts. You will have to check to see if you have a script in /system/etc/init.d that will look for scripts in /sd-ext/userinit.d and execute them. Mine is called "20userinit". If you don't have one, then you will have to add a script in /system/etc/init.d.

Here is the contents of the 20userinit script. If you need to, create the file in /system/etc/init.d and make it executable.
The next time you restart your phone, this script will get executed, look for anything in /sd-ext/userinit.d and execute them.

To check that its working, type "mount" in TE or through ADB.
You should see something like "/dev/block/mmcblkop2 on /data/app"
Also if you do 'ls /data/app", you should get the same result as "ls /sd-ext/app"

#!/system/bin/sh
# call a userinit.sh script if it's present on the sdcard

if [ "$SD_EXT_DIRECTORY" = "" ];
then
SD_EXT_DIRECTORY=/sd-ext;
fi;

if [ -e $SD_EXT_DIRECTORY/userinit.sh ];
then
log -p i -t userinit "Executing $SD_EXT_DIRECTORY/userinit.sh";
busybox chmod +x $SD_EXT_DIRECTORY/userinit.sh;
logwrapper /system/bin/sh $SD_EXT_DIRECTORY/userinit.sh;
setprop cm.userinit.active 1;
fi;

if [ -d $SD_EXT_DIRECTORY/userinit.d ];
then
logwrapper busybox run-parts $SD_EXT_DIRECTORY/userinit.d;
setprop cm.userinit.active 1;
fi;

if [ -e /data/local/userinit.sh ];
then
log -p i -t userinit "Executing /data/local/userinit.sh";
busybox chmod +x /data/local/userinit.sh;
logwrapper /system/bin/sh /data/local/userinit.sh;
setprop cm.userinit.active 1;
fi;

if [ -d /data/local/userinit.d ];
then
logwrapper busybox run-parts /data/local/userinit.d;
setprop cm.userinit.active 1;
fi;
 
Last edited:

simon.ponder

Well-known member
Dec 3, 2010
444
46
0
Visit site
CM7 also

Sorry, I forgot to mention that I run CM7 and it has support for userinit scripts. You will have to check to see if you have a script in /system/etc/init.d that will look for scripts in /sd-ext/userinit.d and execute them. Mine is called "20userinit". If you don't have one, then you will have to add a script in /system/etc/init.d.

Here is the contents of the 20userinit script. If you need to, create the file in /system/etc/init.d and make it executable.
The next time you restart your phone, this script will get executed, look for anything in /sd-ext/userinit.d and execute them.

To check that its working, type "mount" in TE or through ADB.
You should see something like "/dev/block/mmcblkop2 on /data/app"
Also if you do 'ls /data/app", you should get the same result as "ls /sd-ext/app"

#!/system/bin/sh
# call a userinit.sh script if it's present on the sdcard

if [ "$SD_EXT_DIRECTORY" = "" ];
then
SD_EXT_DIRECTORY=/sd-ext;
fi;

if [ -e $SD_EXT_DIRECTORY/userinit.sh ];
then
log -p i -t userinit "Executing $SD_EXT_DIRECTORY/userinit.sh";
busybox chmod +x $SD_EXT_DIRECTORY/userinit.sh;
logwrapper /system/bin/sh $SD_EXT_DIRECTORY/userinit.sh;
setprop cm.userinit.active 1;
fi;

if [ -d $SD_EXT_DIRECTORY/userinit.d ];
then
logwrapper busybox run-parts $SD_EXT_DIRECTORY/userinit.d;
setprop cm.userinit.active 1;
fi;

if [ -e /data/local/userinit.sh ];
then
log -p i -t userinit "Executing /data/local/userinit.sh";
busybox chmod +x /data/local/userinit.sh;
logwrapper /system/bin/sh /data/local/userinit.sh;
setprop cm.userinit.active 1;
fi;

if [ -d /data/local/userinit.d ];
then
logwrapper busybox run-parts /data/local/userinit.d;
setprop cm.userinit.active 1;
fi;

I am running CM7 also, and I changed the file in the userinit.d directory to userinit.sh to see if that will help. I am assuming that if there is a primary partition that is an ext2,3,or 4 on the sdcard, that cm7 automatically mounts it as sd-ext. Is that correct?
 

simon.ponder

Well-known member
Dec 3, 2010
444
46
0
Visit site
/dev/block/mmcblk0p2 on /sd-ext type ext3 (rw,noatime,nodiratime,errors=continue,barrier=1,data=writeback)

So, it is not setting up the symlink correctly, right?

EDIT-

This is the contents of the script I am using:

mv /data/app/* /sd-ext/app
mount -o bind /sd-ext/app /data/app

I think I am missing a forward slash, hold on...
The script isn't running at boot, I can run it manually and it works.

Where to now?
 
Last edited:

chiphead

Active member
Nov 9, 2010
34
9
0
Visit site
I hope u guys realize that anything after froyo includes a2sd, so dont really see the point. The only benefit would be the added space when moving the dalvik vm on the sd card, but with the added wear & tear, the advantages are questionable.
 

mercrapper

Well-known member
Mar 4, 2011
88
11
0
Visit site
I am running CM7 also, and I changed the file in the userinit.d directory to userinit.sh to see if that will help. I am assuming that if there is a primary partition that is an ext2,3,or 4 on the sdcard, that cm7 automatically mounts it as sd-ext. Is that correct?

CM7 expects the ext to be the second partition. I think Ext 2 and 3 are ok, not sure about ext 4.

If you use CWM 3.0.0.6, just go to Advanced->Partition SD. Make sure you backup your SD card as this will erase the card.
 

mercrapper

Well-known member
Mar 4, 2011
88
11
0
Visit site
I hope u guys realize that anything after froyo includes a2sd, so dont really see the point. The only benefit would be the added space when moving the dalvik vm on the sd card, but with the added wear & tear, the advantages are questionable.

The built-in apps2sd is not very good. Every app that is moved to SD is mounted as a separate app, taking a lot of resources and it's slow.

At least that's my opinion.
 

simon.ponder

Well-known member
Dec 3, 2010
444
46
0
Visit site
half right.half wrong

I hope u guys realize that anything after froyo includes a2sd, so dont really see the point. The only benefit would be the added space when moving the dalvik vm on the sd card, but with the added wear & tear, the advantages are questionable.

It has a2sd on a per item basis, and you need to either let android decide, by choosing automatic or manually move to sd card through manage applications. We are trying to get it to move all items except for user data..

EDIT - So as I said before, I can run the commands in the script manually and have success, so I am assuming the script is not getting read correctly or it has the wrong privileges.

I made the script and then chmod 775 on it and chown root:system on it.

Any ideas left?
 

mercrapper

Well-known member
Mar 4, 2011
88
11
0
Visit site
So, it is not setting up the symlink correctly, right?

EDIT-

This is the contents of the script I am using:

mv /data/app/* /sd-ext/app
mount -o bind /sd-ext/app /data/app

I think I am missing a forward slash, hold on...
The script isn't running at boot, I can run it manually and it works.

Where to now?

This is not a symlink. We are actually remounting /sd-ext/app as /data/app, so when anything tries to access /data/app, it is actually looking at /sd-ext/app.

This is better then a symlink because someone or something could delete the symlink and you would have no more /data/app. Also mounting is a little more efficient than symlinks

If you are not going to use the userinit.d directory, then you have to put the script in the root of sd-ext and name it userinit.sh.

If it is still not running on boot, then check there things :
1. /system/etc/init.d/20userinit exists and is executable
2. /sd-ext/userinit.sh is executable
3. /sd-ext/userinit.sh is chmoded to root:system

HINT : While you are testing, you might want to change the move command to a copy command (cp /data/app/* /sd-ext/app)
 

mercrapper

Well-known member
Mar 4, 2011
88
11
0
Visit site
It has a2sd on a per item basis, and you need to either let android decide, by choosing automatic or manually move to sd card through manage applications. We are trying to get it to move all items except for user data..

EDIT - So as I said before, I can run the commands in the script manually and have success, so I am assuming the script is not getting read correctly or it has the wrong privileges.

I made the script and then chmod 775 on it and chown root:system on it.

Any ideas left?

If your script is in userinit.d, the script name can only consist of letters, numbers, hyphen, and underscore.

See excerpt of the run-parts man page below.

run-parts runs all the executable files named within constraints described below, found in directory directory. Other
files and directories are silently ignored.

If neither the --lsbsysinit option nor the --regex option is given then the names must consist entirely of upper and
lower case letters, digits, underscores, and hyphens.

If the --lsbsysinit option is given, then the names must not end in .dpkg-old or .dpkg-dist or .dpkg-new or .dpkg-tmp,
and must belong to one or more of the following namespaces: the LANANA-assigned namespace (^[a-z0-9]+$); the LSB hier‐
archical and reserved namespaces (^_?([a-z0-9_.]+-)+[a-z0-9]+$); and the Debian cron script namespace (^[a-zA-
Z0-9_-]+$).

If the --regex option is given, the names must match the custom extended regular expression specified as that option's
argument.

Files are run in the lexical sort order of their names unless the --reverse option is given, in which case they are run
in the opposite order.
 

simon.ponder

Well-known member
Dec 3, 2010
444
46
0
Visit site
Not executable

This is not a symlink. We are actually remounting /sd-ext/app as /data/app, so when anything tries to access /data/app, it is actually looking at /sd-ext/app.

This is better then a symlink because someone or something could delete the symlink and you would have no more /data/app. Also mounting is a little more efficient than symlinks

If you are not going to use the userinit.d directory, then you have to put the script in the root of sd-ext and name it userinit.sh.

If it is still not running on boot, then check there things :
1. /system/etc/init.d/20userinit exists and is executable
2. /sd-ext/userinit.sh is executable
3. /sd-ext/userinit.sh is chmoded to root:system

HINT : While you are testing, you might want to change the move command to a copy command (cp /data/app/* /sd-ext/app)

script in userint.d wasn't executable, it works now...
I will post it up in an easier to read format, for those that want to try it...

EDIT -- I was wrong, it still isn't mounting correctly. I will test some more.
 
Last edited:

Forum statistics

Threads
943,756
Messages
6,919,925
Members
3,159,215
Latest member
Teresa Belmonte