Solved ntpd not sync after PC wake up

I have a FreeBSD 14.2 running on VirtualBox VM, and it's using ntpd to sync the time, the rc.conf is as below:

Code:
ntpd_enable="YES"
ntpd_sync_on_start="YES"

it works but if the host PC (MS Windows) has slept for a long time such as 3 hours, when I wake up the PC, the FreeBSD time is not sync anymore and it shows below messages:
ntpd[723]: Clock offset exceeds panic threshold.
ntpd[723]: Set system clock by hand.

I guess it's not the normal way to use FreeBSD that the host PC will sleep :), it is actually for testing purpose, is there any way to overcome it (or let it sync again automatically after wake up)? thanks.
 
Stop ntpd, then either run ntpdate or restart ntpd with the -g option.
Now I'm confused. I thought it was vice versa exactly. My /etc/rc.conf contains:
Code:
# depricated:
# ntpdate_enable="YES"
# use:
ntpd_enable="YES"
ntpd_sync_on_start="YES"
and ntpd is also part of the default installation.... ??? :-/
 
Yes.

Upstream has deprecated ntpdate about ten or more years ago. I don't see it going away any time soon.

ntpdate will be replaced by ntpd -G. Or you can still use ntpdate.

Use ntpd -g to make that first jump when ntpd starts.
 
This ntpd discussion also occurs here once in a while.
Could be fired up even more if leap seconds were braught up 😁

Maybe it produces less confusion if there simply were a template what needs to be written into /etc/rc.conf exactly, or even better, those two lines were not produced automatically by default installation anymore, but the correct ones?
 
I have in /etc/rc.conf:
Code:
ntpd_enable="YES"
ntpd_flags="-g"

I have a FreeBSD VirtualBox VM with Windows 11 as host. When the machine goes in sleep state, the time returns ok at wake up.

Reading ntpd(8), I understand it should do that but once. In fact, the time is synced each time the PC wake up, even several times a day. 🤷‍♂️
 
I understand it should do that but once. In fact, the time is synced each time the PC wake up, even several times a day.
I think even one sync at power up was okay for most users. It is at least for me. The clocks are pretty precisely. Problems occur when the battery becomes depleted, so on old mainboards. But once the machine is powered up and running, and time was set right those clocks normally stay pretty precise for weeks.
Since I don't have no ground control for space ships a second precision is pretty enough for me.

Okay, cleared.
Thanks to both of you!
 
Thanks, I will try to add the ntpd_flags as below to the rc.conf, and see whether the time sync after wake up from 3 hours sleep:

Code:
ntpd_enable="YES"
ntpd_sync_on_start="YES"
ntpd_flags="-g"

I will re-post the result here after the testing, thanks.
 
After testing for 3 to 4 times, I found that the time of FreeBSD VM is not sync after the host PC (it's a notebook) wake up, the FreeBSD time stopped when the host PC slept, then resume counting after wake up, so the time is delayed.

Adding the ntpd_flags="-g" to /etc/rc.conf can prevent the "Clock offset exceeds panic threshold" message from being shown, but the time is still delayed after wake up.

I guess it's because the FreeBSD run on VirtualBox as guest VM, when the host PC slept, the FreeBSD VM pause, when the host PC wake up, the FreeBSD VM resume running, as it is not a restart hence the ntpd does not sync again.

FYI, my host PC (notebook) is running Windows 11, while the VirtualBox is 7.1.6.
 
As others have mentioned, ntpd will not correct the clock if it is too far out of sync. ntpd makes very small adjustments to the clock to keep it synced, so it needs to be close to correct to start with. Use ntpdate to set it with a seconds or so, and then ntpd can handle it.

Also keep in mind that since it is a vm, it should be using the host's clock, making ntpd redundant. You are further ahead of the game making sure the host clock is correct and just using it.
 
I guess it's not the normal way to use FreeBSD that the host PC will sleep :), it is actually for testing purpose, is there any way to overcome it (or let it sync again automatically after wake up)? thanks.
First off: if this isn't a VM where there's some critical aspect to a fast, accurate, automatically adjusting time synchronisation at play from the moment a VM gets 'revived' under all circumstances, then the option first mentioned by cy@ seems one of the most practical ways to go about it.

Generally you have to decide whether you want the VM to have its own synchronisation, via NTP for example, or by employing time syching methods virtualbox is offering in syching to the host OS; having both at work at the same time isn't recommended. For Guest-Host synching, have a look at Fine Tuning Timers and Time Synchronization

It's important to realise when start-up settings like in rc.conf are actually being triggered with respect to an out of sleep awakening Windows host. You didn't mention what procedure you use with respect to the FreeBSD VM when letting the host go to sleep. Options that come to mind:
  1. properly shutting down FreeBSD and the VM
  2. saving the state of the VM
  3. doing nothing - worst possible option
In general, accurate time keeping of VMs when they are not in continuous operation has all sorts of problems, and most of the time needs additional attention; this is not something that usually works automatically right out of the box.
 
For a VM you should use tinker panic 0 to tell ntp not to give up on large time jumps. Large time jumps are a risk for guests.

Reducing hz to 100 is also recommended for FreeBSD (and Linux) guests.
 
Back
Top