[android] How can I remount my Android/system as read-write in a bash script using adb?

For info

adb remount 

returns "remount failed: Operation not permitted"

adb shell 'su -c  mount -o rw,remount /system'

returns unknown option -- o

My device is rooted.

This question is related to android bash adb mount

The answer is


Probable cause that remount fails is you are not running adb as root.

Shell Script should be as follow.

# Script to mount Android Device as read/write.
# List the Devices.
adb devices;

# Run adb as root (Needs root access).
adb root;

# Since you're running as root su is not required
adb shell mount -o rw,remount /;

If this fails, you could try the below:

# List the Devices.
adb devices;

# Run adb as root
adb root;

adb remount;
adb shell su -c "mount -o rw,remount /";

To find which user you are:

$ adb shell whoami

In addition to all the other answers you received, I want to explain the unknown option -- o error: Your command was

$ adb shell 'su -c  mount -o rw,remount /system'

which calls su through adb. You properly quoted the whole su command in order to pass it as one argument to adb shell. However, su -c <cmd> also needs you to quote the command with arguments it shall pass to the shell's -c option. (YMMV depending on su variants.) Therefore, you might want to try

$ adb shell 'su -c "mount -o rw,remount /system"'

(and potentially add the actual device listed in the output of mount | grep system before the /system arg – see the other answers.)


I had the same problem and could not mount system as read/write. It would return

Usage: mount [-r] [-w] [-o options] [-t type] device directory

Or

operation not permitted. Access denied

Now this works on all rooted devices.

DO THE FOLLOWING IN TERMINAL EMULATOR OR IN ADB SHELL

$ su
#mount - o rw,remount -t yaffs2 /system

Yaffs2 is the type of system partition. Replace it by the type of your system partition as obtained from executing the following

#cat /proc/mounts

Then check where /system is appearing from the lengthy result

Extract of mine was like

mode=755,gid=1000 0 0
tmpfs /mnt/obb tmpfs rw,relatime,mode=755,gid=1000 0 0
none /dev/cpuctl cgroup rw,relatime,cpu 0 0/dev/block/platform/msm_sdcc.3/by-num/p10 /system ext4 ro,relatime,data=ordered 0 0
/dev/block/platform/msm_sdcc.3/by-num/p11 /cache ext4 rw,nosuid,nodev,relatime,data=ordered 0 0

So my system is ext4. And my command was

$ su
#mount  -o  rw,remount  -t  ext4  /system 

Done.


I could not get the mount command to work without specifying the dev block to mount as /system

#cat /proc/mounts returns ( only the system line here )
/dev/stl12 /system rfs ro,relatime,vfat,log_off,check=no,gid/uid/rwx,iocharset=utf8 0 0

so my working command is
mount -o rw,remount -t rfs /dev/stl12 /system


mount -o rw,remount $(mount | grep /dev/root | awk '{print $3}')

this does the job for me, and should work for any android version.


Get "adbd insecure" from google play store, it helps give write access to custom roms that have it secured my the manufacturers.


The following may help (study the impacts of disable-verity first):

adb root
adb disable-verity
adb reboot

Otherwise... if

getenforce

returns

Enforcing

Then maybe you should call

setenforce 0 
mount -o rw,remount /system 
setenforce 1

Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to bash

Comparing a variable with a string python not working when redirecting from bash script Zipping a file in bash fails How do I prevent Conda from activating the base environment by default? Get first line of a shell command's output Fixing a systemd service 203/EXEC failure (no such file or directory) /bin/sh: apt-get: not found VSCode Change Default Terminal Run bash command on jenkins pipeline How to check if the docker engine and a docker container are running? How to switch Python versions in Terminal?

Examples related to adb

ADB server version (36) doesn't match this client (39) {Not using Genymotion} ADB device list is empty "unable to locate adb" using Android Studio Run react-native on android emulator Solving "adb server version doesn't match this client" error Adb install failure: INSTALL_CANCELED_BY_USER Session 'app': Error Installing APK Where is adb.exe in windows 10 located? How to debug in Android Studio using adb over WiFi Set adb vendor keys

Examples related to mount

VMware Workstation and Device/Credential Guard are not compatible How can I remount my Android/system as read-write in a bash script using adb? How to mount host volumes into docker containers in Dockerfile during build Transport endpoint is not connected Permission denied on accessing host directory in Docker How to mount a host directory in a Docker container Check if directory mounted with bash A terminal command for a rooted Android to remount /System as read/write Manually put files to Android emulator SD card Linux: Which process is causing "device busy" when doing umount?