Block ads on your Android phone (2010-04-15)

Search This thread

scholbert

Senior Member
Aug 1, 2007
1,347
821
1. after entering :
adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
I got: adb server is out of date. killing...
* daemon started successfully *
mount: Operation not premitted

2. after entering:
adb push hosts.for.mobile.txt /etc/hosts
I got: failed to copy 'hosts.for.mobile.txt to '/etc/hosts': Read-only file system
You need to be root to re-mount system partition.
Try:
1. adb push hosts.for.mobile.txt /sdcard
2. adb shell
3. in your device shell type su
4. mount -o rw,remount /dev/block/mtdblock3 /system
5. use mount to check if system partition has been re-mounted.
6. cp /etc/hosts /sdcard/hosts.backup
7. cp /sdcard/hosts.for.mobile.txt /etc/hosts

If your using the recovery console you'll have to:
1. mount system partition to /system first
2. make sure that it's mounted r/w
3. copy your host file to /system/etc/hosts instead of /etc/hosts

Anyway, these are noob questions and have been answered many times in this forum... please use the search button.

Apart from that try to update your adb tool on your host to a newer version.
There'd been an update for 2.1 and up.

@mobileweasel:
After your device has booted up into Android /system/etc is mounted to /etc.
In other words this is the same directory from systems view.

Good luck!

scholbert
 

Savagery

Member
Jul 28, 2010
12
0
Finally got it to work.

Now there is no way I got this working from terminal app, adb + phone booted or default recovery mode (traingle screen). However if you boot into clockwork recovery mode, manually mount system and sdcard and than use the commands from this topic it will work.

Hmm after using this. I can easy pull the hosts file and verify its the correct one. But after boot its back to the old version. Any ideas ? And yes it is succesfully transfered, ea I can pull it and see its correct. Tried twice just to make sure all was ok.

reedit : It seems that under the latest cyanogen mod 7 the phone auto copies its host file from the system directory - meaning you gotta push your host file to "adb push hosts.for.mobile.txt /system/etc/hosts" and NOT "adb push hosts.for.mobile.txt /etc/hosts" even though the regular directory also excist.
 
Last edited:

scholbert

Senior Member
Aug 1, 2007
1,347
821
reedit : It seems that under the latest cyanogen mod 7 the phone auto copies its host file from the system directory - meaning you gotta push your host file to "adb push hosts.for.mobile.txt /system/etc/hosts" and NOT "adb push hosts.for.mobile.txt /etc/hosts" even though the regular directory also excist.
This is no copy at boot time... or some mystic magic :rolleyes:

Independent of which distribution you are using, it's all the same on Android phones:
The /etc folder in the root directory is a symlink to /system/etc.
To modify any file in /etc, the source of the symlink has to be modified of course (/system/etc).

While handling with files in the system structure in general, take care of read only mounts, file permissions and file owner.... etc.
Shell scripts and configuration files need unix text format.
So does the hosts file ;)

These are linux basics and while Android is based upon this OS, it would do no harm to read some educational books.

Have fun!

scholbert
 
Last edited:

Tanker Bob

