[MOD] Move Dalvik to /cache to free up 40-60 M on /data

picasticks

Well-known member
Feb 28, 2011
136
58
0
Visit site
This is a mod to move your phone's Dalvik cache to the /cache partition, freeing up the space it would normally take up in /data. Depending on how many apps you've got installed, you'll free up 40+ M of space on /data.

This is an old mod that has been around a while and in all of the Optimus S ROMs. Recently I flashed my phone back to stock to build my own ROM, and was shocked to learn I had to delete half my apps until I'd reimplemented this feature! Finally, I understood why all the V people were messing around with old-school link2sd/app2sd instead of just using the froyo-native "Move to SD card"! :) Personally, I have tons of apps installed and around 60 M free on /data.

I recently contributed this mod to LeslieAnn for Harmonia, so here I'm just putting it out separately. I don't know if he's the original author, but I owe props to KSmith since I originally cribbed mvdalvik.sh from ThundeROM. Thanks!

Can I use this mod?

This mod will only help you if you don't already have it. So, it's great if you're running mostly stock, like me.

I don't know about every ROM, but these ROMs already have this feature (so you don't need to add it):
  • Harmonia (upgrade to latest)
  • Nameless/Reborn
  • CM7

These ROMs don't (yet) have this feature (so you can add it):
  • stock (obviously)
  • Aphrodite
  • Bumblebee
  • Rodimus

Other ROMs ... I haven't checked, but I'll update this list as people provide info.

Count'em ... TWO ways to install

1. There is an easy way, an update .zip. However, it may not be compatible with your ROM.

2. There is the hard way, for which I will give full instructions. It is compatible with everything! However, it requires a Linux machine, the Android SDK installed, and familiarity with the command line. (You *could* also do it on an OS X or Win machine, if you've got mkbootimg and mkbootfs binaries ... but in that case you probably don't need this tutorial).

So, first see if meet the requirements for the easy way. If you don't, or you're just a nerd, look at the hard way.

1. The Easy Way

The update .zip will replace the root filesystem (all the .rc files and other stuff in /) of your phone with a modded one from a stock Optimus V.

Why could this possibly be bad? Well, your ROM may have done customizations in there that you want to keep. Or, it may have done customizations that don't matter to you, at least not as much as 40 M free on /data!

I will try to make recs based on what I know about various ROMs, but you've got to make the decision for yourself.

DO flash the .zip for:
  • stock ROM, including flashed with alternate kernel
  • Aphrodite
  • Bumblebee (NOTE you will lose init.d support ... so if you care about this move on to the hard way)
  • Rodimus (NOTE you will lose init.d support ... so if you care about this move on to the hard way)

If you're still here, just download the attached mvdalvik-update.zip, copy it to your /sdcard, and flash like any update .zip. Last, be sure to wipe Dalvik and cache before you reboot.

2. The Hard Way

1. Download the attached mvdalvik-howto.zip and unzip it. From here on I'll assume it's unzipped into your home directory (and will refer to ~/mvdalvik-howto/filename) but you can put it anywhere. It contains:

  • flash_image: this is an ARM binary for your phone in case you don't already have
  • init.rc.diff: this is a patch you will be applying to your init.rc
  • mkbootfs: this is a Linux x86 binary I compiled from the froyo branch of Android
  • mkbootimg: "
  • mvdalvik.sh: this is a shell script you will be putting in /system/etc/ on your phone
  • split_bootimg.pl: script to unpack the boot partition image

2. OK, first let's put mvdalvik.sh into /system/etc.

Code:
adb shell "mount -o remount,rw /dev/block/mtdblock5 /system"
adb push ~/mvdalvik-howto/mvdalvik.sh /system/etc/
adb shell "chmod 700 /system/etc/mvdalvik.sh"
adb shell "mount -o remount,ro /dev/block/mtdblock5 /system"

3. Now you will dump /boot to boot.img, unpack it, patch init.rc, and repack. (Read this for background.)

Code:
adb shell "cat /dev/mtd/mtd0 > /sdcard/boot-old.img"
adb pull /sdcard/boot-old.img
mkdir ramdisk && cd ramdisk
gzip -dc ../boot-old.img-ramdisk.gz | cpio -i
patch init.rc < ~/mvdalvik-howto/init.rc.diff
cd ..
~/mvdalvik-howto/mkbootfs ramdisk | gzip -9 > ramdisk.gz
~/mvdalvik-howto/mkbootimg --kernel boot-old.img-kernel --ramdisk ramdisk.gz --cmdline 'mem=477M console=ttyMSM2,115200n8 androidboot.hardware=thunderc' --base 0x12200000 -o boot-new.img

4. (possibly optional) If your ROM doesn't already have a flash_image command, you can add the included binary:

Code:
adb shell "mount -o remount,rw /dev/block/mtdblock5 /system"
adb push ~/mvdalvik-howto/flash_image /system/bin/
adb shell "chmod 755 /system/bin/flash_image"
adb shell "mount -o remount,ro /dev/block/mtdblock5 /system"

5. Now push boot-new.img to /sdcard, flash, clean up and reboot to recovery:

Code:
adb push boot-new.img /sdcard/
adb shell "cat /dev/zero > /dev/mtd/mtd0"     # don't worry, "No space left on device" is normal
adb shell "flash_image boot /sdcard/boot-new.img"
adb shell "rm /sdcard/boot-new.img /sdcard/boot-old.img"
adb reboot recovery

6. Wipe Dalvik and cache, and reboot. You're done!
 
  • Like
Reactions: theboundless

picasticks

Well-known member
Feb 28, 2011
136
58
0
Visit site
This moves it to cache partition.
Would I have to uninstall link2sd before attempting this?

