Using rdate(8) for VM Time Correction
If you suspend an OpenBSD virtual machine in VMWare Fusion, its clock will not automatically update when you resume. To fix this by hand, you can use the rdate(8) command (as root).
rdate
will update the system's clock using
an NTP server that you provide as an argument. For example, to sync your VM
with Cloudflare Time
Services, you can run the following:
# rdate time.cloudflare.com
But why should you have to do this yourself? Shouldn't this be
easy for the computer to automate? Well, yes, but as with most time
problems, the answer is tricky. If you call rdate
as
mentioned above, you will make the computer skip forward in time. If your VM
has been suspended for a long time, this could cause problems with
time-sensitive applications, like databases. This is usually not an issue on
a desktop or a development host.
To safeguard against this scenario in a production environment, OpenBSD's ntpd(8) server will slowly adjust the time until it matches the time of the outside world. To see this in action, you can compare the UNIX timestamp of your OpenBSD virtual machine with that of your workstation:
echo "$(date +%s) - $(ssh your-openbsd-vm date +%s)" | bc
This will run date(1) on your local machine to get the current UNIX timestamp (which we are assuming is up-to-date), and then it will run the same command on your OpenBSD VM. It will then pass those two figures as a subtraction problem to the bc(1) calculator command, which will print the difference (in seconds).
If you run this command again in 10-20 minutes, you will
see that the difference between the two hosts will have shrunk by a few
seconds. This is because ntpd
is bringing the
virtual machine into sync
very slowly in order
to minimize confusion for time-sensitive applications.
ntpd
accomplishes this by using the
adjtime(2) system call, which requires root privileges.
If you want to learn more about ntpd
, your
best resource is the
ntpd.conf(5) man page. This is pretty common for OpenBSD
daemons: the manual for the daemon contains only basic information about the
flags you'd use in
rc.conf(8), but the manual for the config file contains much
more information about how the daemon works, what features it supports,
etc.