[HowTo] Running Adguard Home on OpenWrt

you know for older routers or routers with limited space that's a brilliant engineering hack.

Might be worth writing up as a post separately because other routers with usb ports could use the same trick.

Suddenly, my AGH cannot be blocked. AGH will perform DNS Queries, but it cannot Blcok by filters.
What should I do?

check your disk space. You may have run out and updated filters have not been downloaded.

Then restart AGH so it reloads its filters.

/etc/init.d/AdGuardHome restart

currently AGH uses 35mb of space for its binary. It then will use space for its query logs and database. Query logging is currently using 45mb of space on my router. Current log rotation setup means you will need double that space so 35mb x 2 (for AGH binary and its backup when it upgrades) and log space x2.
AGH also will crash with error messages once it it out of diskspace. Keeping an eye on your free diskspace is crucial. Once you have AGH up and running after an upgrade you can delete the /opt/AdGuardHome/agh-backup folder contents.

If you run out of space entirely?

/etc/init.d/AdGuardHome stop

Now delete the /opt/AdGuardHome/agh-backup contents. (this is your previous AGH binary and setup files. Copy it to your pc if you want but its safe to delete all of this)

The /opt/AdGuardHome/data folder contains the following.

root@OpenWrt:/opt/AdGuardHome/data# ll -h
drwxr-xr-x    3 root     root         512 Oct 29 09:42 ./
drwxrwxrwx    4 root     root         736 Oct 30 09:06 ../
drwxr-xr-x    2 root     root         800 Nov  2 09:52 filters/
-rw-r--r--    1 root     root       45.4M Nov  2 20:42 querylog.json
-rw-r--r--    1 root     root        8.9M Oct 29 09:00 querylog.json.1
-rw-r--r--    1 root     root       32.0K Oct 30 05:28 sessions.db
-rw-r--r--    1 root     root        4.0M Nov  2 21:00 stats.db

Delete the querylog files. These are your DNS queries.
sessions.db are connections to AGH currently. This can be deleted as well
stats.db you can purge but you will lose your statistics data.

filters folder contains all your filter downloads. Purge if it is full but it will re-download your filters. If your filters are too large for your diskspace you will have to disable large filters and restrict their usage.

I suggest you purge the filters folder to force AGH to redownload good filters and start filtering again.

Now
/etc/init.d/AdGuardHome start

Then logread -f and watch AGH start back up and watch for errors. Once it is fully loaded you can control C and exit your SSH session.

1 Like

I disconnected the power and restarted the device, and everything returned to normal.

I will perform these operations later, and Then thank you.

I've been thinking of doing this. Can you put a brief how to on these forums?
Thanks

Okay, I've posted it.

I haven't tried to be thorough about supporting topics like configuring AdGuard Home or writing an operating system to an SD card: these are separate issues and well-documented elsewhere. Mostly I've stuck to the parts that are distinctive about this application.

Is there a way to change the default working directory of AGH after the installation, preferably in it's configuration .yaml file?

The idea is I would like to leave the executables in /opt folder, but pipe the log / stats / filters to /tmp, where there are more spaces and will be wiped out after a reboot.

Thanks.

good question.

i dont see it in their Yaml spec, however

shows this

Options:
  -c, --config VALUE                 Path to the config file.
  -w, --work-dir VALUE               Path to the working directory.

I suspect that will mean the data folder (and thus the filters folder below it) will end up on the /tmp.

Maybe someway to have configs for all of them? so keep stats and filters but logins and queries are /tmp and discarded?

Maybe worth filling an issue on AGH page to ask for it?

I pointed out on my filesystem checks bug i filed with them that some routers have limited space (it doesn't check for freespace before installing updates which is kinda bad)

(edit) /etc/init.d/AdGuardHome

cmd="/opt/AdGuardHome/AdGuardHome "-s" "run""

So adding in the working directory there should tweak things. Don't forget to reference the config file as well!

(edit 2) so having thought about this for bit. I think you would have to write some sort of script that would copy/dump the files you want saving to a folder and when you reboot it copies them to the /tmp folders in preperation for AGH starting (to prepopulate the filters and to restore the stats db if u wanted it kept) However if u willing to just dump it all on reboot. then redirecting the working folder to /tmp would work fine. Functionally wise AGH works. What we are asking for is modifications for limited router space issues. Thats most likely going to end up as a low priority feature request. My disk space checks for instance are aimed at the next point release. see here : https://github.com/AdguardTeam/AdGuardHome/issues/3801

That reminds me. i did write up my upgrade script but i posted it on the other thread. I've copied it here now as well.

Limited space routers.

AGH binary takes up 35mb and during its update it will download the new binary compressed, backup your old binary and then extract and replace the old binary with the new one. This means you require 35mb x2 and the compressed file space and extraction space.

To manually do this, do an upgrade from the control panel and look for what version it wants to upgrade to in your syslog. Make sure you use the version you installed. Don't blindly copy my config :slight_smile:

AdGuardHome[5830]: 2021/11/10 16:03:30.149784 [info] Updating from v0.107.0-a.199+2fc10848 to v0.107.0-a.203+6fd9e72f. URL:https://static.adguard.com/adguardhome/edge/AdGuardHome_linux_mips_softfloat.tar.gz

SSH into your router and stop AGH.

/etc/init.d/AdGuardHome stop

download the new version to your routers /tmp area or to your laptop/pc. Then either unpack AGH binary from the compressed download over the existing binary or unpack the binary on your laptop/pc and copy it over the existing binary using something like WinSCP or equivalent.

Now restart AGH.

/etc/init.d/AdGuardHome start

(Edit) commands to do this below.

#Stop AGH
/etc/init.d/AdGuardHome stop 

#Grab updated AGH from server and save to /tmp
wget https://static.adguard.com/adguardhome/edge/AdGuardHome_linux_mips_softfloat.tar.gz -P /tmp

#unzip updated file over top of AGH in /opt
tar x -vzf /tmp/AdGuardHome_linux_mips_softfloat.tar.gz -C /opt

#cleanup /tmp
rm /tmp/AdGuardHome_linux_mips_softfloat.tar.gz

#Restart AGH
/etc/init.d/AdGuardHome start

Thank you for your quick replies. I don't really care about saving the logs / stats between reboots, so /tmp folder is a prefect fit.

Simply adding -w option to /etc/init.d/AdGuardHome didn't work, or I don't know how to modify it myself. I am thinking to create a symbolic link in /opt/AdGuardHome to point to /tmp.

[Edit] Symbolic link works the trick. I modified /etc/init.d/AdGuardHome to have a simple logic to test if /tmp/data exists, if not, then create it.

1 Like

Is there a way to get the latest snapshots install directly from OPKG?
Binaries on github are twice as big.
I use 32MB flash with only 22MB free space.

You have to wait until a "stable" version of AdGuardHome is released for the version that is in OpenWrt to be updated.

1 Like

If your router has a usb port you could use exroot to extend your space or just install AGH to the usb stick.

Just a heads up to everyone using AdGuardHome on OpenWRT on an issue I experienced a few days. I don't recall it being shared before in this topic or on AdGuardHome's GitHub page.

I had an issue the last few days where AGH would consume all available memory until the OOM killer stopped it. I was running on the most recent beta version on request of an issue I reported on AdGuardHome in GitHub's issue tracker. At first I thought there's a bug in the beta version so I rolled back to 2 previous versions (one was the stable release) and the problem persisted: start AGH, the web interface loaded but was continuously loading the dashboard, CPU usage and memory usage on OpenWRT kept on growing until the OOM killer did it's job. I also suspected a faulty USB stick that I use to run and store AGH query log's.

In the end it turned out to be a problem in a large DNS blocklist I used. I don't know what the problem was, the file itself is around 93MB on disk and head and tail seemed fine. I disabled that blocklist and AGH was running fine again. I emptied the contents ( > $ADGUARDHOME/data/filters/5.txt) and forced an update via AGH web interface and all was well again.

So, in case AGH goes berserk and you can't find an obvious reason, disable DNS blocklists to quick check that.

1 Like

Was this a custom blocklist of your own, or a generally available one? If the latter, it'd be helpful if you posted the URL, both so people can avoid it and the developers can look at it and zero in on the problem. If it's custom, can you upload it either here or somewhere like github so developers and self-selected users can take a look at it? Even as crude an approach as a binary search might isolate the problem without having to trace through code.

It was this one: https://dbl.oisd.nl/
It’s the full list for network based dns blockers on https://oisd.nl/

It’s updated so the problem is fixed.

1 Like

For AdGuardHome you must use abp.oisd.nl, not dbl.oisd.nl.

Not according to https://oisd.nl/how2use.

Think you might not be reading the right section:

AdGuardHome supports basic Adblock rules and hosts files syntax:

Like so:

root@OpenWrt:/mnt/sda1/AdGuardHome/data/filters# head -30 1.txt 
!
! Title: AdGuard DNS filter
! Description: Filter composed of several other filters (AdGuard Base filter, Social media filter, Tracking Protection filter, Mobile ads filter, EasyList, EasyPrivacy, etc) and simplified specifically to be better compatible with DNS-level ad blocking.
! Homepage: https://github.com/AdguardTeam/AdguardSDNSFilter
! License: https://github.com/AdguardTeam/AdguardSDNSFilter/blob/master/LICENSE
! Last modified: 2021-12-04T12:07:39.096Z
!
! Compiled by @adguard/hostlist-compiler v1.0.12
!
!
! Source name: AdGuard Base filter ad servers
! Source: https://raw.githubusercontent.com/AdguardTeam/AdguardFilters/master/EnglishFilter/sections/adservers.txt
!
!
! Section contains list of advertising networks
!
! The rules with hints are at the end of file
!
||eputfeable.co^
||ngecauuks.co^
||gobiidinshore.com^
||escudotagalog.com^
||courierregistered.com^
||new-pressroom.com^
||madehimn.xyz^
||srsihavelearn.xyz^
||yestedjgrs.xyz^
||maritaltrousersidle.com^
||wearetopple.com^
||d1t4ekjh9ps4ob.cloudfront.net^

root@OpenWrt:/mnt/sda1/AdGuardHome/data/filters# head -30 2.txt 
# AdAway default blocklist
# Blocking mobile ad providers and some analytics providers
#
# Project home page:
# https://github.com/AdAway/adaway.github.io/
#
# Fetch the latest version of this file:
# https://raw.githubusercontent.com/AdAway/adaway.github.io/master/hosts.txt
#
# License:
# CC Attribution 3.0 (http://creativecommons.org/licenses/by/3.0/)
#
# Contributions by:
# Kicelo, Dominik Schuermann.
# Further changes and contributors maintained in the commit history at
# https://github.com/AdAway/adaway.github.io/commits/master
#
# Contribute:
# Create an issue at https://github.com/AdAway/adaway.github.io/issues
#

127.0.0.1  localhost
::1  localhost

# [163.com]
127.0.0.1 analytics.163.com
127.0.0.1 crash.163.com
127.0.0.1 crashlytics.163.com
127.0.0.1 iad.g.163.com

root@OpenWrt:/mnt/sda1/AdGuardHome/data/filters# head -30 5.txt 
#    __ __ ____ ____                 
#   /  (  / ___(    \
#  (  O )(\___ \) D (
#   \__(__(____(____/
#
#  Title: oisd full      
#  Syntax: dbl       
#  Entries: 1039441
#  TimeUpdated: 2021-12-04T15:01:26+01:00     
#  Maintainer: sjhgvr
#  Expires: 1 day (update frequency)
#  Homepage: https://oisd.nl

0-0-0-0-0-0-0-0-0-0-0-0-0-10-0-0-0-0-0-0-0-0-0-0-0-0-0.info
0-0-0-0-0-0-0-0-0-0-0-0-0-18-0-0-0-0-0-0-0-0-0-0-0-0-0.info
0-0-0-0-0-0-0-0-0-0-0-0-0-33-0-0-0-0-0-0-0-0-0-0-0-0-0.info
0-0.fr
00000000-0000-0000-0000-8c89a56da7f2.cdn.adx1.com
00000000-0000-0000-0000-ac1f6b9bc102.cdn.adx1.com
0-07.ru
0-1-2.vicp.cc
0-2u.com
00-4-008001-07-04.nrb.footprintdns.com
0-29.com
0-100-pool.coinlab.biz
0-100.coinlab.biz
0-100pool.coinlab.biz
0-132.net.daraz.com
000-638-practice-test-exam-questions.apponic.com
0-day.us