Senior Member
To install this hosts file, you still need root access obviously:

  1. download the zip
  2. unpack it to the directory where adb.exe is located (if you don't know what adb is or how to get it running, please use the search)
  3. open a command prompt
Code:
adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system 
adb push hosts.for.mobile.txt /etc/hosts
adb shell mount -o ro,remount -t yaffs2 /dev/block/mtdblock3 /system

You might need to restart your phone. Also clearing the Android browser cache will apparently help in getting rid of already cached ads (worked for me, ymmv).

I've tried these commands under 1.57, but it didn't work. I keep getting "Permission denied" when I run the first mount. I also tried using su, but it didn't help. I definitely have root and can open an su shell. Any ideas? Am I missing something?
 

iamxeph

Senior Member
Nov 24, 2008
334
24
Ad-Free.apk is working great, but If I put this file to manually on /system/etc/ , it doesn't work. weird.
 

MomirPeh

Senior Member
Feb 5, 2011
85
11
Sarajevo
Which file are you putting in system/etc? Hosts file or the .apk? Hosts file should go to system/etc and .apk can go to system/app or data/app directories. Also watch for file permissions.

Sent from my GT540 using XDA App
 

croques

Senior Member
Oct 20, 2009
427
80
I've shamelessly stolen from the hosts files in this thread and then added my own to make an up-to-date list that mainly works for me.

The file is sorted, (with the exception of the localhost entry), with duplicates removed.
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 8
    AdFree is a fantastic program created by XDA user delta_foxtrot2 (see this thread in the G1 forum) to facilitate using your hosts file to block ad servers. This makes it extremely easy. Of course you will need root access!


    Unfortunately I found some ads still weren't blocked and the last update to the AdFree hosts file happened 2010-02-27. So I decided to update the hosts file myself. I merged the hosts files from adfree/mvps/yoyo and added a bunch of mobile ad providers I've found myself. The list is free of duplicates and comments, so as to keep it as small as possible (it still amounts to about 635 kB).

    To install this hosts file, you still need root access obviously:

    1. download the zip
    2. unpack it to the directory where adb.exe is located (if you don't know what adb is or how to get it running, please use the search)
    3. open a command prompt
    Code:
    adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system 
    adb push hosts.for.mobile.txt /etc/hosts
    adb shell mount -o ro,remount -t yaffs2 /dev/block/mtdblock3 /system

    You might need to restart your phone. Also clearing the Android browser cache will apparently help in getting rid of already cached ads (worked for me, ymmv).


    As for ethical discussions on blocking ads for free apps, blah. I don't so much have a problem with ads, as I do with the personal data that gets send to the ad providers. I'm talking about location data and whatever else they might want to know about my device and what I'm running ("analytics" is a fancy name for "we want to find out as much about you as we possibly can get away with").

    Anyway.. use it, don't use it, up to you.

    Last updated

    15-4-2010 23:23 (20808 hosts blocked)


    .
    5
    Hello, since this is the top search result for this topic on Google I'd thought I'd share an update. This is a simple method:

    1. Boot into clockworkmod recovery
    2. partitions > mount /system
    3. adb push hosts /system/etc/hosts
    4. adb reboot

    No need to play with remount and permissions in recovery. Working on CM7 RC2 on HTC Aria. I have updated the hosts file using the sources in the comments as of March 8, 2011.

    Edit: Put mobile advertisers from original list back in and removed duplicates.
    2
    I've shamelessly stolen from the hosts files in this thread and then added my own to make an up-to-date list that mainly works for me.

    The file is sorted, (with the exception of the localhost entry), with duplicates removed.
    2
    caps are important - yes, however, it is strange that the hosts file is HOSTS on your Android ROM... but I guess nothing is impossible...

    @No-Frost: If you have Terminal Emulator and some Superuser app for granting root privileges, you can use the following:

    You need to place the hosts file on your SD card to begin with (in this example, the hosts file is: /mnt/sdcard/hosts.final)

    Next, you need to mount the filesystem in read-write mode, as it is read-only by default

    su
    mount -o remount,rw /dev/block/mtdblock3 /system
    mv /etc/hosts /etc/hosts.bak
    cp /mnt/sdcard/hosts.final /etc/hosts
    chmod 644 /etc/hosts
    mount -o remount,ro /dev/block/mtdblock3 /system
    ls -l /etc/hosts


    That should move the hosts.final file from the root of your SD card, into the /etc directory, and apply the filename: hosts

    Be weary of filenames and foldernames under linux - they are case-sensitive... you don't want System or ETC, etc.

    Once you've executed the last line in the script ls -l /etc/hosts, you should be able to verify that the hosts file exists, with the correct access rights.

    Maybe reboot at this point.

    Quit Terminal Emulator, open your browser, maybe clear the cache in the browser, and open one of the ad-servers listed in your hosts file, e.g.:
    http://00fun.com
    If the page fails to load, then everything worked!

    If you still get ads in apps or websites after the above test succeeded, then it could be that the specific app or website is sourcing it's ads from another host that is not yet in the hosts file, or via some other means...
    2
    Finally got it to work.

    Now there is no way I got this working from terminal app, adb + phone booted or default recovery mode (traingle screen). However if you boot into clockwork recovery mode, manually mount system and sdcard and than use the commands from this topic it will work.