How to bind-mount "data" and "obb" folders from external SD card in "/sdcard/Android"?


Sub-directories in /sdcard/Android/data or /sdcard/Android/obb (called apps' private directories on primary external storage) have synthesized permissions based on directory structure. While public directories on the rest of the /sdcard have fixed permissions. See details in Android's Storage Journey and What is /storage/emulated/0/?.

My answer to your linked question: How to bind mount a folder inside /sdcard with correct permissions? addresses the latter case i.e. bind mounting public directories which are shared with all apps. But private directories cannot be bind-mounted from external storage with fixed permissions. However using the same approach you can bind-mount every app's private directory separately.

Let's take example of Termux app. Its private directories (Android/data/com.termux and Android/obb/com.termux) are owned by the UID of Termux app assigned at the time of installation. Common ways to get UID value is to read from /data/system/packages.list or do ls -ld /sdcard/Android/data/com.termux or using stat command. A simple approach is to bind-mount the directory as world-writable so that every app can write to it. But it's not a good idea to set such open permissions. So we go the Android's way; bind-mount a directory from external SD card using FUSE:

~# bindfs -u $(stat -c %u /sdcard/Android/data/com.termux) -g 9997 -p a-rwx,ug+rw,ug+X /mnt/media_rw/[UUID]/Android/data/com.termux /mnt/runtime/write/emulated/0/Android/data/com.termux

  • For further mount options and details see the above linked answer.

  • Replace /mnt/media_rw/[UUID] with /mnt/expand/[UUID]/media/0 if SD card is formatted as Adoptable Storage but data is not migrated.

  • In the same way obb directories can be bind-mounted.

  • If your device supports sdcardfs, the same mount should propagate to default and read emulated VIEWS as well. Otherwise if your device is older you can bind-mount the same way to other VIEWS.

  • Some apps by default prefer writing private data to secondary external storage (i.e. external SD card), so you don't need to bind-mount their data or obb directories.


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