8

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.

1

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.

  • 1
    Would be nice if you could add some information from the links into your post – Flow Sep 14 '12 at 15:06
  • 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. – Izzy Sep 14 '12 at 15:36
1

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.

  • 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). – iBug Jan 16 '18 at 1:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.