3

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.

4

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.

    1. You must root your device first.

    2. Then, you must remount the filesystem as read-write.

    3. Don't write too much to the rootfs; if you do, you'll take up too much RAM and your device will slow down.

    4. 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:

  • Does only shutdown clears the content? Does reboot clear it too? – Calmarius Feb 1 '17 at 19:53
  • Rebooting clears it too. I've now edited the answer to say so. – unforgettableidSupportsMonica Sep 28 '17 at 0:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.