Guide for proper Android KitKat ramfs setup

I received quite a few complaints from users of FolderMount running custom kernels and ROMs on Android KK that it was not working or was not able to find the obb path so I'm going to discuss some of the most common errors and mistakes that I have seen in some of the kernels' ramfs. The intended audience of this document are kernel devs and ROM chefs.

1. /system/bin/sdcard daemon

Your ramfs must include a service entry for each sdcard that is being emulated in the device. Note that all sdcards (internal and external) are being 'emulated' in Android KitKat by the fuse daemon.

1.1. Internal sdcard (if your internal content is located in /data/media:

service sdcard /system/bin/sdcard -u 1023 -g 1023 -l /data/media /mnt/shell/emulated
    class late_start


The flags that we are specifying here are important. This is especially true for the -l flag as this legacy flag means that obb content will be shared among users (in a multi-user Android environment) in /data/media/obb instead of being separated into different /data/media/< user_id >/Android/obb paths where there is a risk of having the data being duplicated if two users chose to download the same obb game/data.

1.2 External sdcard(s) and OTG devices

For all other devices, a service declaration as following will suffice:

service fuse_sdcard1 /system/bin/sdcard -u 1023 -g 1023 -d /mnt/media_rw/sdcard1 /storage/sdcard1
    class late_start
    disabled


The name of the service start with the word fuse, followed by an underscore, followed by the name of the storage device. In this case, it is sdcard1. This will guarantee that the mmc gets mounted in /mnt/media_rw/sdcard1 and the fuse daemon exposes the storage device to all users in /storage/sdcard1. The latter path is where users will read/write data from and not from /mnt/media_rw/sdcard1.

2. Environment variables

A lot of folks miss the declaration of an important variable called SECONDARY_STORAGE. This environment variable is now required given that some Android KK APIs use this variable to retrieve local storage information. See for example:
HERE. Line 164
HERE. Line 1342
A simple line in your ramfs that looks like this should be all you need:

export SECONDARY_STORAGE /storage/sdcard1

After exporting the appropriate environment variable and declaring the correct fuse daemon services, FolderMount (and other apps?) should hopefully work as expected.