From 5643f1db6c946b57bf65d723e4cf84c7cb6f2ab6 Mon Sep 17 00:00:00 2001 From: Randy Bush Date: Sat, 4 Jul 2020 14:32:43 -0700 Subject: [PATCH] from wiki --- pages/GuestNTP.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 pages/GuestNTP.md diff --git a/pages/GuestNTP.md b/pages/GuestNTP.md new file mode 100644 index 0000000..9e6cdcd --- /dev/null +++ b/pages/GuestNTP.md @@ -0,0 +1,55 @@ +# Setting Up NTP in a Guest + +I read on the Internet, so it must be true, that a kvm guest defaults to a clock source of "kvm-clock", which sets the guest's TSC clock to the host's. But this is at boot, and the guest then runs a virtual TSC from boot on out. This can yield poor results. To see what clocking is being used, + +``` +$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource +``` + +which, in the default configuration, yields "kvm-clock", meaning that the guest's TSC was set to the host's TSC when the guest booted, and has been drifting on the virtual sea ever since. This is not a good thing. + +So, setting up ntpd is advised, at least if you want better than the average time source. + +First, you need to install NTP, which also starts it + +``` +$ apt-get install ntp +``` + +Though not absolutely necessary, I also like to have a known stratum-1 in the configuration, so I add the following line to /etc/ntp.conf + +``` +server my.strat.1 +``` + +You then have to whack the NTP daemon so it sees the configuration change + +``` +$ service ntp restart +``` + +Wait a minute and then check that ntpd is OK + +``` +$ ntpq -p +``` + +There is one remaining problem. the ntp daemon is setting the guest TSC which conflicts with the kvm-clock syncing the TSC off the host's clock. To see what clocking is being used, try + +``` +$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource +``` + +which should yield the default "kvm-clock". As you do not want this, to disable kvm-clock, you have to add + +``` +no-kvmclock +``` + +to the kernel grub invocation parameter list. After rebooting with the kernel config change + +``` +$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource +``` + +should show "tsc" as opposed to "kvm-clock". This is saying that the guest is using its internal TSC, a virtual hardware clock, which we have arranged to maintained by the ntpd daemon in the guest. \ No newline at end of file