hstroph
Android Expert
My goal is to replace /system/etc/hosts file with one that includes my own network hosts, but /system is read-only, and I can't seem to change the permissions on it using adb. All operations are performed as the root (Linux) user.
Here's how one accomplishes the task, assuming "busybox" and "super-su" are installed on the Nexus 4. On the Linux:
# ps auxw | grep adb
root 6518 0.0 0.0 29980 1376 pts/0 Sl 18:53 0:01 adb -P 5037 fork-server server
# adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
004323648951e5d9 device
# adb push hosts /system/etc/hosts
failed to copy 'hosts' to '/system/etc/hosts': Read-only file system
# adb help 2>&1 | grep remount
adb remount - remounts the /system partition on the device read-write
# adb remount
remount failed: Permission denied
So I remount the /system partition in rw mode from an adb shell and test it:
# adb shell
shell@mako:/ $ su
root@mako:/ # mount -o remount,rw /system
root@mako:/ # cp /system/etc/hosts /system/etc/hosts.ORG
root@mako:/ # exit
shell@mako:/ $ exit
Then the file pushes successfully:
# adb push hosts /system/etc/hosts
4017 KB/s (1092858 bytes in 0.265s)
... and /system is restored to original ro mode:
# adb shell
shell@mako:/ $ su
root@mako:/ # mount -o remount,ro /system
root@mako:/ # exit
shell@mako:/ $ exit
Mission accomplished, in case anyone else needs to know.
Here's how one accomplishes the task, assuming "busybox" and "super-su" are installed on the Nexus 4. On the Linux:
# ps auxw | grep adb
root 6518 0.0 0.0 29980 1376 pts/0 Sl 18:53 0:01 adb -P 5037 fork-server server
# adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
004323648951e5d9 device
# adb push hosts /system/etc/hosts
failed to copy 'hosts' to '/system/etc/hosts': Read-only file system
# adb help 2>&1 | grep remount
adb remount - remounts the /system partition on the device read-write
# adb remount
remount failed: Permission denied
So I remount the /system partition in rw mode from an adb shell and test it:
# adb shell
shell@mako:/ $ su
root@mako:/ # mount -o remount,rw /system
root@mako:/ # cp /system/etc/hosts /system/etc/hosts.ORG
root@mako:/ # exit
shell@mako:/ $ exit
Then the file pushes successfully:
# adb push hosts /system/etc/hosts
4017 KB/s (1092858 bytes in 0.265s)
... and /system is restored to original ro mode:
# adb shell
shell@mako:/ $ su
root@mako:/ # mount -o remount,ro /system
root@mako:/ # exit
shell@mako:/ $ exit
Mission accomplished, in case anyone else needs to know.