[MOD] How to replace /cache partition with a virtual one (any size)

Search This thread

stratosk

Recognized Developer
Mar 3, 2011
6,223
31,852
Thessaloniki
www.semaphore.gr
I found a solution to temporarily replace the /cache partition with a virtual one having any arbitrary size.

I made a script that creates an empty file (64MB but it can be larger) on /data/local. Then it creates an ext4 filesystem on the file, unmounts the /cache and finally mounts the file as the cache partition through the loop device.

This virtual partition works until the next reboot and then the old /cache partition is mounted again.

To test this, copy the script to your phone give it executable permissions and run it through adb shell or a terminal. You have to be root and have busybox installed

I tested the script on stock JVQ, Semaphore kernel and works OK.

You may find a CWM edition (thanks to corgar) here. This version will create the cache partition (50 MB) in the /dbdata.

Use this script only if you know what you are doing and with your own risk!.
 

Attachments

  • change_cache.txt
    414 bytes · Views: 1,877
Last edited:

neswii

Senior Member
Sep 22, 2010
221
38
What does this do exactly? Does it take part of the flash memory to use as cache instead of RAM? I dont know much about advanced hacking etc, but this sounds like it could fix my constantly restarting apps when there are too many apps opened at the same time, or too many processes running at the same time. or are those things unrelated with this?
 

stratosk

Recognized Developer
Mar 3, 2011
6,223
31,852
Thessaloniki
www.semaphore.gr
What does this do exactly? Does it take part of the flash memory to use as cache instead of RAM? I dont know much about advanced hacking etc, but this sounds like it could fix my constantly restarting apps when there are too many apps opened at the same time, or too many processes running at the same time. or are those things unrelated with this?

No, it creates a file in the /data partition and mount it as cache. I don't think that this will solve you the problem.
I made it mostly for people who want to download applications more that 30 MB from market
 

Rebel2k

Senior Member
May 19, 2007
1,338
283
I'm ready to test during the day. Do you have any name of a free app bigger than 30 Mb we can download to validate it works? ;)
 

lucbl1

