Accessing root files (/system, /dev) from a native library in Android application

I have an NATIVE LIBRARY which will try to create files in the /system, /dev folders in an android device (using open(), fopen() etc).

Now i have integrated the library with an android application using JNI & NDK. But the creation of the files in the root folders are failing. I have tried to create a file in the sdcard from the native library and this works fine.

Neither I want to move the file opening code to Android code (Java code) nor I want to create the files in the sdcard. I have clear requirements to create the files in root folder itself.


In recent android versions, rootfs and system are mounted read-only after init has set up the directories and files.

In order to create a file in the system partition you must remount them with write access. So you will have to call on /system/bin/mount as root user.

The command for mounting system rw is different depending on if /system/bin/mount a toybox or toolbox symlink

If you're failing to get su in with Runtime.getRuntime().exec("su"), are you using the su binary produced by aosp in userdebug builds? If so I believe you would have to be shell user in order to use it. Maybe switch to a more commonly available su binary or update the aosp one.

EDIT: for mounting system rw, you first need to determine if /system/bin/mount is a symlink to toybox or to toolbox, because the command they use for mounting system rw will be different

ls -l, or readlink should be able to easily answer that.

for toolbox,

(running as uid(0))

mount -o remount,rw /system

for toybox,

(running as uid(0))

mount -o rw,remount -t auto /system

In Java the subprocess must request su first as only root user can execute the mount command


  • Failed when trying to create AVD is Android SDK
  • Save XML file on Android device and read it
  • How to screen record iOS-real device with command?
  • Android emulator sd card image already in use
  • Access 2007 forms with parameterized RecordSource
  • Opening links in a new tab and only the new tab
  • UML diagram generator in Visual Studio 2010
  • XBee Linux Serial Port on Rasberry Pi
  • Opening two instances of InAppBrowser (_system and _blank) prevents events from triggering
  • What is this strange character in chrome's resource css viewer?
  • Is there any way to call saveCurrentTurnWithMatchData without sending a push notification?
  • Embedded Glassfish JPA Datasource connection fail
  • Angular2 - Template reference inside NgSwitch
  • Assign variable to the value in HTML
  • How to use carriage return with multiple line?
  • Custom Tabgroup Appcelerator
  • Disable Enter in editText android
  • why do I get the error when installing the gem 'pg'? [duplicate]
  • Cannot resolve symbol 'MyApi'
  • How to rebase a series of branches?
  • If I include Java 8 in my Android app does that affect which devices it will work on?
  • Jenkins: How To Build multiple projects from a TFS repository?
  • Sony Xperia Z Tablet not found by adb
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Cross-Platform Protobuf Serialization
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • ILMerge & Keep Assembly Name
  • Perl system calls when running as another user using sudo
  • Release, debug version and Authorization Google?
  • Large data - storage and query
  • How can I estimate amount of memory left with calling System.gc()?
  • WOWZA + RTMP + HTML5 Playback?
  • How to format a variable of double type
  • Acquiring multiple attributes from .xml file in c#
  • Hits per day in Google Big Query
  • coudnt use logback because of log4j
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • JaxB to read class hierarchy
  • java string with new operator and a literal