47

I'm writing an android app that needs to copy a file to the "/system" partition at runtime. I've got the commands to run "su" and can successfully request SuperUser permissions and run commands as root. But I don't know how to make this app universal across multiple devices, because the mount command can differ depending on where the /system is actually mounted. Here's the command that's used most offen:

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

But I know that mtdblock3 could be different on some devices (and for that matter, i guess so could yaffs2). So, my question is: Is there a universal command that will work on all phones? Or is there a way to find out at runtime what the correct parameters are?

user496854
  • 6,461
  • 10
  • 47
  • 84
  • 1
    None of the solutions work for Marshmallow (maybe even >=5.1.1) – Paschalis Oct 26 '15 at 13:45
  • works just fine for me under 5.1.1, but I don't have a Marshmallow device to test – user496854 Oct 26 '15 at 19:37
  • **workaround for pushing files on M**: adb push seems to fail if I push directly to /system. What I do: **1.** mount /system **2.** give permissions **3.** push to sdcard something **4.** su mv from sd to /system **5.** leave permissions as is, and system mounted because we like bad practices! – Paschalis Nov 04 '15 at 11:24
  • It works with Marshmallow (6.0) using Genymotion. mount -o remount,rw /system – sonique May 11 '16 at 05:48
  • related: https://stackoverflow.com/questions/13089694/adb-remount-permission-denied-but-able-to-access-super-user-in-shell-android – Ciro Santilli OurBigBook.com Jan 30 '19 at 16:19

9 Answers9

126

I use this command:

mount -o rw,remount /system
Oz Edri
  • 571
  • 5
  • 8
Gussoh
  • 1,261
  • 2
  • 8
  • 3
  • 7
    Doesn't work, spitting out `Usage: mount [-r] [-w] [-o options] [-t type] device directory`. Samsung Sidekick 4G. – MiffTheFox Mar 28 '13 at 01:06
  • 5
    You need to be root in order for this to work. Run `su` in your shell prior to executing this command. – user149408 Mar 25 '14 at 12:00
  • 1
    When done, I suggest to remount it read-only again, for safety reasons. `mount -o remount rw /system` – naXa stands with Ukraine Apr 24 '14 at 21:30
  • @naXa - if I remember correctly, the suggested command didn't work, but my version did... it probably depends on the OS / terminal version you're running. I should have been more clear about that. – Luke Apr 28 '14 at 20:51
  • 9
    This does not work for me. I tried: `mount -o remount,rw /system`, `mount -o rw,remount /system` and `mount -o remount,rw /dev/block/mmcblk0p23 /system`, with the two possibilities `remount,rw` and `rw,remount`. I keep getting `Read-only file system`. – Luis A. Florit Oct 25 '14 at 11:40
  • 1
    Seems like remounting as `rw` does not work in Android 5.1.1. I ended up with booting into `TeamWin TWRP` recovery, mounting `/system` from there and doing my file operations with the integrated file manager. Of course you should have TWRP installed beforehand. – Neurotransmitter Oct 02 '15 at 18:44
18

You can run the mount command without parameter in order to get partition information before constructing your mount command. Here is an example of the mount command without parameter outputed from my HTC Hero.

