1. Download our Official Android App: Forums for Android!

Can't find hosts file of a rooted phone

Discussion in 'Android Rooting' started by andfo, Jan 4, 2016.

  1. andfo

    andfo Member
    Thread Starter
    Rank:
    None
    Points:
    38
    Posts:
    50
    Joined:
    May 26, 2015

    May 26, 2015
    50
    14
    38
    I am doing this in the Terminal Emulator on my phone.

    Is that what you mean by adb shell?

    "Open your command prompt in the folder containing abd" What does this mean?

    You mean I need to open cmd on my Windows PC rather than phone??

    But if I do it on PC, where should I "cd" to? I can't see the system folder of my phone on my PC, even if I connect this phone to my PC.


     

    Advertisement

  2. andfo

    andfo Member
    Thread Starter
    Rank:
    None
    Points:
    38
    Posts:
    50
    Joined:
    May 26, 2015

    May 26, 2015
    50
    14
    38
    Oh.. alright. I followed http://lifehacker.com/the-easiest-way-to-install-androids-adb-and-fastboot-to-1586992378 and I can now use adb.

    I can now do

    $ adb pull /system/etc/hosts hosts

    and

    $ adb pull /system/etc/hosts original-hosts

    But I can't do cat. It says

    "
    'cat' is not recognized as an internal or external command,
    operable program or batch file.
    "

    Also, when I do

    C:\Program Files (x86)\Minimal ADB and Fastboot>echo "127.0.0.1 localhost" >>hosts

    it says

    Access is denied.


    The problem is not about root access.

    When I type

    C:\Program Files (x86)\Minimal ADB and Fastboot>adb root

    It says

    adbd is already running as root
     
  3. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #7
    Points:
    2,138
    Posts:
    22,285
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,285
    23,605
    2,138
    Male
    space alien ;)
    Indy
    Oh, good point, LV!

    I was using a Cygwin window to demonstrate the adb connectivity, so I didn't pay attention to what @andfo was posting for the initial adb command.

    @andfo, make sure you're doing/checking the adb connectivity from a Windows Command Prompt:

    c:\> adb devices
     
    andfo likes this.
  4. andfo

    andfo Member
    Thread Starter
    Rank:
    None
    Points:
    38
    Posts:
    50
    Joined:
    May 26, 2015

    May 26, 2015
    50
    14
    38
    Yeah the device connected.

    adb devices​

    List of devices attached
    016B73781801A009 device


    "$ adb pull /system/etc/hosts hosts " works.

    But "echo "127.0.0.1 localhost" >>hosts" doens't work and says "Access denied"

    hmm..
     
  5. andfo

    andfo Member
    Thread Starter
    Rank:
    None
    Points:
    38
    Posts:
    50
    Joined:
    May 26, 2015

    May 26, 2015
    50
    14
    38
    I also tried

    echo "127.0.0.1 facebook.com" >>/system/etc/hosts


    But it says "The system cannot find the path specified."
     
  6. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #7
    Points:
    2,138
    Posts:
    22,285
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,285
    23,605
    2,138
    Male
    space alien ;)
    Indy
    Now that you've got adb connectivity, you should be able to follow the outline of tasks in post #11.

    You cannot do the echo that you're trying to do without 1) becoming root, 2) remounting /system in read-write mode, 3) resetting the permissions on the /system/etc/hosts file, etc...

    Follow my instructions and a the place where it says "### I'm just going to add to the file from the shell prompt; you'll probably want to use and editor" you should use a editor like Notepad.exe to edit the hosts file that you pulled off of your phone in the steps before it.

    Add your lines / changes in there.

    Subsequent commands (i.e., the adb push...) will put the edited file back on your device, and so on...
     
    argedion and andfo like this.
  7. andfo

    andfo Member
    Thread Starter
    Rank:
    None
    Points:
    38
    Posts:
    50
    Joined:
    May 26, 2015

    May 26, 2015
    50
    14
    38
    Thank you again. Yes I am doing what post11 is recommending, but the echo part doesn't work.

    1) becoming root: I typed "adb root" and it says "adbd is already running as root" so I assume it's done.

    2) remounting /system in read-write mode : How do I do this?

    3) resetting the permissions on the /system/etc/hosts file : How do I do this?


    And how can I open hosts file from notepad.exe ? I can't access it using notepad.
     
  8. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #7
    Points:
    2,138
    Posts:
    22,285
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,285
    23,605
    2,138
    Male
    space alien ;)
    Indy
    I don't have "adb root" in my instructions :( :eek: :thinking:...not sure where you're getting that from...that is NOT in contents of post #11.

    Follow the instructions and at the point AFTER you've pulled the /system/etc/hosts file to your PC, fire-up the Notepad app on your PC, open/edit the "hosts" file in the folder that it got copied to (on your PC), make your changes, and then continue on in the script.

    Those instructions work. I tested them.

    edit: remember, you will NOT be doing the following section:

    ### I'm just going to add to the file from the shell prompt; you'll probably want to use and editor
    c:\> echo "173.194.46.72 google.com" >> hosts
    but will instead be editing the "hosts" file that is now on your PC.
     
    andfo likes this.
  9. andfo

    andfo Member
    Thread Starter
    Rank:
    None
    Points:
    38
    Posts:
    50
    Joined:
    May 26, 2015

    May 26, 2015
    50
    14
    38
    Oh the key was I had to start the command window in administrator mode in the first place!! :)

    Not just the notepad, I need to open the MAF32 in administrator mode!

    Now everything worked

    Thank you very very very X 9999 much.

    You are wonderful!
     
  10. Curtis1973

    Curtis1973 Android Expert
    Rank:
     #67
    Points:
    353
    Posts:
    2,189
    Joined:
    Jul 1, 2012

    Jul 1, 2012
    2,189
    1,663
    353
    Male
    Greenville,SC USA
    ES File Explorer won't show root directories if you are not rooted. It will only show you the storage tabs last that I used it. Been awhile though. Root explorer will let you browse the root directory tree. you'll find system etc then.
     
    scary alien likes this.
  11. alocut

    alocut Lurker
    Rank:
    None
    Points:
    16
    Posts:
    4
    Joined:
    Dec 2, 2016

    Dec 2, 2016
    4
    1
    16
    Female
    www.k3lvinmitnick.com
    Tks about your Useful ADB commands,

    How do I copy 2 files from my Computer (D:\abc\file1 and D:\abc\file2) to data/nvram/APCFG/APRDEB/ (In my Device) via ADB command only ?
     

    Attached Files:

  12. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #7
    Points:
    2,138
    Posts:
    22,285
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,285
    23,605
    2,138
    Male
    space alien ;)
    Indy
    Welcome to our AndroidForums, @alocut :).

    You'd first need to copy your files to your "SD card" area since adb won't be able to push a file to the protected /data area directly.

    So, something like this:

    // first, push your files to your external storage area:
    //
    d:/> adb push file1 /sdcard/file1
    d:/> adb push file2 /sdcard/file2

    // next, fire-up an adb shell (or you can do this from your device via something
    // like the Terminal Emulator for Android):
    //
    d:/> adb shell
    //
    // yes, you'll need root for the next steps:
    //
    $ su
    # cd /sdcard
    //
    // now, if your device does not support the cp (copy) command:
    //
    # cat file1 > /data/nvram/APCFG/APRDEB/file1
    # cat file2 > /data/nvram/APCFG/APRDEB/file2
    //
    // or, if your device supports the cp (copy) command/utility --
    //
    # cp file1 /data/nvram/APCFG/APRDEB/.
    # cp file2 /data/nvram/APCFG/APRDEB/.
    # exit
    $ exit
    d:/>

    That's it :).
     
    El Presidente, alocut and lunatic59 like this.
  13. alocut

    alocut Lurker
    Rank:
    None
    Points:
    16
    Posts:
    4
    Joined:
    Dec 2, 2016

    Dec 2, 2016
    4
    1
    16
    Female
    www.k3lvinmitnick.com
    scary alien likes this.
  14. andfo

    andfo Member
    Thread Starter
    Rank:
    None
    Points:
    38
    Posts:
    50
    Joined:
    May 26, 2015

    May 26, 2015
    50
    14
    38
    Hi scary alien.. I came back after 3 years... It doesn't work on my new phone.

    Please find the attached.

    I did developer option, I did enabled usb developing, I opened minimal adb using admin mode.

    And all others work.

    "cat" doesn't work.

    "su" command doesn't work.

    It fails to change from read-only to read-write.

    What should I do?

    Thank you so much.
     

    Attached Files:

  15. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #7
    Points:
    2,138
    Posts:
    22,285
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,285
    23,605
    2,138
    Male
    space alien ;)
    Indy
    Your device does not appear to be rooted, which is a requirement for what you're trying to (re-)do.
     
  16. andfo

    andfo Member
    Thread Starter
    Rank:
    None
    Points:
    38
    Posts:
    50
    Joined:
    May 26, 2015

    May 26, 2015
    50
    14
    38
    Thank you! I rooted the phone now at least "su" seems to work. "cat" still results in "cat is not recognized as an internal or external command, operable program or batch file"

    And.. when I do "mount -o remount,rw /system", it can't change it to read-write. It says "/system: Device or resource busy"
     
  17. andfo

    andfo Member
    Thread Starter
    Rank:
    None
    Points:
    38
    Posts:
    50
    Joined:
    May 26, 2015

    May 26, 2015
    50
    14
    38
    Oh! Just doing

    mount -o rw,remount /system

    solved the issue!
     

Share This Page

Loading...