Sent from my VM670 using Tapatalk
I haven't tested that but you shouldn't have to.

Link2SD sets up a system of symlinking the apk and dex files of an individual app to copies on another location. This just bind mounts the entire dalvik cache (/data/dalvik) to the cache partition (mtdblock1).

The system just sees /data/dalvik and uses it as normal.
 

overthinkingme

Well-known member
Feb 10, 2011
219
14
0
Visit site
I ask because it symlinked the dalvik cache too with it. I'm guessing the dalvik will be moved symlinks and all?

Thank you for your time and contribution :D

Sent from my VM670 using Tapatalk
 

picasticks

Well-known member
Feb 28, 2011
136
58
0
Visit site
I ask because it symlinked the dalvik cache too with it. I'm guessing the dalvik will be moved symlinks and all?

Thank you for your time and contribution :D

Sent from my VM670 using Tapatalk
You're welcome!

Yes, that's what I think will happen. When you do this mod, you will want to wipe dalvik and cache in recovery. Then, on boot, dalvik is mounted to a different disk partition. Then the system rebuilds the dalvik cache. Finally, Link2SD will start once the full system is up, and do whatever magic it normally does (which I think is to look for .dex files in /data/dalvik, move them to sd partition, and symlink in /data/dalvik to the sd versions).

If you are using Link2SD, this won't free up as much space as if you weren't, because these .dex are living on SD. But, there's still the dalvik cache for all your system/apps, and now that will be on cache instead of data, so you should still gain some space.
 

00_wrath_00

Well-known member
Mar 11, 2011
657
82
0
Visit site
I'm on RA-thunderc-1.1.0-GNM

Where am I supposed to put the zip file?

Oh yeah, and will losing init.d support affect sl4a scripts?

Just place on the root of your sd card. Go to flash zip on thunderc recovery scroll down til you find the zip name. As to your other question not sure if you'll lose it or not.

Sent from my VM670 using Tapatalk
 
  • Like
Reactions: theboundless

theboundless

Well-known member
Mar 16, 2011
180
14
0
Visit site
Thanks, I got it working, my recovery was just acting wonky I guess, i deleted the file, redownloaded it, deleted a few old useless zips on my sd card, and there it was! Trying it out right now, funny, I just posted on the bumblebee rom thread about doing this! Great timing Pikasticks :)
 

JMusic

Well-known member
Nov 19, 2009
136
15
0
Visit site
I was asking about this earlier and was directed to this post. I'm just curious if there is an easier way, because this seems like it may be more complex than it needs to be. On my old Samsung Moment I moved the dalvik cache to the cache directory and just linked it back to the data directory. Is there a reason this wouldn't work on the Optimus?
 

JMusic

Well-known member
Nov 19, 2009
136
15
0
Visit site
And on another note...

adb pull /sdcard/boot-old.img
mkdir ramdisk && cd ramdisk
gzip -dc ../boot-old.img-ramdisk.gz | cpio -i

needs to be:

adb pull /sdcard/boot-old.img
./split_bootimg.pl boot-old.img
mkdir ramdisk && cd ramdisk
gzip -dc ../boot-old.img-ramdisk.gz | cpio -i
 

zedorda

Well-known member
Mar 16, 2011
2,594
178
0
Visit site
Can this be used with Data2ext or would it be pointless?

I was hoping to run the Dalvik cache on the phones memory instead of the SD will this be the case with this mod?
 

LeslieAnn

Android Developer
Feb 8, 2011
2,895
1,720
0
Visit site
I was asking about this earlier and was directed to this post. I'm just curious if there is an easier way, because this seems like it may be more complex than it needs to be. On my old Samsung Moment I moved the dalvik cache to the cache directory and just linked it back to the data directory. Is there a reason this wouldn't work on the Optimus?

Easiest method is to load a rom with it included.
Harmonia and Bumblebee have it built in, I'm not sure about Nameless/Reborn.
 

JMusic

Well-known member
Nov 19, 2009
136
15
0
Visit site
Easiest method is to load a rom with it included.
Harmonia and Bumblebee have it built in, I'm not sure about Nameless/Reborn.

I'm not looking for easy, just "works". I like the ROM that's on the phone already just fine. The reason I asked about sym-linking is it seems so logical that I was curious why it wasn't being used.

I'm quite alright with doing any necessary work (I started with the manual steps for this mod, obviously).
 

J_Jetski

New member
Oct 10, 2012
3
0
0
Visit site
Thanks Picasticks for making this mod avaliable to us. Unfortunately when I flashed mvdalvik-update.zip to my android it now won't start up. When I turn it on it just says "fastboot mode" in small letters up in the top left corner and does nothing. At that point it doesn't respond to the power button either, so I just have take out the battery to turn my phone off. I did not wipe the dalvik and cache in recovery, because I didn't know what that meant exactly, so could that be why my phone is not starting up now? In the recovery mode on my phone where I flashed the mvdalvik-update.zip from, it didn't apear to have an option to wipe the davik or cache. (By the way, in my limited understanding I thought that you were refering to the folder data\davikcache, which I have deleted from time to time to remove any useless left over files from uninstalled apps, but I didn't bother to delete this time before shutting down the OS, because it starts rebuilding it as soon as you've deleted it. I just presumed that there would be an option to wipe it in recovery mode.)

So the main problem is, I can't boot my phone now and don't know how to fix it - either revert it back to the way it was, or just make it boot up. Unfortunately I didn't do a nandroid backup first. I need to get my phone back up and running. Is anyone able to help??

My phone is a rooted Acer Liquid MT S120 and is running stock ROM Gingerbread 2.3.6 and use Link2SD with partitioned SD card.