2
votes

I've written an app that modifies file system contents. One of the requirements to do this is mounting the system as read-write. From here and other sources, I've found the widely accepted command is this:

 mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system

I'm hoping someone can better explain how this works. I understood it to mean that we're working with a yaffs2 file system and going to mount the directory /dev/block/mtdblock3 as /system. When I issue the mount command on my phone though, /system is listed as ext3, not yaffs2 (if I substitute ext3 for yaffs2 the command works equally well). Also, /dev/block/mtdblock3 is not an existing directory.

This may be more of a Linux question than Android, but I'm sure someone knows all about this. Most importantly, how universal is this command? I'm planning on releasing this to a huge variety of devices, do I need to accomodate other file systems? Or will this "just work"?

3
I think as soon as you want to make /system read-write (or for that matter mess with filesystems at all), all bets are off. - geekosaur
geekosaur is right. On a device like the HTC Desire which arrives S-OFF, it's not possible to write to the system partition unless you're in recovery mode. - David Snabel-Caunt
I understood S-OFF to allow writing and S-ON to restrict it. But I also thought S-ON wouldn't allow root access, so it would die before it even got that far. - jarvisteve

3 Answers

1
votes

I use this in one of my apps to make it as universal as possible. Of course it needs a rooted phone in order to work.

FileInputStream inputStream;
BufferedReader r;
String line, device = "", fs = "";

try {
   inputStream = new FileInputStream("/proc/mounts");
} catch (FileNotFoundException e) {
   Log.e("Could not read mounts");     
   return;
}

r = new BufferedReader(new InputStreamReader(inputStream)); 

//find device mounted as system and file system type
try {
   while ((line = r.readLine()) != null) {
       if(line.indexOf("/system") >= 0) {
           String mount[] = line.split(" ");
           device = mount[0];
           fs = mount[2];
           break;
       }
   }
   inputStream.close();
} catch (IOException e) {
   Log.e("Could not read mounts");     
   return;
}       

//mount system as rw
CommandCapture command = new CommandCapture(0, "mount -o rw,remount -t " + fs + " " + device + " /system");
try {
    RootTools.getShell(true).add(command).waitForFinish();
} catch (Exception e) {
    Log.e("Couldn't mount system as rw!");    
    return;
}

It uses RootTools for convenience on shell commands and assumes the user already granted root access to your app.

0
votes

The location of the device corresponding to the /system partition is device-specific, as is the filesystem in use; there is no single standard command. Moreover, there is no guarantee that the filesystem will be mutable at all; it's perfectly possible for the root fs to be on cramfs, or on some type of flash that's not easily randomly overwritten. For some phones it may be enough to check /proc/mounts for the actual device and fs-type corresponding to /system; for others you may not be able to remount it read-write.

0
votes

Try this:

grep " /system " /proc/mounts | awk '{system("mount -o rw,remount -t "$3" "$1" "$2)}'

Remember your android device must be rooted and busybox must be installed.

Chat again