Can I change the dalvik cache location e.g. with a symbolic link?

by Eshwar   Last Updated February 20, 2017 13:11 PM

I currently use Link2SD since my phone's onboard storage is insufficient for more than a few essential apps. It is very effective but limited to when the phone is on.

While changing ROMs, the dalvik cache is wiped and when the phone restarts you see a progress bar saying Android is optimising applications. So given a reasonable number of applications, the dalvik cache fills up the storage long before link2sd can do anything about it.

So is there a way that mounts a sd card folder as the appropriate cache location before the system gets on with booting and doing its business? I know it might involve creating a symbolic link but I just don't know when things are mounted and in what order.

Answers 2

There are some nice Howtos available, which might prove helpful to solve your issue:

According to several forum threads, A2SDGUI - Darktremor A2SD GUI should be the app of choice to move the Dalvik cache to your SD card.

August 03, 2012 11:11 AM

Of course you can. Although it seems like there's no problem to migrate dalvik-cache to a normal SD card filesystem (the most common, vfat), it still is highly recommended that you format your SD card to ext4 (or the same as your /data) to ensure everything works fine.

So let's go. A full backup of all your apps is recommended before proceeding though if you feel lucky, it isn't required.
Assume that you have a terminal emulator to do the necessary jobs.
First, create a folder that you want to migrate your dalvik-cache to. Then chmod and chown the new folder to match /data/dalvik-cache. If you're running a SELinux-enabled Android OS, don't forget to change security contexts correspondingly. Run

ls -dlZ /data/dalvik-cache
ls -lZ /data/dalvik-cache

to see the original permissions, owner/groups and security contexts of dalvik-cache folder.
Next, copy all files from /data/dalvik-cache to your new location, for example /storage/sdcard1/dalvik-cache. You could use cp -a command to preserve file attributes, which would make things simpler.
Ensure no new apps start during the process of the following step.
Then, rm -r /data/dalvik-cache and create a symbolic link to the new location using

ln -s /storage/sdcard1/dalvik-cache /data/dalvik-cache

That's all. We're done. Reboot your phone (not required but recommended).

Some notices about this process:
1. The busybox may not always work well as Android is based on a highly modified Linux kernel. For example almost all SELinux-related functions do not work properly. For example, test it out as follows.

toolbox ls -Z /data
busybox ls -Z /data
toolbox getenforce
busybox getenforce

However these work properly:

busybox chcon <context> <files>...
busybox runcon <context> <prog> [args...]
  1. Never remove your SD card. If you re-format your SD card, make sure it's still ext4 AND create the dalvik-cache folder back before booting your phone for the first time.
January 20, 2017 14:05 PM

Related Questions

Unable to Install more Apps in Micromax Unite 2

Updated May 02, 2015 21:04 PM

Moving Apps From Internal Storage To SD Card

Updated June 02, 2015 10:04 AM