72

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?

franzlorenzon
  • 5,333
  • 6
  • 31
  • 55
Filip Majernik
  • 7,350
  • 13
  • 39
  • 51

4 Answers4

64

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.

franzlorenzon
  • 5,333
  • 6
  • 31
  • 55
Leif Andersen
  • 19,065
  • 16
  • 62
  • 92
  • 3
    Can't adb do this directly? The usage shows: `adb remount - remounts the /system partition on the device read-write` – gsingh2011 Dec 29 '12 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 Mar 13 '13 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. – Clayton Hughes Apr 17 '13 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 Nov 17 '13 at 04:49
  • On my Samsung Galaxy Core with Android 4.1.2 'su: not found'. Any ideas? – barbaris May 03 '14 at 11:25
  • 1
    Thanks for the reminder @naXa. But to make it read-only again, use `mount -o ro,remount /system`. – Tyler Collier Aug 16 '14 at 21:58
  • @TylerCollier Of course... silly copy-paste error in a comment.) When done, do not forget to remount partition read-only again, for safety reasons. The correct command is `mount -o ro,remount /system` – naXa Aug 22 '14 at 08:15
  • 2
    It still doesn't work for me, even with remount and root. – JohnyTex Oct 28 '14 at 14:12
  • Not work for me, is there any further fix? – Nguyen Minh Binh May 12 '16 at 17:04
  • @Tyler thanks for the reminder. A perfect answer might include this information. – voices Dec 26 '18 at 16:22
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.

voices
  • 323
  • 4
  • 16
Paul
  • 451
  • 4
  • 3
  • 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. – Simon Woodside May 22 '12 at 02: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 Jan 05 '14 at 06:47
  • Note that I need to do `mount -o rw,remount /system` in Nexus 5X (`remount,rw` will get "Device or resource busy" error.) – Fruit Nov 21 '17 at 09:11
  • This works well. – voices Dec 26 '18 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
dsomnus
  • 1,312
  • 14
  • 21
  • 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. – Filip Majernik Nov 24 '11 at 18:00
  • you right, i tested it only on emulator. good to know, thanks. – dsomnus Dec 12 '11 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 May 31 '12 at 09:04
  • Mariuz - thx, good to know. i did it on 2.3. – dsomnus Jun 13 '12 at 13:50
  • @Mariuz, what -partition-size value did you use? It worked for me on the 4.0.4 emulator if I use a value greater than 215 (which I believe is the size of system.img for the AVD). – Joe Aug 29 '12 at 21:10
  • It works for me fine! API level 15 – Ashraf Sayied-Ahmad Sep 09 '12 at 20:31
  • 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 Jun 24 '13 at 15:07
11

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

byroncorrales
  • 745
  • 6
  • 12
  • 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 Feb 25 '14 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 Jan 08 '16 at 18:46