Senior Member
Oct 6, 2010
97
2
I've runned the script with SGS Tools. It runs ok, and creates a bigger cache partition, but i still can't download bigger apps on market, although it now gives me a different error (before was something like: There isn't space on this device. And now it is something like: There was an error). Tried with "Battle Bears 1 Lite" and "Extreme Formula"


EDIT: is it ok to run with SGS tools? I don't know how to run them in Terminal! Someone could tell me how?
EDIT 2: Actually i've tried now, and i can't download any apps from market! :(
 
Last edited:

stratosk

Recognized Developer
Mar 3, 2011
6,223
31,852
Thessaloniki
www.semaphore.gr
I've runned the script with SGS Tools. It runs ok, and creates a bigger cache partition, but i still can't download bigger apps on market, although it now gives me a different error (before was something like: There isn't space on this device. And now it is something like: There was an error). Tried with "Battle Bears 1 Lite" and "Extreme Formula"


EDIT: is it ok to run with SGS tools? I don't know how to run them in Terminal! Someone could tell me how?
EDIT 2: Actually i've tried now, and i can't download any apps from market! :(

Are you sure you have enough space on /data ?
 

lucbl1

Senior Member
Oct 6, 2010
97
2
Are you sure you have enough space on /data ?

Yeah, pretty sure.
I've rebooted my device now, and downloads work fine again, except of course of those bigger than 30mb (actually 26mb, since ext4 conversion uses 4mb on cache).

PS: thinking about it now, could it be that the 4mb of ext4 conversion is keeping me from downloading the apps properly?
 

corgar

Senior Member
Oct 12, 2010
1,062
118
Rome
Just modified that script to move cache in dbdata ( onenand). A little request how to mount without specify fs? Instead of mount -t ext4. Thx

Inviato dal mio GT-I9000 usando Tapatalk
 

stratosk

Recognized Developer
Mar 3, 2011
6,223
31,852
Thessaloniki
www.semaphore.gr
Yeah, pretty sure.
I've rebooted my device now, and downloads work fine again, except of course of those bigger than 30mb (actually 26mb, since ext4 conversion uses 4mb on cache).

PS: thinking about it now, could it be that the 4mb of ext4 conversion is keeping me from downloading the apps properly?

I'm not sure about this.
If you don't use this remember to delete the cache.img file from /data/local because it's 64MB :)
 

corgar

Senior Member
Oct 12, 2010
1,062
118
Rome
If i delete the conversion and want to make the script dynamic? Mount rfs if rfs or mount ext4 if ext4. Dbdata is converted by kernel and by user decision so making it dynamically check is a must have i think.

Inviato dal mio GT-I9000 usando Tapatalk
 

stratosk

Recognized Developer
Mar 3, 2011
6,223
31,852
Thessaloniki
www.semaphore.gr
If i delete the conversion and want to make the script dynamic? Mount rfs if rfs or mount ext4 if ext4. Dbdata is converted by kernel and by user decision so making it dynamically check is a must have i think.

Inviato dal mio GT-I9000 usando Tapatalk

Actually you may have dbdata in rfs and the file system of the cache.img could be ext4. You make and independent file system on this file
 
  • Like
Reactions: corgar

corgar

Senior Member
Oct 12, 2010
1,062
118
Rome
ok after some testing and tuning up, and since market apps can go up to 50mb maximum, and dbdata is on fast onenand i've modified a bit your script.

Code:
#!/system/bin/sh

# 
# stratosk - 27/07/2011
# Corgar - 28/07/2011 ( changed location of cache in dbdata for onenand i/o, decreased cache dimension to 50mb )
# Remount /cache partition with a larger one (54.5 MB / 50mb cache)

# create a file 54.4 MB
dd if=/dev/zero of=/dbdata/cache.img bs=1024 count=55808

# create ext4 filesystem 
mke2fs -F -T ext4 /dbdata/cache.img

# unmounting old cache partition
umount /dev/block/stl11

# mount 
losetup /dev/block/loop7 /dbdata/cache.img
mount -t ext4 /dev/block/loop7 /cache

chown system.cache /cache
chmod 770 /cache


here are the script to push in /system/init.d folder. i'm not making a cwm flashable zip because is still in test version and i prefer at the moment to be used only by "veteran" user.


thx anyway to stratosk.

Download Here!
 
Last edited:
  • Like
Reactions: skorm and stratosk

corgar

Senior Member
Oct 12, 2010
1,062
118
Rome
sdcard is mounted and checked after fs integrity check.

sdcard is slow compared to onenand memory. also sdcard is more fragmented than internal memory.
 

corgar

Senior Member
Oct 12, 2010
1,062
118
Rome
Running flawlessy on my custom rom. Very nice job indeed. Thx man. If you need a link Just ask but It's only for italian customer.

Inviato dal mio GT-I9000 usando Tapatalk
 

stratosk

Recognized Developer
Mar 3, 2011
6,223
31,852
Thessaloniki
www.semaphore.gr
Running flawlessy on my custom rom. Very nice job indeed. Thx man. If you need a link Just ask but It's only for italian customer.

Inviato dal mio GT-I9000 usando Tapatalk

Glad to hear that:)
Did you test it on market applications > 30 mb?

Thanks for feedback.

P.S. with similar manner you can make portable (and maybe encrypted) filesystem. Create a file mount it as filesystem, write anything you want in it, then umount and mount somewhere else... Even in other phone or in your linux box

Edit: yes please send me the link
 
  • Like
Reactions: corgar

Top Liked Posts

  • There are no posts matching your filters.
  • 23
    I found a solution to temporarily replace the /cache partition with a virtual one having any arbitrary size.

    I made a script that creates an empty file (64MB but it can be larger) on /data/local. Then it creates an ext4 filesystem on the file, unmounts the /cache and finally mounts the file as the cache partition through the loop device.

    This virtual partition works until the next reboot and then the old /cache partition is mounted again.

    To test this, copy the script to your phone give it executable permissions and run it through adb shell or a terminal. You have to be root and have busybox installed

    I tested the script on stock JVQ, Semaphore kernel and works OK.

    You may find a CWM edition (thanks to corgar) here. This version will create the cache partition (50 MB) in the /dbdata.

    Use this script only if you know what you are doing and with your own risk!.
    4
    What does this do exactly? Does it take part of the flash memory to use as cache instead of RAM? I dont know much about advanced hacking etc, but this sounds like it could fix my constantly restarting apps when there are too many apps opened at the same time, or too many processes running at the same time. or are those things unrelated with this?

    No, it creates a file in the /data partition and mount it as cache. I don't think that this will solve you the problem.
    I made it mostly for people who want to download applications more that 30 MB from market
    4
    OK try this

    Rename to remove .txt extension, chmod to 777 and then reboot. Verify by running "df" command in terminal.
    Or use this:
    CWM flashable version

    Anyone know if clearing cache at boot is a good/bad thing?
    3
    Well, why not just use:

    Code:
    umount /cache
    mount -o rw,remount -t rootfs /
    rmdir /cache
    mkdir /data/cache
    ln -s /data/cache /cache

    It's much easier and should be faster (no extra abstraction layer),
    and works perfectly for me - using this /cache size is only limited
    by /data free space.

    Thanks , this method worked. The OP's method somehow didn't work. When trying to download cordy it was still throwing error.

    A related issue: Do you know how to solve the incompatibility issue which comes up when trying to install applications like Lookout Mobile Security, Android System Info for Galaxy S?

    Maybe edit something in build.prop, to fool the android market in thinking that it is compatible? [not sure why it would be incompatible though for SGS]

    EDIT: Guess , I spoke too soon. It downloaded, but said package invalid. So, finally changing the OP's script by one line, it finally worked.

    Code:
    #!/system/bin/sh
    
    # 
    # stratosk - 27/07/2011
    #
    # Remount /cache partition with a larger one (64MB)
    
    # create a file 64 MB
    dd if=/dev/zero of=/data/local/cache.img bs=1024 count=65536
    
    # create ext4 filesystem 
    mke2fs -F -T ext4 /data/local/cache.img
    
    umount /dev/block/stl11
    
    # mount 
    losetup /dev/block/loop7 /data/local/cache.img
    mount -t ext4 /dev/block/loop7 /cache
    
    [B]chown 1000.2001 /cache[/B]
    chmod 770 /cache
    3
    Hah I also wanted Third Blade when I ran into this problem. I fixed it by mounting a directory on sdcard as cache.

    su
    umount /cache
    mkdir /sdcard/cache
    busybox mount /sdcard/cache /cache

    Need to repeat after a reboot but I reboot my phone maybe once a month once it is working well (which it is right now!).
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone