0

I'm using this code to create a file but I'm getting this error:

java.io.IOEx: open failed: EROFS (Read only file system)

The system is mounted as rw and the app has SU permissions.

File f = new File(Environment.getRootDirectory().getPath().toString(), "/etc/init.d/script");
if (!f.exists()) {
    try {
        mountSystemRW();
        f.createNewFile();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Ahmad
  • 69,608
  • 17
  • 111
  • 137
Hasta'98
  • 184
  • 2
  • 9
  • Why are you trying to do this? [If you want your app to start at boot there are better ways](http://stackoverflow.com/q/6391902/243712). – poolie Apr 26 '14 at 20:56
  • possible duplicate of [Read only file system on Android](http://stackoverflow.com/questions/6066030/read-only-file-system-on-android) – poolie Apr 26 '14 at 20:57

2 Answers2

0

The Android root filesystem is always mounted readonly because it's meant to contain only the system image.

If you have rooted your device you can run

# mount -o rw,remount /
poolie
  • 9,289
  • 1
  • 47
  • 74
  • 1
    I mount system by this, it is okay? "mount -o rw,remount /system" – Hasta'98 Apr 26 '14 at 20:53
  • Actually `/` is different to `/system`. But, again, why are you trying to do this? The root filesystem is created at startup so putting a service file there won't help much. – poolie Apr 26 '14 at 21:05
  • I wanna create scripts using an app, so I need to create a file into "/system/etc/init.d", but I can't as you can see – Hasta'98 Apr 26 '14 at 21:30
0

Regardless if the filesystem in question mounted read-only as normal, or has been changed to read-write, an application process is still never able to write to a file for which it lacks access rights.

Application code such as your java excerpt cannot run as root, period. Only helper processes can.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117