Skip to content

Install NTP Daemon for Asuswrt Merlin

kvic-z edited this page Sep 24, 2017 · 6 revisions

NTP Daemon and Performance Stats

Package

  • ntpd_stats-arm-R3-1.tar.gz (for arm)
  • ntpd_stats-mips-R2.tar.gz (for mips)

This package provides a NTP Daemon (ntp-4.2.8p4 for mips and ntpd-4.2.8p9-win for arm) for Asuswrt/Merlin firmwares. Both ARM and MIPS based routers are supported (by installing the correct package). The package tries hard to be firmware version agnostic. Seems that's the case finally.

Pre-requisite

Entware installed

Installation

Step 1: Install rrdtool and wget packages from Entware.

We need rrdtool for graphing. wget is for retrieving the tarball from github.

  • opkg install rrdtool
  • opkg install wget

Step 2: Copy /www to /opt/var/www in preparing WebGUI to run from /opt/var/www

  • tar cf - /www | tar -C /opt/var -xvf -

Step 3: Retrieve and install the package

NOTE We want to install ntpd_stats-arm-R3-1.tar.gz for ARM routers or ntpd_stats-mips-R2.tar.gz for MIPS routers.

WARNING: the tarball has the following content. If you notice a conflict with your setup, make a backup of existing files first. Then do a merge after Step 3 and before proceed to Step 4.

/jffs/bin/ntpd
/jffs/bin/ntpq
/jffs/bin/ntpstats.sh
/jffs/etc/ntp.conf
/jffs/configs/fstab
/opt/etc/init.d/S77ntpd-custom
/opt/var/spool/ntp/Tools_NtpdStats.asp
/opt/var/spool/ntp/stats.rrd

Once safe to proceed, run the following if you have a ARM router

  • wget --no-check-certificate -O - https://github.com/kvic-z/goodies-asuswrt/blob/master/ntpd_stats-arm-R3-1.tar.gz?raw=true | tar -C / -xzf -

OR run the following if you have a MIPS router

  • wget --no-check-certificate -O - https://github.com/kvic-z/goodies-asuswrt/blob/master/ntpd_stats-mips-R2.tar.gz?raw=true | tar -C / -xzf -

Step 4: Run the following command to manually start ntpd as litmus test

  • cp /jffs/configs/fstab /etc; mount -a
  • /opt/etc/init.d/S77ntpd-custom start
  • /jffs/bin/ntpstats.sh

mount -a mounts /opt/var/www to /www. No worries. It's not a destructive operation. The original content of /www still resides safely in ROM.

Stop and check if any error. Or else proceed to next step.

Step 5: (FW version <= 380.67) Patch files for WebUI and restart httpd

  • cp /opt/var/spool/ntp/Tools_NtpdStats.asp /www
  • sed -i 's/Other Settings");/Other Settings", "NTP Daemon");/' /www/state.js
  • sed -i 's/therSettings.asp");/therSettings.asp", "Tools_NtpdStats.asp");/' /www/state.js
  • service restart_httpd

Step 5: (FW version >= 380.68) Patch files for WebUI and restart httpd

  • cp /opt/var/spool/ntp/Tools_NtpdStats.asp /www
  • sed -i '/"Tools_OtherSettings.asp", tabName: "Other Settings"/a {url: "Tools_NtpdStats.asp", tabName: "NTP Daemon"},' /www/require/modules/menuTree.js
  • service restart_httpd

Stop and check if any error. If things go well, you shall see NTP Daemon on WebUI > Tools page.

Step 6: Create a cron job to collect NTPD stats. Add the following line to /jffs/scripts/services-start

  • cru a NtpdStats "*/5 * * * * /jffs/bin/ntpstats.sh"

Step 7: Append the following two lines to the end of /jffs/scripts/post-mount

  • mount -a
  • service restart_httpd

Step 8: Reboot your router and enjoy!

You may want to reboot now to confirm changes stay.

Tune your NTP Daemon Config

Check the "server" entries in /jffs/etc/ntp.conf. You may want to replace those ip addresses with time servers near you. Preferrably put some stratum 1 servers there.

If you have a USB GPS dongle...

You may want to install gpsd from Entware-ng, and get ntpd_SHM.tar.gz from kvic-z/goodies-asuswrt. This tarball contains a version of ntpd which has SHM driver compiled in. Note that this binary is for ARM only at the moment.

For more detail on how to get GPS work, go to this post.

Uninstall

  • unstall rddtool and wget through Entware
  • remove the lines you added to /jffs/scripts/post-mount and /jffs/scripts/services-start
  • rm /jffs/bin/ntpd
  • rm /jffs/bin/ntpq
  • rm /jffs/bin/ntpstats.sh
  • rm /jffs/etc/ntp.conf
  • rm /jffs/configs/fstab
  • rm /opt/etc/init.d/S77ntpd-custom
  • rm /opt/var/spool/ntp/Tools_NtpdStats.asp
  • rm /opt/var/spool/ntp/stats.rrd
  • rm -rf /opt/var/www
  • reboot

Forum discussion

http://www.snbforums.com/threads/ntp-daemon-for-asuswrt-merlin.28041/