What is rootfs? Can I make persistent changes to my device's root filesystem?


Question

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.


Answer

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:




Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes