Replace 'hosts' file on Desire

Search This thread

zoltar99

Senior Member
Sep 10, 2008
152
6
Romford, UK
Apologies if this has been discussed before, I have been researching this for a few days now and have tried every single method that has been advised but was unable to replace the hosts file from my Desire with a custom one. Seems the methods used for the Hero and other Android phones do not work on the Desire. Has anyone managed to replace the default 'hosts' file with a custom one?
My Desire IS rooted. I have tried the adb push method after deleting original file and remounting, I always get an error, something 'cannot allocate space' or similar. I have also tried using Root Explorer, again it says the file is too big. If I make the hosts file smaller by removing some data from it, it copies it, then the phone restarts itself and then when i check, the old hosts file is back (the original hosts file only has one entry for local host 127.0.0.1). I also tried editing the hosts file on the device using Root Explorer, I save, then the phone restarts and all the changes are lost. I seem to have tried all the possibilities and had no joy.
And before you ask, yes, I tried installing the AdFree app from the market, it doesn't seem to do anything, and sometimes it does restart my phone as well.
Any advice how to sort this out would be much appreciated.
 

kingchris

Senior Member
Apr 17, 2007
310
13
Hello,

i have created a patched Adfree app for Desire
Adree now loads the hosts-file to

/sdcard/etc/hosts
i have removed /system/etc/hosts
and symlinked to /sdcard/etc/hosts

after the first start klick on "revert" and then on "Update & Install Hosts"

after that you can edit the Hosts file in /sdcard/etc/hosts and it will be used by android system

all files attached

(start in recovery using recovery script,
after that run the install script - STEP1 inside,
reboot into System
run install Script - STEP2)

please tell me if it wont work for you
 
Last edited:

DocRambone

Retired Recognized Developer
Jan 7, 2010
6,834
3,446
Stockholm
Hello,

i have created a patched Adfree app for Desire
Adree now loads the hosts-file to

/sdcard/etc/hosts
i have removed /system/etc/hosts
and symlinked to /sdcard/etc/hosts

after the first start klick on "revert" and then on "Update & Install Hosts"

after that you can edit the Hosts file in /sdcard/etc/hosts and it will be used by android system

all files attached

(start in recovery using recovery script, after that run the install script inside)

please tell me if it wont work for you

NICE
But i have some bug: get java.io.EOFExecepion error when i try to update.
ect/hosts folder on sd, installed apk by rootexplorer
 

aslocum

Member
Sep 5, 2009
45
4
48
Lübeck
where is the problem? I have just pushed my custom hosts file to /system/etc in recovery and it works without any problems.
Just mount /system in the root recovery and push it...
my hosts is from here: http://xdaforums.com/showthread.php?t=664532

Sent from my HTC Desire using Tapatalk
 

kingchris

Senior Member
Apr 17, 2007
310
13
NICE
But i have some bug: get java.io.EOFExecepion error when i try to update.
ect/hosts folder on sd, installed apk by rootexplorer

i had this error 2 times,
after pressing "revert" the error is gone

--edit--
seems to be a random error.
but after "revert" it works

@ aslocum
the problem is, that you cant update the file if the system is running. but if u symlink it, it is possible
 
Last edited:

aslocum

Member
Sep 5, 2009
45
4
48
Lübeck
How many times do you update the hosts file? The hosts from the thread I linked is really good and optimized. better the the adfree one.i do not need to update it till we get full write access...

Sent from my HTC Desire using Tapatalk
 

kingchris

Senior Member
Apr 17, 2007
310
13
you are right, it is not necessary to update the hosts-file all the time,
but i like it to add / replace the file even when im not near to a PC.
i thought it is a solution, and i want to share it with all the others.
 

aslocum

Member
Sep 5, 2009
45
4
48
Lübeck
No offense to you :) sometimes im also in the mood just to make something work and others wont understand why ;)
Most times its also fun to make things work :)

Sent from my HTC Desire using Tapatalk
 

zoltar99

Senior Member
Sep 10, 2008
152
6
Romford, UK
Hello,

i have created a patched Adfree app for Desire
Adree now loads the hosts-file to

/sdcard/etc/hosts
i have removed /system/etc/hosts
and symlinked to /sdcard/etc/hosts

after the first start klick on "revert" and then on "Update & Install Hosts"

after that you can edit the Hosts file in /sdcard/etc/hosts and it will be used by android system

all files attached

(start in recovery using recovery script,
after that run the install script - STEP1 inside,
reboot into System
run install Script - STEP2)

please tell me if it wont work for you

Hey kingchris,

Thanks for your efforts in creating the patched version. I have installed your apk, put the hosts file on the sdcard in /etc folder. Ran the app, clicked revert, it said Success, then Download and install Hosts, it went ok, now it says 'No need to update, your system already has the latest version. I click ok, but it doesn't seem to block any ads. Not sure what to do. Does the app have to be running in the background to work?


Trying to run the install script I got the following:

C:\adfreepatched>install-adfree-windows-step1.bat

C:\adfreepatched>adb-windows.exe shell mount /system
- exec '/system/bin/sh' failed: No such file or directory (2) -

C:\adfreepatched>adb-windows.exe shell mount /sdcard
- exec '/system/bin/sh' failed: No such file or directory (2) -

C:\adfreepatched>adb-windows.exe shell mkdir /sdcard/etc
- exec '/system/bin/sh' failed: No such file or directory (2) -

C:\adfreepatched>adb-windows.exe shell cp /system/etc/hosts /sdcard/etc/hosts
- exec '/system/bin/sh' failed: No such file or directory (2) -

C:\adfreepatched>adb-windows.exe shell rm -r /system/etc/hosts
- exec '/system/bin/sh' failed: No such file or directory (2) -

C:\adfreepatched>adb-windows.exe shell ln -s /sdcard/etc/hosts /system/etc/hosts

- exec '/system/bin/sh' failed: No such file or directory (2) -

C:\adfreepatched>install-adfree-windows-step2.bat



Sorry for being such an ignorant :(
 

kingchris

Senior Member
Apr 17, 2007
310
13
i have created a new version of the fiel with a step1 and step2 batch

boot into recovery.
run recovery-windows.bat
run install-adfree-windows-step1.bat
reboot into your normal system
install-adfree-windows-step2.bat
then start adfree

if you get the Error Message try it again.
i think this is not an error created by the modification,
this is a problem on checking and downloading the hosts file

i made an error in the first script
in the script i wrote adb mount but it has to be adb shell mount
 

Attachments

  • Desire-adfree_helper.zip
    3.3 MB · Views: 960

zoltar99

Senior Member
Sep 10, 2008
152
6
Romford, UK
Uninstalled the program, deleted the /etc/hosts from my sdcard and started all over. If i boot into recovery mode and I get to the green recovery screen, I can no longer type any commands from the terminal window. If I reboot into Android, I run the two install commands and here are the results:

C:\adfreepatched2>install-adfree-windows-step1.bat

C:\adfreepatched2>adb-windows.exe shell mount /system
mount: can't read /etc/fstab: No such file or directory

C:\adfreepatched2>adb-windows.exe shell mount /sdcard
mount: can't read /etc/fstab: No such file or directory

C:\adfreepatched2>adb-windows.exe shell mkdir /sdcard/etc

C:\adfreepatched2>adb-windows.exe shell cp /system/etc/hosts /sdcard/etc/hosts

C:\adfreepatched2>adb-windows.exe shell rm -r /system/etc/hosts
rm: can't remove '/system/etc/hosts': Directory not empty

C:\adfreepatched2>adb-windows.exe shell ln -s /sdcard/etc/hosts /system/etc/host
s
ln: /system/etc/hosts: File exists

C:\adfreepatched2>install-adfree-windows-step2.bat

C:\adfreepatched2>adb-windows.exe install signed-Adfree_patched.apk
812 KB/s (39004 bytes in 0.046s)
pkg: /data/local/tmp/signed-Adfree_patched.apk
Success

The program is installed on my phone, it says Update found, i press ok, then click on Revert, all it does is it restarts my phone. Here, I went and replaced the 1KB hosts file from /sdcard/etc/ with the one in your folder, then when I clicked Revert, it said Success! Your hosts file has been restored. I then clicked Download & install hosts, and it said Success! your Android device should now be AdFree, however you might need to reboot to clear your cache. I rebooted the device. Ran AdFree again and it says your good to go! No need to update, your system already has the latest version.
So I guess it should now be working?

I installed a few 'free' apps from the market to see if I get the adds, and sure they are there.
For some reason, I still think it is using the /system/etc/hosts version instead of the version on the sdcard.
 

kingchris

Senior Member
Apr 17, 2007
310
13
If i boot into recovery mode and I get to the green recovery screen, I can no longer type any commands from the terminal window.

you have to open a second Command,if you are in the green recovery console
and run the step1.bat there

if you type after you have done all the steps

cd system
cd etc
ls -al *host*



you should see something like

lrwxrwxrwx 1 0 0 17 May 13 04:43 hosts -> /sdcard/etc/hosts

then its rights
 

zoltar99

Senior Member
Sep 10, 2008
152
6
Romford, UK
I got that, thanks, but please read the second part of my last message and tell me do you think that is ok? I have installed Adfree, it says it is up to date, but it is still not blocking ads, apparently.
 

zoltar99

Senior Member
Sep 10, 2008
152
6
Romford, UK
That's what I thought, but is there another way to tes apart from running apps that use adds? I tried by putting a few sites taken from the hosts file into the browser, and it opens all of them :( I have a customised hosts file on my pc as well, and it works like a charm.
 

kingchris

Senior Member
Apr 17, 2007
310
13
then use your customized one. idk if the files from adfree uptodate. but i can say it will work
 

zoltar99

Senior Member
Sep 10, 2008
152
6
Romford, UK
Finally Adfree working

i have created a new version of the fiel with a step1 and step2 batch

boot into recovery.
run recovery-windows.bat
run install-adfree-windows-step1.bat
reboot into your normal system
install-adfree-windows-step2.bat
then start adfree

if you get the Error Message try it again.
i think this is not an error created by the modification,
this is a problem on checking and downloading the hosts file

i made an error in the first script
in the script i wrote adb mount but it has to be adb shell mount


Thanks a lot man, seems to be working ok now, I have had so much trouble getting this to work, finally working.
 

veronl

Member
Aug 23, 2009
43
0
I have successfully updated adfree with your file. Thanks so much.

Sorry to ask a silly question...

because when I boot into the recovery mode, I can see several options available but I cannot choose them.

I hold volume down & power on, then I select "recovery" & press "power" again that means I choose this option then it goes into recovery mode, right? In the recovery mode, I cannot choose anything because if I press any button it simply turns off the monitor! What should I do??
(I take out the battery to complete the reboot........... There must be some other ways?)
 

NSF12345

Member
Aug 5, 2010
37
0
I have successfully updated adfree with your file. Thanks so much.

Sorry to ask a silly question...

because when I boot into the recovery mode, I can see several options available but I cannot choose them.

I hold volume down & power on, then I select "recovery" & press "power" again that means I choose this option then it goes into recovery mode, right? In the recovery mode, I cannot choose anything because if I press any button it simply turns off the monitor! What should I do??
(I take out the battery to complete the reboot........... There must be some other ways?)

Not sure if you've resolved this or not. If not, what recovery are you using? Iv use Amon_Ra's on my HTC Magic, and Clockwork's on HTC Desire, both of which allow you to use the scrollball/pad to select the menu's