• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Root modify /system/etc/hosts ? [solved]

hstroph

Android Enthusiast
Oct 18, 2012
743
147
From a Linux laptop using the most recent Android SDK, I am trying to push a modified /system/etc/hosts file to the rooted, "SuperSU"-enabled N4, but am meeting with permission problems:

$ ps auxw | grep adb
root 10924 0.1 0.0 29188 1428 pts/0 Sl 11:29 0:00 adb fork-server server
$ adb -d push hosts.mod /system/etc/hosts
failed to copy 'hosts.mod' to '/system/etc/hosts': Read-only file system
$ adb -d shell
shell@android:/ $ ls -l -d / /system /system/etc /system/etc/hosts
drwxr-xr-x root root 2013-07-02 23:20
drwxr-xr-x root root 2013-05-21 12:48 system
drwxr-xr-x root root 2013-02-15 12:13 etc
-rw-r--r-- root root 1025804 2013-01-21 22:34 hosts

The intent is to temporarily grant "others" write permission to the hosts file, but that also meets with the problem, even for root:

shell@android:/ $ su -
root@android:/ # chmod 0326 /system/etc/hosts
Unable to chmod /system/etc/hosts: Read-only file system

How can I modify the /system/etc/hosts file please? The new hosts file is too large to use an in-phone app to manually edit the existing file; I need to "adb push" it.

What's missing please?

[solution]
As usual, the messages are telling us exactly what's happening. The filesystem needs to be remount rw to push the file:

Android:
root@android:/ # mount | grep system
/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 ro,relatime,data=ordered 0 0
root@android:/ # mount -o rw,remount /dev/block/platform/msm_sdcc.1/by-name/system /system
root@android:/ # chmod 0326 /system/etc/hosts
root@android:/ #

Linux:
$ adb -d push hosts.mod /system/etc/hosts
562 KB/s (1026030 bytes in 1.779s)
$

Restore Android:
root@android:/ # chmod 0644 /system/etc/hosts
root@android:/ # ls -l /system/etc/hosts
-rw-r--r-- root root 1026030 2013-07-03 12:27 hosts
root@android:/ # mount -o ro,remount /dev/block/platform/msm_sdcc.1/by-name/system /system
root@android:/ #

[/solution]
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones