Enabling ntpd PPS support for Debian Lenny Linux
The following procedure takes the standard pre-built Debian kernel and rebuilds it with PPS (pulse per second) support for ntpd. This allows you to utilise a low cost gps serial time antenna to turn your existing Debian Linux server into an economical stratum 1 ntp network time source.
(Please note that in this configuration, the pps data and serial time and date data should be supplied to the Linux server on different com ports. Alternate linuxpps patch / kernel versions may fix this issue).
1. Install Debian Lenny
This procedure assumes you have a working fresh install of Debian Lenny Linux version 5.0.6. The commands should be entered via a command shell. You will need to be logged on as root.
2. Install optional packages
Enter the following commands to install optional packages required for the kernel rebuild:
# apt-get install bzip2
# apt-get install module-init-tools
# apt-get install initramfs-tools
# apt-get install procps
# apt-get install fakeroot
# apt-get install zlib1g-dev
# apt-get install git-core
# apt-get install libblkid-dev
# apt-get install kernel-package
3. Kernel source
Download the kernel source code and unpack in a new directory:
# mkdir /newkernel/
# cp /usr/src/linux-source-2.6.26.tar.bz2 /newkernel/
# cd /newkernel/
# tar jxf linux-source-2.6.26.tar.bz2
# cd linux-source-2.6.26
4. Patch the kernel source
Obtain the linuxpps patches and apply to the new kernel source:
# patch -p1 < ntp-pps-2.6.26.diff
(you may need to apply part of this patch manually).
5. Copy kernel configuration file
Copy your existing kernel .config file to the new kernel build:
6. Kernel configuration
Start the new kernel build configuration utility:
7. Enable PPS support
In the kernel configuration utility, enable the following in 'Device Drivers' > 'PPS support' > :
[ ] Use low level IRQ timestamps
[ ] PPS debugging messages
*** PPS clients support ***
<M> Kernel timer client (Testing client, use for debug)
<M> PPS line discipline
[ ] Parallel printer support
8. Build serial support as a module
Again in the kernel configuration utility, in 'Device drivers' > 'Character devices' > 'Serial drivers' >, change '8250/16550 and compatible serial support' to be built as a module.
9. Exit kernel configuration
Save and exit the kernel configuration utility.
10. Build the kernel
Build the new kernel:
# make-kpkg --rootcmd fakeroot --initrd --append-to-version=.pps001 kernel_image kernel_headers
(this will take a while).
11. Install the kernel
Install the new kernel:
# dpkg -i *.deb
12. Bootloader setup
Change the grub bootloader to select the new kernel at reboot:
# vim menu.lst
Edit 'default' value as applicable for your new kernel.
13. Reboot
Reboot:
14. Linuxpps tools
After reboot, log on again as root and obtain the linuxpps userland tools:
# git clone git://www.linuxpps.org/git/pps-tools pps-tools
15. Kernel header files
Update the kernel header files:
# mv linux linux.old
# mv asm asm.old
# mv asm-generic asm-generic.old
# ln -s /lib/modules/2.6.26.pps001/build/include/linux linux
# ln -s /lib/modules/2.6.26.pps001/build/include/asm asm
# ln -s /lib/modules/2.6.26.pps001/build/include/asm-generic asm-generic
16. timepps.h
Copy the timepps.h file so ntpd gets built with pps support:
# cp /usr/src/pps-tools/timepps.h timepps.h
17. ppstest tool
Build the ppstest tool:
# make
18. Build ldattach
Obtain and build ldattach:
# mkdir ldattach
# cd ldattach
# wget http://www.kernel.org/pub/linux/utils/util-linux-ng/v2.14/util-linux-ng-2.14.2.tar.bz2
# tar jxf util-linux-ng-2.14.2.tar.bz2
# cd util-linux-ng-2.14.2
# ./configure
# make
(build may fail but ldattach should build successfully).
19. Copy ldattach
Copy ldattach:
# cp ldattach /usr/sbin/
20. Load serial line module
Load serial line support module:
# ldattach 18 /dev/ttyS0
(where ttyS0 is the pps com port).
21. Test pps
With the pps source connected to the com port specified above, test pps support:
# ./ppstest /dev/pps0
If successful, time stamp data will be displayed every second.
22. Build ntpd
Obtain and build ntpd:
# mkdir ntp
# cd ntp
# wget http://archive.ntp.org/ntp4/ntp-4.2/ntp-4.2.6p2.tar.gz
# tar zxf ntp-4.2.6p2.tar.gz
# cd ntp-4.2.6p2
# ./configure --enable-all-clocks
# make
# make install
23. Ref clock com port
Use a symbolic link to specify the ref clock com port:
(replace /dev/ttyS1 and /dev/gps1 as required for your server setup and ref clock data format).
24. NTP configuration file
Create ntp.conf file:
# touch ntp.conf
# vim ntp.conf
Edit this file to include pps support and the address of your ref clock:
fudge 127.127.20.1 time2 0.090 # NMEA offset
server 127.127.22.0 minpoll 4 maxpoll 4 # PPS ATOM driver
fudge 127.127.22.0 flag3 1 flag2 1
driftfile /etc/ntp.drift
25. Serial port latency
If you are using a serial reference clock, you are advised to enable 'low_latency' support for the serial driver. This greatly reduces observed jitter on the ref clock. If this is not enabled, ntpd may reject the ref clock as unstable.
The following installs the 'setserial' utility and enables low latency support for ttyS1:
# setserial /dev/ttyS1 low_latency
26. Start ntpd
Start the ntpd daemon:
27. Test ntpd pps support
Test ntpd pps support:
remote refid st t when poll reach delay offset jitter
==============================================================================
*127.127.20.1 .GPS. 0 l 52 64 377 0.000 0.516 0.011
o127.127.22.0 .PPS. 0 l 3 16 377 0.000 -0.001 0.001
(Please note that the pps source will not be selected until ntpd is synchronised to another reference. You may find you need to stop and restart the ntp daemon before the pps source is detected).
Revised March 2012: pps-tools link updated.