55

How can I mount the /system directory rewritable or read-only on my Android phone?

63

There are a few methods how you can mount your /system directory RW or RO. However, it will require root.

Method 1:

  1. Connect your phone to the computer. (Make sure USB debugging is enabled on your phone)

  2. Open CMD/Terminal on your PC.

    • Windows: CTRL + R, then type cmd.

    • Ubuntu: CTRL + ALT + T.

    • Mac: Navigate to /Applications/Utilities/ and double-click on Terminal.

  3. Type this:

    1. adb shell
    2. su

    3. Choose one: (for security mount /system back to RO when finished)

      • Mount system RW: mount -o rw,remount /system
      • Mount system RO: mount -o ro,remount /system

Method 2:

  1. Open terminal on your android phone (download here):
  2. Type this in the terminal:

    1. su

    2. Choose one: (for security mount /system back to RO when finished)

      • Mount system RW: mount -o rw,remount /system
      • Mount system RO: mount -o ro,remount /system

Method 3:

If you don't want to type the command every time in the terminal, I've written an app designed to do this for you:


Android 2.3

For people running Android 2.3 and the command fails, look at this answer: https://android.stackexchange.com/a/125437/95577

  • 4
    It seems this (method 1) does not work on newer Android any more. I am trying to do it on Android emulator running Android 6, but always get an error "mount: Read-only file system". I've run adb root, but it makes no difference. Any idea on what could be done? – diidu Sep 12 '16 at 12:07
  • 1
    I got it, kind of. I have to use -writable-system command line option when starting the emulator. Then the first adb remount seems to succeed. Seems ... I have not seen it change to rw yet. – diidu Sep 12 '16 at 12:47
  • emulator -writable is still the correct answer. – Edgar Aroutiounian Sep 6 '17 at 3:49
  • "For people running Android 2.3" -- that phrasing doesn't communicate very well. I am guessing you mean >=2.3 or <=2.3 (or, less likely, exactly 2.3 if there's a particular bug in 2.3 only) but we don't know which or why. – Don Hatch Dec 28 '17 at 1:32
2

-writable-system for the emulator

When launching the emulator after a build with, you must use:

. build/envsetup.sh
lunch aosp_x86_64-eng
emulator -show-kernel -verbose -writable-system

Then, for future runs, you must keep the -writable-system option, or else image changes will not be visible:

emulator -show-kernel -verbose -writable-system

-verbose shows us that the emulator switches from the default -drive:

if=none,index=0,id=system,file=/path/to/aosp/8.1.0_r60/out/target/product/generic_x86_64/system-qemu.img,read-only

to:

if=none,index=0,id=system,file=/path/to/aosp/8.1.0_r60/out/target/product/generic_x86_64/system-qemu.img.qcow2,overlap-check=none,cache=unsafe,l2-cache-size=1048576

Therefore it:

  • removes ,read-only

  • uses system-qemu.img.qcow2 instead of system-qemu.img.

    This implies that changes will only be visible afterwards if you pass -writable-sytem on future boots after the change was made!

    We can see that the qcow2 image is just a small overlay on top of the base image since:

    qemu-img info /path/to/aosp/8.1.0_r60/out/target/product/generic_x86_64/system-qemu.img.qcow2
    

    contains:

    backing file: /path/to/aosp/8.1.0_r60/out/target/product/generic_x86_64/system-qemu.img
    

The emulator -help also confirms this:

emulator -help

contains:

-writable-system     make system & vendor image writable after 'adb remount'

adb remount + adb root

I think this is just a shortcut for mount as mentioned at https://android.stackexchange.com/a/110928/126934 , but it is very convenient:

adb root
adb remount
adb shell

adb help contains:

 root                     restart adbd with root permissions
 remount
     remount /system, /vendor, and /oem partitions read-write

Restore the original system image

Same as for userdata: remove the .qcow2 overlay, and re-generate it manually: https://stackoverflow.com/questions/54446680/how-to-reset-the-userdata-image-when-building-android-aosp-and-running-it-on-the

protected by Community Feb 26 '16 at 19:40

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.