11

I have a Moto G (2nd generation) with Android 5.02 on it. Internal SD card is about 8Gb and I have an external SD card with 16Gb free space.

Moving application to SDCARD from the application's menu moves it to sdcard0 which is the internal SD card.

Adb shell command:

pm get-install-location

gives me:

0[auto]

I tried to set installation location through:

pm set-install-location 2

But I'm getting this error:

Error: java.lang.SecurityException: Package android does not belong to 2000

That is I believe complaining about root permissions.

And because it's a production build trying:

adb root

gives me:

 adbd cannot run as root in production builds

Is there any way to set the applications install their data to external SD card?

P.S: I don't want to install a custom rom or install third party software to root the phone.

Edit: I've noticed that applications data was stored in the folder /storage/sdcard0/Android, so I thought of moving this folder to /storage/sdcard1/ and creating a symlink this way instead:

ln -s /storage/sdcard1/Android /storage/sdcard0/Android

will this do the job?

Thank you.

pr.nizar
  • 253
  • 1
  • 2
  • 9

5 Answers5

10

Basically speaking: You can't. At least not without rooting.
The main reasons Android does not allow you to install an application to your external SD card are:

  1. Security: It's the main reason for that restriction. Basic file systems like NTFS or FAT (any version of it) do not allow for Unix-like permission management.
    This means: any application would be able to write to any file on that storage.
    Thinking of malicious apps, they would be able to replace proper apps with fake/infected ones, bricking your phone and rendering it unusable.

  2. Volatile storage: Your external SD card is not safe to be inserted in your device all the time. You are able to eject it any time what makes your SD card not a very good candidate for a permanent storage. Consider apps running off of your SD card and you eject it. Those apps will just crash and all other apps saved on your SD card are gone as well. You can't use them at that time and the data of those app is also affected by reason #1.

