5

I'm trying to write an app that copies something to the /system partition at run time. I've already implemented the ability to run terminal commands as root by requesting SU permissions. I can run a lot of commands successfully (after granting the permission request with SuperUser). However, when I try to remount /system as read/write, nothing happens. I don't get an error or a crash, and the command seems to go through just fine, but the partition stays as read-only. Here's the command I'm running (Droid X): mount -o rw,remount -t ext3 /dev/block/mmcblk1p21 /system, and it works just fine if I run the same command from Terminal. And here's my code to execute root commands from within my app:

String cmd = "mount -o rw,remount -t ext3 /dev/block/mmcblk1p21 /system";
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes(cmd + "\n");          
os.writeBytes("exit\n");  
os.flush();

And then I have some code that checks the stdout and stderr streamd to see what happened. Can anyone give me an idea why this doesn't work?

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
user496854
  • 6,461
  • 10
  • 47
  • 84

1 Answers1

6

I figured it out -- the command was actually successful, but it appears that the RW status only applies to the session in which it was applied. So that after one set of commands was executed under SU, the next set of commands gets the /system in RO state. All I had to do was add the command to copy the files before exiting the SU session.

user496854
  • 6,461
  • 10
  • 47
  • 84
  • Just fyi if you've answered your own question to your satisfaction it is okay to accept your own response. – powerj1984 Sep 21 '11 at 00:00
  • It's rather unlikely the filesystem would be immediately be being remounted read-only - generally it stays writable until you remount it or reboot. However, the lack of stickiness of escalating to the superuser often is an issue which people trying to do this stumble over. You almost certainly need to be superuser both to remount /system, and to change anything on it once it is writable. – Chris Stratton May 05 '12 at 05:19
  • The filesystem RW status in general sticks around, but as far as actually being able to perform any file operations from withing the APK, it definitely doesn't work like that. All the file operations have to be done in the same process as the RW command, otherwise it won't work. – user496854 May 07 '12 at 08:25