What is rootfs? Can I make persistent changes to my device's root filesystem? When I open up a terminal emulator and run the mount command, it indicates that my Android device's root filesystem (/) is of filesystem type rootfs. What is rootfs? Can I write to it? Will my changes persist even after I shut the device down?



Note: If you're an Android ROM developer who wants to add files to your ROM's rootfs, please see the relevant Unix.SE question instead.
What is rootfs?

It's an initramfs. Basically, it's a prepopulated RAM drive. It's prepopulated with some content at boot time, usually from a cpio archive which has been compiled into the kernel.

Can I write to it?


One way to make changes to your rootfs is to unpack the cpio archive, make your changes, and repack the archive.  Your device will almost surely have to be rooted before you can do this.  As well, you'll need the necessary tools.
Alternatively, you can make changes to the rootfs copy which is loaded into RAM; but, if you do so, there are four gotchas.


You must root your device first.
Then, you must remount the filesystem as read-write.
Don't write too much to the rootfs; if you do, you'll take up too much RAM and your device will slow down.
The biggest gotcha is that the files you create will disappear when you shut down or reboot. Please keep on reading.



Will my changes persist even after I shut the device down?

No. If you create or modify files in rootfs, your changes will be undone when you shut down or reboot.

What should I do instead of writing to the root filesystem?

Store your files somewhere under /storage or /data or /system instead. You can choose any of the three. Somewhere under /storage is probably best, since that's the most common choice.

Why doesn't my device act like a normal Linux device and mount a normal disk-backed filesystem to /?

I don't know.

I suspect that the answer is as follows:  Android isn't a full Linux distribution.  It doesn't include a full glibc, it's probably not fully LSB-compliant, and it doesn't feel obligated to provide the niceties that most Linux distributions provide (e.g. a disk-backed root filesystem).

Elsewhere, Gilles writes:


  Most desktop Linux systems have a small initramfs which contains just enough programs and configuration files to mount the real root filesystem, which is then mounted on /, replacing the initramfs. Android, like some embedded Linux systems, keeps the initramfs mounted forever. Android's initramfs contains only /init, adbd and a few configuration files.




References:


http://forum.xda-developers.com/showthread.php?t=1004478
https://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt by Rob Landley
https://unix.stackexchange.com/questions/122787/how-to-add-folders-and-file-before-compiling-kernel#122840
And others.