Skip to content

Instantly share code, notes, and snippets.

@elieux
Last active April 2, 2017 14:56
Show Gist options
  • Save elieux/a35b73de8febfbf87ba5 to your computer and use it in GitHub Desktop.
Save elieux/a35b73de8febfbf87ba5 to your computer and use it in GitHub Desktop.
morespace.sh
#!/system/bin/sh
#
# MORESPACE - init script to use an ext4-formatted sdcard for both app installations and user data
# Revision: 3
# Author: github.com/elieux
# Device: Huawei Ascend G300 [U8815] with CM11
#
# Warning: The script does not reformat your sdcard. That needs to be done manually before installing the script.
# Warning: The script is not designed for multiple-partition sdcards (sd-ext).
#
# These directories should be in the root of the card (missing ones are created on the first run):
# - sdcard: user data (e.g. "Android" directory)
# - app: *.apk
# - app-lib: *.so
# - dalvik-cache: *.dex
#
# Other directories are ignored. The root of the card can be accessed through /mnt/real-sdcard0. The original contents of data partition can be accessed through /mnt/real-data.
#
# Installation in recovery:
# adb shell "mount /dev/block/mmcblk0p12 /system" # or mount system in recovery menu
# adb push 10morespace /system/etc/init.d/10morespace
# adb shell "chmod go-w /system/etc/init.d/10morespace"
# adb shell "chmod +x /system/etc/init.d/10morespace"
#
# Copy the contents of app and app-lib to the new locations and reboot. You should see that "apps are being optimized". After you verify it's working, you can delete contents of original app, app-lib and dalvik-cache to free up space.
shell=busybox
CARD_DEV=/dev/block/mmcblk0p19
CARD_EMUL=/storage/sdcard0
CARD_REAL=/mnt/real-sdcard0
DATA_EMUL=/data
DATA_REAL=/mnt/real-data
$shell umount $CARD_EMUL
$shell mount -o rw,remount /
for dir in $CARD_EMUL $DATA_REAL $CARD_REAL; do
if ! $shell [ -d $dir ]; then
$shell mkdir $dir
fi
done
$shell mount -o ro,remount /
$shell mount -t ext4 $CARD_DEV $CARD_REAL
for dir in app app-lib dalvik-cache; do
if ! $shell [ -d $CARD_REAL/$dir ]; then
$shell mkdir $CARD_REAL/$dir
fi
$shell mount -o bind $CARD_REAL/$dir $DATA_EMUL/$dir
done
$shell mount -o bind $DATA_EMUL $DATA_REAL
if ! $shell [ -d $CARD_REAL/sdcard ]; then
$shell mkdir $CARD_REAL/sdcard
fi
sdcard $CARD_REAL/sdcard $CARD_EMUL 1023 1023 &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment