By Eshwar


2012-03-06 09:20:32 8 Comments

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.

2 comments

@iBug 2017-01-20 14:05:24

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. Assuming 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 can 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. You can test it out as shown below.

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

    However these may work properly, depending on Android version:

    busybox chcon <context> <files...>
    busybox runcon <context <program> [args...]
    
  2. 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.

@iBug 2018-01-16 01:37:06

I had no idea how wrote this comprehensive answer when I see it again after a year. Guess I've forgotten much about Android (which is of course, impossible).

@Izzy 2012-08-03 11:11:22

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.

@Flow 2012-09-14 15:06:35

Would be nice if you could add some information from the links into your post

@Izzy 2012-09-14 15:36:29

That's a bit too much stuff to integrate with my answer -- which is why I only extracted the basic hint, i.e. the app to do the work with.

Related Questions

Sponsored Content

3 Answered Questions

3 Answered Questions

[SOLVED] How can i change app data location?

1 Answered Questions

2 Answered Questions

[SOLVED] How can I symlink the /cache folder on boot?

1 Answered Questions

[SOLVED] How to keep the size of the Dalvik cache small?

Sponsored Content