GiantTree
  • 4,062
  • 1
  • 20
  • 26
  • I have a linux background so I've considered this approach: I've noticed that the application's menu option "Move to SDCARD" created a folder called Android on sdcard0 (the internal one) with applications data on it; will creating a symlink (in sdcard0) called Android to a folder called Android in sdcard1 work? – pr.nizar Apr 20 '15 at 18:26
  • The issue is: Android stores only application data and obb in /sdcard/sdcard0/Android. Applications are stored in a hidden folder called .android_secure where not even root has access to (I tested it on my device, you can't evencd to that folder). – GiantTree Apr 20 '15 at 18:49
  • Actually that's precisely what I need! The main problem getting me thinking of this is the data especially with heavy games.. The main applications are not that big compared to the data they add later. So you think it might work? – pr.nizar Apr 20 '15 at 18:57
  • If it is only data or obb then it certainly works. At least on Android versions that do not make sdcard_rw belong to the root group or feature the user sdcard_rw at all. But with a bit of permission changes you should be able to get that sorted out. – GiantTree Apr 20 '15 at 19:00
  • Running ls -l /storage/sdcard0 gave me this lrwxrwxrwx root root 2015-04-20 15:59 sdcard0 -> /storage/emulated/legacy and running ls -l /storage/sdcard0/ gave me this drwxrwx--x root sdcard_r 2014-12-20 18:16 Android.. Is that a good or bad news? Since I'm not root I believe I can not set permissions. – pr.nizar Apr 20 '15 at 19:06
  • The first result was predictable, your internal SD card is actually located at /data/media, where storage/emulated/legacy points at. The other result is an "easy fix": First you need to move the original Android folder to another location or rename it, to make space for the symlink. Then link /storage/sdcard1/Android to /storage/sdcard0/Android and name the link Android. At last fix all permissions (777). This is just theoretical but I imagine it should work like this. – GiantTree Apr 20 '15 at 19:13
  • I'm testing it right now. cp -R /storage/sdcard0/Android /storage/sdcard1/ (too shaky about the mv lol) then rm -r /storage/sdcard0/Android then ln -s /storage/sdcard1/Android /storage/sdcard0/Android. If this works the credit goes to you so you may update your answer. I'll let you know! ;-) – pr.nizar Apr 20 '15 at 19:19
  • Don't remove Android it will break all running apps (or at least most of them). It's just a theoretical approach off of my head; nothing to exactly follow. If you are quick enough, you may be able to recover apps after crashing but keep in mind that all actions are undone after the next reboot. – GiantTree Apr 20 '15 at 19:25
  • Yep! It all broke up! lol I was unable to create a symlink: it gave me the error ln: /storage/sdcard0/Android: Operation not permitted. So the next question is how to create a symlink? (I reverted my changes and all is fine.. or so I think for now! lol) – pr.nizar Apr 20 '15 at 19:31
  • The main issue is: Android tracks file accesses and if one of the Android folders are missing, it recreates them a moment later. this is also why applications like Link2SD link individual app's folders instead of the whole Android folder. You can try that, but I can't promise success. – GiantTree Apr 20 '15 at 19:35
  • This is quite interesting because I have a problem with only a data folder of a game (that is taking 2Gb).. I will try that and report back. Thank you. P.S: Link2SD did nothing in my case. – pr.nizar Apr 20 '15 at 19:39
  • It's just how Link2SD worked last time I used it. I don't need it anymore because my storage space is sufficient :) – GiantTree Apr 20 '15 at 19:46
  • I failed to create a single symlink. (Operation not permitted). I believe it's simply because my sdcard1 is fat32 formatted. To what should I format it (I mean its main partition)? – pr.nizar Apr 20 '15 at 19:52
  • You can create a symlink to anywhere, the destination does not matter (even though fuse might not permit you to create a symlink to your external SD card). If you can, try formatting your SD card as ext4 so permissions can be applied without using fuse as an intermediate permission manager, that blocks most read and write attempts without proper package permission. – GiantTree Apr 20 '15 at 19:58
  • I was unable to use ext4 since my phone didn't recognize it and kept w95 fat32 LBA (kernel issue?!).. I was unable too to create symlinks for many reasons: non root (?!), fat32 issue.. Now I believe I'll take option B.. ^^ – pr.nizar Apr 20 '15 at 23:38
  • Only root can create symlinks. Keep that in mind. – GiantTree Apr 21 '15 at 13:20
6

Basically you can! ;)

  • First, Root your phone!
  • Second, Create a secondary partition in your SD card (Ext.4) >= 2GB and set it as primary.
  • Third, download and install Link2sd app from playstore. Open the app, and I will ask you to create a mount point to your 2nd partition. Select Yes. Reboot.

After reboot, EVERY app you install will automatically go to SD card.

If you don't know how to create partition search for a guide in Google there are plenty of them

Kanellis
  • 57
  • 2
4

That was quite a journey searching for an answer not involving rooting but I ended up:

  1. Unlocking my bootloader

  2. Booting on TWRP without installing it:

    fastboot boot recovery.img
    
  3. Installing Chainfire's SuperSU with TWRP.

  4. From Terminal Emulator or adb's shell:

    su
    pm set-install-location 2
    
  5. From an application's menu in Settings > Applications just pushing Move to SDCARD moves it* - its data and obb - to the external SDCARD.

  6. Removing SuperSU......

Full unroot

Nah... I didn't do that! 3:)

pr.nizar
  • 253
  • 1
  • 2
  • 9
0

Go to this address http://developer.android.com/tools/help/shell.html#shellcommands

Android 5 and above does not support this pm get-install-location

Try to backup your apk and follow the steps bellow

adb shell pm install -r -s <path of your apk>

Example

adb shell pm install -r -s /storage/sdcard1/base.apk

-r means reinstall apk with existing data and -s means sdcard

-1

First install Adbd insecure (apk download from xda-developers).

Once installed on your device, open it and mark the box: "Enable insecure adbd".

Now you can change the location to install your apps.

ale
  • 19,723
  • 34
  • 110
  • 159