ntpd_enable="YES"
ntpdate_enable="YES"
gordon@ said:In FreeBSD, I recommend you use both ntpdate and ntpd. ntpdate will set the clock when you first boot so it's close enough that ntpd will work with it.
You can just add the following to /etc/rc.conf:
Code:ntpd_enable="YES" ntpdate_enable="YES"
Then read through /etc/ntp.conf. It's pretty well documented so it should be pretty obvious what to set.
#----------ntp config
ntpd_enable="YES"
ntpd_sync_on_start="YES"
Thanks, rbelk, that works for me. When I tried it the other way, it was giving me errors saying "hostname nor servname provided" and "cannot find host" or "cannot resolve host" or something along those lines. Now it's working fine.ntpd_enable="YES"
ntpd_sync_on_start="YES"
gilinko said:Or install openntpd from ports, which is much simpler and in my opinion works a lot better then the native ntpd daemon. No need to worry about stratum or anything else like that, just point it at a ntp server and let it go. However do use ntpdate to set the time and date on boot, to always have a good clock to start with.
Addtinker panic 0
to /etc/ntp.conf.
ntp.conf(5):Tried it, still required ntpd service restart
[...]
tinker [allan allan | dispersion dispersion | freq freq | huffpuff
huffpuff | panic panic | step step | stepback stepback |
stepfwd stepfwd | stepout stepout]
This command can be used to alter several system variables in
very exceptional circumstances. It should occur in the config-
uration file before any other configuration options.
tinker panic 0
does not work immediately after a wake up of the VM.files=`rcorder ${rcorder_opts} /etc/rc.d/* ${local_rc} 2>/dev/null`
for _rc_elem in $files; do
debug "run_rc_script $_rc_elem resume"
run_rc_script $_rc_elem resume
done
ntpd_resume()
{
run_rc_command restart
}
Tried it, still required ntpd service restart
If the last quote means that when a VM is awakened/started ntpd goes through a restart (=stop followed by a start) just as during a normal boot, then the desired effect of quickly synchronising by use of ntpd should be attainable with a combination of the use of/etc/rc.resume actually restarts /etc/rc.d/ntpd.
iburst
* and ntpd_sync_on_start
. These commands are perhaps likely to synch even quicker than with the tinker panic 0
directive and IMO preferable to the tinker directive as this directive also stays in effect after the initial synching.USAGE
How NTP Operates
[...]
Finally, in the past many startup scripts would run ntpdate(8) or
sntp(8) to get the system clock close to correct before starting
ntpd(8), but this was never more than a mediocre hack and is no longer
needed. If you are following the instructions in "Starting NTP (Best
Current Practice)" and you still need to set the system time before
starting ntpd, please open a bug report and document what is going on,
and then look at using sntp(8) if you really need to set the clock be-
fore starting ntpd.
There is a way to start ntpd(8) that often addresses all of the prob-
lems mentioned above.
Starting NTP (Best Current Practice)
First, use the iburst option on your server entries.
If you can also keep a good ntp.drift file then ntpd(8) will effec-
tively "warm-start" and your system's clock will be stable in under 11
seconds' time.
As soon as possible in the startup sequence, start ntpd(8) with at
least the -g and perhaps the -N options. Then, start the rest of your
"normal" processes. This will give ntpd(8) as much time as possible to
get the system's clock synchronized and stable.
Configuration Commands
[...]
iburst When the server is unreachable, send a burst of eight packets
instead of the usual one. The packet spacing is normally 2 s;
however, the spacing between the first two packets can be
changed with the calldelay command to allow additional time for
a modem or ISDN call to complete. This is designed to speed
the initial synchronization acquisition with the server command
and s addresses and when ntpd(8) is started with the -q option.
ntpd_sync_on_start
(bool) If set to "YES", ntpd(8) is run with the -g flag,
which syncs the system's clock on startup. See ntpd(8) for
more information regarding the -g option. This is a pre-
ferred alternative to using ntpdate(8) or specifying the
ntpdate_enable variable.
pool 0.nl.pool.ntp.org iburst
pool 1.nl.pool.ntp.org iburst
pool 2.nl.pool.ntp.org iburst
pool 3.nl.pool.ntp.org iburst
ntpd_enable="YES"
ntpd_sync_on_start="YES" #sync time at startup in a big leap; after that gentle clock synchronization
ntpd_oomprotect="YES" # protect ntpd from being killed by the system attempting to recover from an Out Of Memory (OOM) condition.
ntpd_oomprotect
to protect ntpd from falling prey to OOM.burst
, How do I use pool.ntp.org?:Be friendly. Many servers are provided by volunteers, and almost all time servers are really file or mail or webservers which just happen to also run ntp. So don't use more than four time servers in your configuration, and don't play tricks with burst or minpoll - all you will gain is extra load on the volunteer time servers.
qemu_guest_agent_enable="YES"
in /etc/rc.conf didn't help. i.e. ntpd was not restarted after closing the lid for 5 minutes, and opening it again.# On the FreeBSD client, install and configure the guest agent
pkg install qemu_guest_agent
# Add the following to /boot/loader.conf
virtio_console_load="YES"
# Add the following to /etc/rc.conf
qemu_guest_agent_enable="YES"
qemu_guest_agent_flags="-d -v -l /var/log/qemu-ga.log -p /dev/ttyV0.2"
# Shutdown the FreeBSD KVM client
sudo shutdown -p now
# On the KVM server, enable communication with the guest agent.
# A side effect is that this will cause the creation of /dev/ttyV0.2 on the client.
host=gunsynd # name of the FreeBSD client
sudo EDITOR=vi virsh edit $host # Add the following after the first "</channel>" you find
<channel type='unix'>
<target type='virtio' name='org.qemu.guest_agent.0'/>
</channel>
[gunsynd.139] $ sudo service qemu-guest-agent status
qemu_guest_agent is running as pid 699.
[gunsynd.140] $ ls -la /dev/vtcon/
total 1
dr-xr-xr-x 2 root wheel 512 Nov 6 12:30 .
dr-xr-xr-x 10 root wheel 512 Nov 6 12:28 ..
lrwxr-xr-x 1 root wheel 10 Nov 6 12:30 com.redhat.spice.0 -> ../ttyV0.1
lrwxr-xr-x 1 root wheel 10 Nov 6 12:30 org.qemu.guest_agent.0 -> ../ttyV0.2
[gunsynd.141] $ ls -lad /dev/ttyV*
crw------- 1 root wheel 0x38 Nov 6 12:30 /dev/ttyV0.1
crw------- 1 root wheel 0x39 Nov 6 13:05 /dev/ttyV0.2
[farlap.1365] $ host=gunsynd
[farlap.1366] $ sudo virsh qemu-agent-command $host '{"execute":"guest-get-osinfo"}'
{"return":{"name":"FreeBSD","kernel-release":"13.3-RELEASE-p7","version":"13.3-RELEASE-p8","pretty-name":"FreeBSD 13.3-RELEASE-p8","version-id":"13.3","kernel-version":"FreeBSD 13.3-RELEASE-p7 GENERIC","machine":"amd64","id":"freebsd"}}
[gunsynd.130] $ sudo cat /var/log/qemu-ga.log
1730856559.605833: debug: read data, count: 59, data: {"execute":"guest-sync", "arguments":{"id":1730856686717}}
1730856559.605941: debug: process_event: called
1730856559.605952: debug: processing command
1730856559.605981: debug: sending data, count: 26
1730856559.608536: debug: read data, count: 70, data: {"execute":"guest-set-time","arguments":{"time":1730856686717444419}}
1730856559.608590: debug: process_event: called
1730856559.608597: debug: processing command
1730856686.717506: debug: g_unix_open_pipe() called with FD_CLOEXEC; please migrate to using O_CLOEXEC instead
1730856686.718338: debug: sending data, count: 112
sudo apt install acpid
sudo cat - >>/etc/acpi/events/lm_lid <<'EOF'
event=button/lid.*
action=/etc/acpi/lid.sh
EOF
sudo cat - >>/etc/acpi/lid.sh <<'EOF'
#!/bin/sh
# https://linuxconfig.org/how-to-handle-acpi-events-on-linux
# https://askubuntu.com/questions/517683/laptop-doesnt-hibernate-when-i-close-the-lid-in-ubuntu-14-04/518825#518825
# NOTE: runs as root
export PATH=/bin
LOGTAG='LaptopLid'
LOGPRI='local0.notice'
if grep -q open /proc/acpi/button/lid/LID0/state >/dev/null 2>&1
then
logger -p "$LOGPRI" -t "$LOGTAG" "lid opened"
VMclients=$(virsh list | grep running | awk '{print $2}')
for host in $VMclients
do
virsh qemu-agent-command $host "{\"execute\":\"guest-set-time\",\"arguments\":{\"time\":$(date +%s%N)}}"
done
fi
sudo chmod a+x /etc/acpi/lid.sh
EOF