[HowTo] Running Adguard Home on OpenWrt

curious. you have 27mb of ram free. Your loads however are nuts.

Are you using packet steering? That enables all CPUs to handle routing.

SSH in and enable it if not.

uci set network.globals.packet_steering='1'
uci commit network

Now reboot and see if that changes your loads.

I have packets steering enabled already.

You have rebooted to get a clean restart?

You have disk space spare? df -h and check how much space you have left.

/opt/AdGuardHome/data check this folder and see how much is used there.

There was a bug with reloading the stats db (it would cause massive cpu usage reloading the database). Delete or rename everything in the /opt/AdGuardHome/data folder after stopping AGH. Then restart AGH and see if your cpu usage returns to normal.

df -h shows the below, don't think this is OK, or is it?

Filesystem                Size      Used Available Use% Mounted on
/dev/root                 4.5M      4.5M         0 100% /rom
tmpfs                    59.5M      1.8M     57.7M   3% /tmp
/dev/sda1                14.0G    144.2M     13.2G   1% /overlay
overlayfs:/overlay       14.0G    144.2M     13.2G   1% /
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/ubi0_2             105.9M     19.6M     81.5M  19% /rwmste code here

Just to mention I am using USB stick as system storage and all sits there... I think.

After deleting everything from AGH data folder usage shows the same :frowning:

Mem: 93904K used, 27988K free, 1892K shrd, 920K buff, 15468K cached
CPU:  19% usr  19% sys   0% nic  53% idle   3% io   0% irq   4% sirq
Load average: 1.47 0.92 0.90 4/101 28281
  PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
28242     1 root     S     686m 576%  27% /opt/AdGuardHome/AdGuardHome -s run
24800     1 dnsmasq  S     1420   1%   5% /usr/sbin/dnsmasq -C /var/etc/dnsmasq.conf.cfg01411c -k -x /var/run/dnsmasq/dns
25761     1 root     SN    4256   3%   3% /usr/sbin/collectd -C /tmp/collectd.conf -f
  251     2 root     SW       0   0%   2% [kswapd0]

hmm. the usb port on the HH5 is only a usb2.

Have you tried just running with a standard install? The space is tight but sufficient to run OpenWRT and AGH. Its upgrades that use the space and can be mitigated by upgrading manually. OpenWrt AdGuard Home 101 ( DNSMASQ ) - #11 by mercygroundabyss

How did you setup AGH once it was installed?

Otherwise i'd suggest removing the /opt/AdGuardHome/ folder totally and reinstalling from scratch in case something went wrong during install.

1 Like

So just for fun, I've attached an old $5 Pi Zero in ethernet gadget mode to my OpenWRT router's USB2 port, which provides both a USB ethernet NIC to the router and a client NIC to the Zero itself. The idea is that the Zero runs Adguard Home on its own CPU with its own memory and storage, which means that:

A) it does not consume those resources from the router, and
B) it survives a router upgrade without getting wiped or even affected

And it works brilliantly; I've even got the router host set to hand out the Zero's address for DNS, which in turn delegates resolution of the local domain back to the router: which means I cut out the middleman for most domains and it doesn't fork dnsmasq on every request.

So far the only problem is that they share a common uptime: if I reboot the Zero/Adguard gadget, the OpenWRT/router host doesn't reliably reinitialize the USB pseudo-NIC host when it comes back, and the only way out of it is to reboot the router. This is probably okay, because neiether of these platforms ever crashes, but it'd be nice to be able to reboot the Zero without rebooting the router.

[Edit: This is working fine now. The problem was I'd unset "Force link" on the host interface. It seems to work better with this checked.]

5 Likes

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.

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