$ mount
mount
rootfs / rootfs ro 0 0
tmpfs /dev tmpfs rw,mode=755 0 0
devpts /dev/pts devpts rw,mode=600 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
tmpfs /sqlite_stmt_journals tmpfs rw,size=4096k 0 0
none /dev/cpuctl cgroup rw,cpu 0 0
/dev/block/mtdblock3 /system yaffs2 rw 0 0
/dev/block/mtdblock5 /data yaffs2 rw,nosuid,nodev 0 0
/dev/block/mtdblock4 /cache yaffs2 rw,nosuid,nodev 0 0
/dev/block//vold/179:1 /sdcard vfat rw,dirsync,nosuid,nodev,noexec,uid=1000,gid=
1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,s
hortname=mixed,utf8,errors=remount-ro 0 0
Bao Le
  • 16,643
  • 9
  • 65
  • 68
  • OK, that's great, thanks. One question, though -- from that output, I can find the line that has /system and parse the mount point and partition type. Is there any command that will just output that info for only /system (to avoid all the parsing)? – user496854 Mar 29 '11 at 04:46
  • 1
    Nevermind -- I got it all parsed without any issues, but there is another problem: I can run other root commands just fine from within my app, but the "mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system" command has no effect. I get no errors, and it looks like it ran successfully, but /system stays as read-only. Any ideas or suggestions? – user496854 Mar 29 '11 at 05:27
  • 1
    I think you can not run the "mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system" command with regular app permission. You should run it with root permission in order to take effect. – Bao Le Mar 29 '11 at 05:48
  • I'm running it under "su", meaning it has root permissions from the SuperUser app; – user496854 Mar 29 '11 at 13:46
  • I recommend you read this thread on how to execute a command with [http://stackoverflow.com/questions/4594071/android-how-can-execute-a-chmod-on-rooted-devides]("root" permission) – Bao Le Mar 30 '11 at 03:15
  • I've already done that, and I actually posted a follow-up question with the exact code I use: http://stackoverflow.com/questions/5481395/android-how-to-mount-filesystem-in-rw-from-within-my-apk-rooted-of-course – user496854 Mar 30 '11 at 03:27
12

Try

mount -o remount,rw /system

If no error message is printed, it works.

Or, you should do the following.

First, make sure the fs type.

mount

Issue this command to find it out.

Then

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

Note that the fs(yaffs2) and device(/dev/block/mtdblock3) are depend on your system.

accuya
  • 1,412
  • 14
  • 14
  • 2
    When done, do not forget to remount it read-only again, for safety reasons. `mount -o remount,ro /system` – naXa stands with Ukraine Apr 24 '14 at 21:25
  • This was the best solution for me. In my case, I had to expand it to specify which mount command to run. (I think there's a busybox version in xbin that is failing on my device.) `/system/bin/mount -o remount,rw /system`. I also add this line to the end my script for verification that it worked: `mount | grep yaff`. – Jon Coombs May 31 '15 at 22:26
5

Instead of

mount -o rw,remount /system/

use

mount -o rw,remount /system

mind the '/' at the end of the command. you ask why this matters? /system/ is the directory under /system while /system is the volume name.

Mobiletainment
  • 22,201
  • 9
  • 82
  • 98
Rabeeh Khoury
  • 51
  • 1
  • 1
5

You can try adb remount command also to remount /system as read write

adb remount
Rahul R Dhobi
  • 5,668
  • 1
  • 29
  • 38
4

You don't need to pass both arguments when performing a remount. You can simply pass the mount point (here /system). And /system is universal amongst Android devices.

Harry
  • 1,362
  • 12
  • 19
  • That is dead wrong. /System is totally different on different devices – user496854 Apr 22 '12 at 15:46
  • 1
    OK. I am sorry if I am wrong but you are saying that it is possible for an Android device to not have a /system directory? – Harry Apr 22 '12 at 15:56
  • No, I'm saying that on different devices, /system has different mount points. So the mount command requires both a mount point and a partition (which could be /system, /data, /ext, and a bunch of others) – user496854 Apr 22 '12 at 16:02
  • 2
    What I am saying is that by issuing the mount command with the remount option there is no need to specify the partition you want to mount it to as it will use the same partition which is currently mounted to that directory (along with all of it's parameters). – Harry Apr 22 '12 at 16:14
  • 1
    That won't work all the time. The remount command works from ADB (most of the time), but it doesn't work in terminal on a lot of devices. It depends on the Android OS version and the ROM that's loaded. – user496854 Apr 22 '12 at 17:17
  • 2
    How is executing the command via ADB or directly through the terminal any different? Surely it calls the same executable?! Thanks for the info though, I had no idea the functionality of the mount command differed depending on the Android version. – Harry Apr 22 '12 at 17:43
  • 1
    ADB has its own remount command. I didn't mean running it in ADB shell window, but the actual "adb remount" command. Either way, your solution isn't valid because it won't run on all ROMs & devices, and the correct solution has already been posted and accepted – user496854 Apr 22 '12 at 20:02
  • 1
    @user496854 are you saying `mount -o rw,remount /system` will not work on all ROMs, but `mount -o rw,remount /path/to/partition /system` will ? Sounds like you have misunderstood @Harry – Alexander Malakhov Jan 16 '14 at 08:22
2

I had the same problem. So here is the real answer: Mount the system under /proc. Here is my command:

mount -o rw,remount /proc /system

It works, and in fact is the only way I can overcome the Read-only System problem.

Jk1
  • 11,233
  • 9
  • 54
  • 64
JPNicole
  • 29
  • 1
  • Based on other answers, this doesn't seem to be the 'only way'. It may be convenient here, and the fact that it doesn't globally affect /system sounds good in this use case. In other situations, the whole point is to globally (though temporarily) RW for the sake of other scripts/apps. – Jon Coombs May 30 '15 at 22:42
2

This is what works on my first generation Droid X with Android version 2.3.4. I suspect that this will be universal. Steps:

  1. root system and install su.

  2. Install busybox

  3. Install a terminal program.

  4. to mount system rw first su then

    busybox mount -o rw,remount system
    
  5. To remount ro

    busybox mount -o ro,remount system
    

Note that there are no slashes on "system".

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
neonjohn
  • 21
  • 1
1

If you have rooted your phone, but so not have busybox, only stock toybox, here a one-liner to run as root :

mount -o rw,remount $( mount | sed '/ /system /!d' | cut -d " " -f 1 ) /system

toybox do not support the "-o remount,rw" option

if you have busybox, you can use it :

busybox mount -o remount,rw /system

FredG
  • 712
  • 7
  • 10