EC2 Micro Instance Clock Drift

Recently I’ve been experimenting with the Amazon Free Tier micro instances (one is running this blog). After running an instance for a few days I noticed that the clock seems to drift quite heavily ( more than 10 minutes over 24 hours ).

The most obvious fix to any clock drift is to install and configure ntp – however in this case it didn’t seem to make a lot of difference. The solution in the end was to configure ntp

and to set the value of sys.xen.independent_wallclock to 1 with this command:

echo 1 > /proc/sys/xen/independent_wallclock

And to add this line to /etc/sysctl.conf ( in Gentoo anyway, other operating systems may have this in a slightly different path ):

xen.independent_wallclock=1

This apparently stops the machine from relying on the xen host ( ie the physical server the VM is running on ) and lets it use its own clock, allowing NTP to fix the clock correctly.