Android - Is it possible to create a RAMDisk / Ramdrive for Android 4.x?

If you do a cat /proc/filesystems you should notice tmpfs. So if you have access to the mount command, you shoud be able to

  1. create a directory (mkdir MYDIRECTORY)
  2. mount a tmpfs-filesystem there (mount -t tmpfs tmpfs MYDIRECTROY)

Per default a tmpfs-mount will use halv of the available RAM on your system. So rather than "auto-growing" you can think of it as "auto-shrinking" - i.e. the more you use it, the less RAM will be available. In the worst case your system might start swapping (which you do not want). You can use options to use a different RAM-size for that mount.

2017-02-28 Update: Due to the restrictions imposed by Android you should choose a mount point below an writeable to all Apps. Like an SD Card.

From the linky the OP has enclosed, the key part summed it up:

tmpfs is supported by the Linux kernel from version 2.4 and up.[3] tmpfs (previously known as shmfs) is based on the ramfs code used during bootup

Emphasis mine, that is what the RAMDisk is about! It enables the kernel to temporarily mount the root filesystem, and continue executing the necessary scripts upon start-up.

Same applies in this case of Android, each and every boot.img that is flashed to the /boot partition, whether by Odin, fastboot, Kies, Sony Update Software, Heimdall, etc, contains the "ramfs code", which has a directory structure containing, pertinent ones are included:

  • /dev for device files
  • /sbin for system binaries
  • /sys for usage of interacting with the device files after /proc has mounted

The boot-up script reads the ramfs directory structure and mounts it after successfully mounting the /system in the very early stage of boot.

As in relation to the OP's keyword in the question:

create an auto-growing ...

It does not auto-grow per se, rather, its limited by the ramfs structure, and amount of RAM available, and more importantly, it disappears on reboot!

The confusion comes from inter-mixing "RAMDisk" with "RAMDrive" interchangeably, technically a RAMDrive, is a swap space in the native swap partition, commonly found on desktop Linux If you're thinking of the old DOS era, where RAMDrive was used, to simulate a disk drive resident in memory, and programs when copied over to that disk, and loaded faster not execute faster, rather than loading from the old MFM/RLL disk-drives (Ever see DOS directory listing scroll very slowly on those drives?) this, was also known as RAMDisk as well! (To make matters worse, back then, different manufacturers produced RAMDRIVE.SYS or even RAMDISK.SYS!)

In the case of viewpoint of the Linux kernel, both desktop and Android, RAMDisk is tmpfs, but is not intended for normal users to store data/documents etc as that is exclusively for the usage by the kernel itself!


To note @nil's comment below, you can mount it yes, but it comes with a cost, resources allocated to the tmpfs gets halved and uses up half of remaining of whatever amount of RAM left. Realistically speaking, it is not an ideal avenue to persue from the viewpoint of Android running on devices.

That is where the /sdcard comes in, to store user data/documents for that reason alone, hence why I omitted the fact that you can, but then again, why?

  • What if the end user forgets to save the data to the right place - because that is lost upon reboot!