Using NTPD in a Ubuntu 8.04 Xen Virtual Machine

August 02, 2008 · 2 min read

It’s a good idea to have an accurate clock on any computer you access. Beyond the obvious convenience, consistent timestamps across your infrastructure make log analysis and event replays far more reliable. Unfortunately, clocks drift over time. NTP – the Network Time Protocol – keeps things honest by synchronising your clock against a group of reference servers on the internet.

There’s a wrinkle, though: Xen guests (such as those provided by Xeriom Networks) have their clocks tied to the Xen host by default. Here’s how to break free and get NTP running properly.

Taking a shortcut

If you’re running a Ubuntu-based VM and you use the package host at Xeriom Networks, one command does the lot:

sudo apt-get install xeriom-ntp-client --yes --force-yes

Gaining independence

To stop your VM’s clock being slaved to the host, tell the kernel the clock is independent:

sudo su -c "echo 1 > /proc/sys/xen/independent_wallclock"

To make this persist across reboots, add the following line to /etc/sysctl.conf:

xen.independent_wallclock = 1

Installing and configuring NTPD

Install the NTP daemon via apt-get:

sudo apt-get install ntp --yes

If you’re on one of Xeriom’s VMs you can use time.xeriom.net as a time source. Edit /etc/ntp.conf to include it alongside a few servers from your nearest NTP pool:

server time.xeriom.net prefer
server 0.uk.pool.ntp.org
server 1.uk.pool.ntp.org
server 2.uk.pool.ntp.org

Restart NTP and you’re done:

sudo /etc/init.d/ntp restart

What’s the time, Mr. Wolf?

NTP takes roughly 15 minutes to settle down and select the best time source. You can check its progress with ntpq -p:

ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*time.xeriom.net 212.13.194.87    3 u   39   64  377    0.402  -45.729   7.496
+dns1.rmplc.co.u 195.66.241.3     2 u   39   64  377    3.443  -54.808   6.142
+ntpt1.core.thep 194.152.64.68    3 u   40   64  377    0.723  -53.765   5.965
+weevil.pwns.ms  249.240.53.144   2 u   38   64  377    9.110  -57.739  11.427

The * marks the currently selected source, and + indicates candidates NTP might switch to. For a more detailed breakdown of this output, the Novell documentation is worth a read.

Now there’s no excuse for being late

That’s it – your Xen guest now keeps its own time, synchronised properly via NTP. No more mysterious timestamp drift in your logs.

These posts are LLM-aided. Backbone, original writing, and structure by Craig. Research and editing by Craig + LLM. Proof-reading by Craig.