Android - How to mount /system rewritable or read-only? (RW/RO)
There are a few methods how you can mount your /system
directory RW or RO. However, it will require root.
Method 1:
Connect your phone to the computer. (Make sure USB debugging is enabled on your phone)
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.
Type this:
adb shell
su
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
- Mount system RW:
Method 2:
Open
terminal
on your android phone (download here):Type this in the
terminal
:su
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
- Mount system RW:
Android 2.3
For people running Android 2.3 and the command fails, look at this answer: https://android.stackexchange.com/a/125437/95577
-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 ofsystem-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