External SD card with ext4 under Android (CM10.1) 04. July 2013
I just bought a new SD card (32 GB) because my old one died with thousands of erroneous blocks. And because this is the single biggest external storage available to me (apart from external hard drives with multiple TB), I want to be able to use this storage to transport large files – like for example HD movies. But with the default FAT32 filesystem, this is impossible: It imposes a 4 GB file size limit, which you easily reach even with DVD quality.
Now googling for nearly an hour for „ext4“ (a much better filesystem, the default one in Linux) and „Android“ didn’t yield anything really useful. The problem: ext4 supports proper permission management as opposed to FAT32, which simply allows anybody to do anything. But this is something that Android has a problem with: Every app runs as its own user and thus a file created by app A can most probably not be read by app B when you store it on ext4.
Note: In CyanogenMod 11, ext4 formatted SD cards work out of the box.
Now really all you need to make this work is already there – at least in CyanogenMod 10.1. I put the following little script in
/data/local/userinit.sh (which is executed by CyanogenMod on startup – if it exists, which it doesn’t by default), which mounts the external SD card to a temporary mountpoint and uses the standard Android binary
sdcard to create a world-read-writeable view of this filesystem in
/storage/sdcard1 (the place where CyanogenMod 10.1 mounts the external SD card by default):
So, in contrast to what hundreds of Google results suggested, it is quite simple to use ext4 on an external SD card without the permission hassle – if you know how and have an up-to-date Android. Just wanted to drop these few lines here, hoping someone can use it. Obviously, you need root on you phone to do this, but if you have CM, you already rooted it, so wayne.
As response to some comment:
tl;dr: I don’t really care if ext is bad for flash. I didn’t try apps on the card yet, will try if I find the time. Avoid NTFS.
Long version: I don’t use the SD card for heavy I/O, so I don’t really care about ext4 being bad for flash media. I keep some crypto keys on the SD card (because I want to be able to physically remove them at any time – sadly, app developers don’t think of this attitude and mostly import/copy them to the app folder) and maybe want to store a movie on it for along train ride – that’s why I wanted to avoid the 4 GB limitation of FAT. When searching for the topic for earlier attempts, I found people saying “modern flash is smart enough to distribute writes in hardware, no need for a special file system”, but I don’t really know if this applies to microSD cards which are admittedly quite minimalistic. Maybe the reader contains this logic, or maybe ext really is bad for such media, I don’t know. If my card breaks – well, bad luck, I’ll buy another one.
I have plenty of space on my internal memory, so I don’t use the external SD card for apps and thus I don’t have any problems with freezes up to know. I will try it when I find the time, but I’m not sure my solution offers any advantage over a normal FAT system in that regard: The file permissions are all gone and the app2sd stuff probably isn’t smart enough to use the original mount with ext4 in favor of the FUSE mount without permissions.
Finally, regarding NTFS: I would never, ever recommend anyone to seriously use NTFS on any non-Microsoft OS. ntfs-3g nowadays is stable enough to not corrupt the filesystem and can safely read and write, but its performance is a pain in the ass. Even on a smartphone I’m sure you’d notice the difference when downloading a file via 802.11n. Or, maybe especially on a smartphone, because ntfs-3g requires lots of context switches thanks to its FUSE nature, and thus requires quite a bit of computing power – which smartphones usually don’t have to spare.
I don’t use CyanogenMod anymore (sadly, my new phone isn’t supported) and thus don’t use this script anymore. There were various reports of it working or not working, apparently it strictly depends on the precise version and system configuration.
As I cannot help any further with any issues, here are some links that might help: