NSLU2-Linux
view · edit · print · history

After trying several solutions the best for me were found here : http://ditwww.epfl.ch/SIC/SA/SPIP/Publications/article.php3?id_article=947
Thank you to the author.

{Translated from original French to English - lxs} {Note: the follow describes the installation of ntp server, but you could instead install ntpclient}

My NTPD

To synchronise the (processor) system clock over the network, one uses the NTP (Network Time Protocol). Detailed in the RFC 2030, this protocol permits the resolution of variable time across the Internet. NTP ensures a precision of the order of 1/100 of a second. NTP uses a hierarchical (layered) system of clock; the systems in layer 1 are synchronized with a GPS clock or with an Atomic clock (cesium); those in layer 2 calculate time according to one or more servers from layer 1. The installation of ntpd on Slug will first synchronize its internal clock and can then subsequently act as the local network timeserver. Even though many modem routers run NTP as a client, they do not act as NTP server for their own (networking) clients.

Installing ntpd

# ipkg install ntp// Installing ntp (4.2.0-1) to root...
Downloading http:.../ntp_4.2.0-1_armeb.ipk(approve sites)
Configuring ntp

Configuring ntp

It is preferable to configure synchronisation with servers which are closer, that is to say topographically closer on the network. Doing this means that the messages need to travel through less routers.

/opt/etc/ntp/ntp.conf

---
driftfile /var/spool/ntp/ntp.drift
server 0.ch.pool.ntp.org
server 1.ch.pool.ntp.org
server 2.ch.pool.ntp.org
---
becomes for me (Brest/France)
---
#Default conf file for ntpd
driftfile /var/spool/ntp/ntp.drift

server 0.fr.pool.ntp.org
server 1.fr.pool.ntp.org
server 2.fr.pool.ntp.org
---

/opt/etc/init.d/S77ntp is the script which relaunches the ntp process

#!/bin/sh
if [ -n "`pidof ntpd`" ]; then
   /bin/killall ntpd 2>/dev/null
fi

if [ ! -d /var/spool/ntp ] ;  then
   mkdir -p /var/spool/ntp
fi

# correct the incorrect tick value on the {Slug} before starting ntpd!
/opt/bin/tickadj 10000

/opt/bin/ntpd -c /opt/etc/ntp/ntp.conf -f \ /var/spool/ntp/ntp.drift -s /var/spool/ntp -k \ /opt/etc/ntp -l /var/spool/ntp/ntp.log

/unslung/rc.rstimezone replaces the Linksys script :
---
#!/bin/sh
# Diversion script to set time
# will run ntp server from /opt/etc/init.d
# Extract the GUI timezone from the .conf file
# Copy the corresponding /usr/zoneinfo file over /usr/local/localtime
/usr/sbin/Set_TimeZone >/dev/null # Adjust hardware clock for accumulated drift
/usr/sbin/hwclock --adjust --localtime # Initialize the kernel with the corrected time
/usr/sbin/hwclock --hctosys >/dev/null # Do an initial clock set
/opt/bin/ntpdate -b 2.ch.pool.ntp.org >/dev/null 2>&1

# Do not execute the Linksys script
return 0
---

The diversion script /unslung/rc.crond alters the /etc/crontab
---
#!/bin/sh
# Diversion script: customize before starting crond
#
# Reason: change the periodic update of the hwclock to use --adjust
#
if [ ! -e /etc/crontab.orig ]
then cp -p /etc/crontab /etc/crontab.orig; fi
sed -i -e 's/1 \* \* \* \* root \/usr\/sbin\/hwclock -s \&>\/dev\/null/1 \* \* \* \* root\/usr\/sbin\/hwclock --adjust --localtime \&>\/dev\/null/' /etc/crontab
#
# Execute the Linksys script
return 1
---

/etc/crontab after the modification to the diversion script

---\\
SHELL=/bin/sh\\
PATH=/sbin:/bin:/usr/sbin:/usr/bin\\
MAILTO=""\\
HOME=/\\

[=# ------ ------ Default is Empty -------- -- #=]\\
0 0-23/8 * * * root /usr/sbin/CheckDiskFull &>/dev/null\\
0 0 * * * root /usr/sbin/WatchDog &>/dev/null\\
1 * * * * root /usr/sbin/hwclock --adjust --localtime &>/dev/null\\
---\\

As you have modified the diversion scripts and also edited the crontab, it is a good idea to restart the Slug to verify that all falls nicely into place.

Test ntp

After some hours have passed the Slug should have synchronised with the timeservers. To verify this, the date command should return the exact time and the command ntpq will give access to the timeserver Shell :

# ntpq -n

ntpq> pe\\
    remote           refid      st t when poll\\
==============================================\\
130.60.7.43     .STEP.          16 u    - 1024\\
+130.60.7.43     130.60.7.51      3 u  419 1024\\
*217.150.242.8   .DCFa.           1 u  441 1024\\
ntpq> exit\\

The asterisk * indicates that ntpd was synchronised on this particular server. The column St informs us that it is a layer 1 server. Therefore, all is well. + indicates other eligible servers for synchronisation. For more documentation on the configuration and for problem resolution (FAQ) for ntpd see: www.ntp.org.

My results after using what is explained above on unslung 6.8 binary :

\\[=# date=]\\
Sun Apr 16 04:44:41 CEST 2006\\
[=# /opt/bin/ntpq -n=]\\
ntpq> pe\\
     remote           refid      st t when poll reach   delay   offset  jitter\\
==============================================================================\\
*82.238.248.248  195.83.222.27    2 u   48   64  377   80.214   11.869   7.155\\
+194.146.227.112 131.188.3.220    2 u   45   64  377   41.831   30.743  17.842\\
+80.74.64.2      194.2.0.28       3 u   48   64  377   49.654   29.714  21.749\\

Typo in diversion script

I detected a missing blank in the diversion script leading to a malformed crontab! Corrected Version attached. Armin

Wrong:

sed -i -e 's/1 \* \* \* \* root \/usr\/sbin\/hwclock -s \&>\/dev\/null/1 \* \* \* \* root\/usr\/sbin\/hwclock --adjust --localtime \&>\/dev\/null/' /etc/crontab

Correct:

sed -i -e 's/1 \* \* \* \* root \/usr\/sbin\/hwclock -s \&>\/dev\/null/1 \* \* \* \* root \/usr\/sbin\/hwclock --adjust --localtime \&>\/dev\/null/' /etc/crontab
view · edit · print · history · Last edited by Armin.
Based on work by lxs4ever and Pierre LASSALLE.
Originally by Pierre LASSALLE.
Page last modified on November 16, 2006, at 01:54 PM