Moving Android’s (2.3.x) /data Partition

Just a small data2sd script I wrote for my phone. Runs well on CyanogenMod7.2, second partition formatted as ext4. ext2 works but I’ve had one too many occasions of lost data due to unexpected reboots and fsck chaos. Root, init.d, Busybox, and kernel support required.

#!/system/bin/sh
#a simple data2sd script hardcoded for the Samsung i5510/Callisto
#you may modify file as needed

if [ -e /dev/block/mmcblk0p2 ]; then
        
#mounting mmcblk0p2 to /sd-ext 
        busybox mount /dev/block/mmcblk0p2 /sd-ext -o noatime,data=ordered,barrier=1
#mounting stl13 to /system/stl13
	busybox mount /dev/block/stl13 /system/stl13 -o noatime,data=ordered,barrier=1
#        busybox mount /dev/block/mmcblk0p2 /data -o noatime,data=ordered,barrier=1
fi
busybox mount -o noatime /dev/block/stl13 /system/stl13

#simple sanity check
#checks if these directories exist to avoid some mount problems
        if
                [ ! -d /sd-ext/data ]; then
                busybox mkdir /sd-ext/data
                busybox chown 1000:1000 /sd-ext/dalvik-cache   
                busybox chmod 771 /sd-ext/dalvik-cache
        fi
        if
                [ ! -d /sd-ext/app ]; then
                busybox mkdir /sd-ext/app
                busybox chown 1000:1000 /sd-ext/app
                busybox chmod 771 /sd-ext/app
        fi
        if      [ ! -d /sd-ext/dalvik-cache ]; then
                busybox mkdir /sd-ext/dalvik-cache
                busybox chown 1000:1000 /sd-ext/dalvik-cache   
                busybox chmod 771 /sd-ext/dalvik-cache
        fi

#MIUI doesn't seem to like the whole /data partition to be replaced
#so we'll just abuse bind mounts 
#just comment the line you don't want to be placed at /sd-ext
#but please note, it WILL NOT copy the files for you
        
#        busybox mount -o noatime,bind /sd-ext/app /data/app
#        busybox mount -o noatime,bind /sd-ext/data /data/data
#        busybox mount -o noatime,bind /sd-ext/dalvik-cache /data/dalvik-cache

#if you're feeling a bit adventurous, you can just bind mount 
#the whole /data partition instead but be sure to comment the lines
#above  
        
        busybox mount -o bind,noatime /sd-ext /data                           
#        busybox mount -o bind,noatime /system/stl13/dalvik-cache /cache/dalvik-cache
#	busybox mount -o bind,noatime /system/stl13/dalvik-cache /data/dalvik-cache
#        busybox mount -o bind,noatime /system/stl13/data /data/data

#I used bindmounts instead of symlinks because it (for me)
#does not requre the sd card to be necessarily in the phone
#though it will cause the device to reset data until it is 
#rebooted with the appropriate sd card inside, until which,
#it will return back to normal.

#PARTS="stl12 stl13 stl14"
#for j in $PARTS; do
#	busybox mount -o remount,noatime,data=writeback /dev/block/$j
#done
Advertisements

Carefully twist your words.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s