Technical Support Centre

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 ncurses-dev
# 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:

# apt-get install linux-source-2.6.26
# 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:

# wget
# 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:

# cp /boot/config-2.6.26-2-686 ./.config

6. Kernel configuration

Start the new kernel build configuration utility:

# make menuconfig

7. Enable PPS support

In the kernel configuration utility, enable the following in 'Device Drivers' > 'PPS support' > :

<M> 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.

{M} 8250/16550 and compatible serial support

9. Exit kernel configuration

Save and exit the kernel configuration utility.

10. Build the kernel

Build the new kernel:

# make-kpkg clean
# 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:

# cd ..
# dpkg -i *.deb

12. Bootloader setup

Change the grub bootloader to select the new kernel at reboot:

# cd /boot/grub
# vim menu.lst

Edit 'default' value as applicable for your new kernel.

13. Reboot


# shutdown -r now

14. Linuxpps tools

After reboot, log on again as root and obtain the linuxpps userland tools:

# cd /usr/src
# git clone git:// pps-tools

15. Kernel header files

Update the kernel header files:

# cd /usr/include
# 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:

# cd /usr/include
# cp /usr/src/pps-tools/timepps.h timepps.h

17. ppstest tool

Build the ppstest tool:

# cd /usr/src/pps-tools
# make

18. Build ldattach

Obtain and build ldattach:

# cd /usr/src
# mkdir ldattach
# cd ldattach
# wget
# 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:

# cd sys-utils
# cp ldattach /usr/sbin/

20. Load serial line module

Load serial line support module:

# sudo modprobe 8250
# 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:

# cd /usr/src/pps-tools
# ./ppstest /dev/pps0

If successful, time stamp data will be displayed every second.

22. Build ntpd

Obtain and build ntpd:

# cd /usr/src
# mkdir ntp
# cd ntp
# wget
# 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:

# ln -s /dev/ttyS1 /dev/gps1

(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:

# cd /etc
# touch ntp.conf
# vim ntp.conf

Edit this file to include pps support and the address of your ref clock:

server mode 8 prefer           # NMEA GPZDA format
fudge time2 0.090              # NMEA offset
server minpoll 4 maxpoll 4     # PPS ATOM driver
fudge 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:

# apt-get install setserial
# setserial /dev/ttyS1 low_latency

26. Start ntpd

Start the ntpd daemon:

# ntpd

27. Test ntpd pps support

Test ntpd pps support:

# ntpq -pn
     remote           refid      st t when poll reach   delay   offset  jitter
*    .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.