74

I have successfully rooted my Samsung Galaxy Mini (android 2.2.1) and thought, that I could change anything (as root usually can).

I would like to change the hosts file on the android, to include some local addresses. However, I still get the message that I do not have permission to do that. I tried following options:

  1. adb push /path/to/my/new/hosts /system/etc ... and I got the response Read-only file system.

  2. directly in the shell on the phone. But this didn't work either. I can do su in the console, but cannot change the file.

Isn't it strange, that as super user I am not allowed to change some files?

4 Answers 4

66

You have root, but you still need to remount /system to be read/write

$ adb shell
$ su
$ mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system

Go here for more information: Mount a filesystem read-write.

10
  • 3
    Can't adb do this directly? The usage shows: adb remount - remounts the /system partition on the device read-write
    – gsgx
    Commented Dec 29, 2012 at 19:19
  • 1
    If you have root, you can find out the /system path and the fs type with: adb shell su -c cat /proc/mounts
    – greg7gkb
    Commented Mar 13, 2013 at 23:38
  • 2
    @gsingh2011: adb remount gives me the error remount failed: Operation not permitted and adb root gives the error adbd cannot run as root in production builds on my unlocked Nexus 4. If you know how to get adb remount to work, I'd love to hear it. Commented Apr 17, 2013 at 21:55
  • 4
    @ClaytonHughes I know this is old, but for future thread-goers, adb root && adb remount works for me just fine on CM10.2 on the Nexus 7 (2013).
    – Brandon
    Commented Nov 17, 2013 at 4:49
  • 2
    It still doesn't work for me, even with remount and root.
    – JohnyTex
    Commented Oct 28, 2014 at 14:12
45
adb shell
su
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system

This assumes your /system is yaffs2 and that it's at /dev/block/mtdblock3 the easier/better way to do this on most Android phones is:

adb shell
su
mount -o remount,rw /system

Done. This just says remount /system read-write, you don't have to specify filesystem or mount location.

4
  • On my device (Milestone 3 with 2.6.35.7-g9f70789) "device" is a required parameter for mount. I was able to leave out -t yaffs2 though. Commented May 22, 2012 at 2:20
  • 7
    mount -o remount,rw /system worked for me; the other command, mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system resulted in: mount: Permission denied.
    – KajMagnus
    Commented Jan 5, 2014 at 6:47
  • Note that I need to do mount -o rw,remount /system in Nexus 5X (remount,rw will get "Device or resource busy" error.)
    – 林果皞
    Commented Nov 21, 2017 at 9:11
  • This works well.
    – voices
    Commented Dec 26, 2018 at 16:19
14

That didn't really work in my case - i.e. in order to overwrite hosts file you have to follow it's directions, ie:

./emulator -avd myEmulatorName -partition-size 280

and then in other term window (pushing new hosts file /tmp/hosts):

./adb remount
./adb push /tmp/hosts /system/etc
7
  • 1
    That's true, but that counts only for the emulator. I was working with a rooted phone (Samsung Galaxy Mini, although I think it does not really matter what phone it is). And on a physical device you have to remount the system partition. Commented Nov 24, 2011 at 18:00
  • you right, i tested it only on emulator. good to know, thanks.
    – dsomnus
    Commented Dec 12, 2011 at 21:25
  • 2
    Does't work with latest sdk (4.0.x) ./adb push /etc/hosts /system/etc failed to copy '/etc/hosts' to '/system/etc/hosts': Out of memory
    – Mariuz
    Commented May 31, 2012 at 9:04
  • Mariuz - thx, good to know. i did it on 2.3.
    – dsomnus
    Commented Jun 13, 2012 at 13:50
  • 2
    This is an older thread but it's worth nothing that if you don't specify "-no-snapstorage" when starting the emulator you might start the snapshot which won't have the partition size. I had the same issue until I added "-no-snapstorage"
    – Nick Bork
    Commented Jun 24, 2013 at 15:07
11

Probably the easiest way would be use this app Hosts Editor . You need to have root

2
  • 5
    Sure, but the description of the question starts with "I have successfully rooted my Samsung Galaxy Mini", so that shouldn't be a problem.
    – NiloVelez
    Commented Feb 25, 2014 at 16:26
  • 1
    From what I can tell, this app just lets you edit entries one at a time. I'd like to read in a 10MB new host file.
    – jaybro
    Commented Jan 8, 2016 at 18:46

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