0

I'm trying to set a fake time on Ubuntu 18.04 (systemd 237) for purposes of testing an execution of a monthly periodic task.

This is running on a virtual machine (virtualbox with guest additions).

The time resets itself back to correct time after a few seconds even though ntp syncing was disabled.

Example.

# Disable the sync
timedatectl set-ntp 0
# There aren't any ntp daemons running
systemctl -a | grep ntp    # Returns nothing

# This confirms there is no sync active
timedatectl status         
#                       Local time: Mo 2019-03-11 15:22:13 CET
#                   Universal time: Mo 2019-03-11 14:22:13 UTC
#                         RTC time: Mo 2019-03-11 14:22:13    
#                        Time zone: Europe/Berlin (CET, +0100)
#        System clock synchronized: no                        
# systemd-timesyncd.service active: no                        
#                  RTC in local TZ: no           

# Setting up the fake time       
timedatectl set-time '2015-11-20 16:14:50'

# It worked! Wuhuu!
timedatectl status         
#                       Local time: Fr 2015-11-20 16:14:51 CET
#                   Universal time: Fr 2015-11-20 15:14:51 UTC
#                         RTC time: Fr 2015-11-20 15:14:51    
#                        Time zone: Europe/Berlin (CET, +0100)
#        System clock synchronized: no                        
# systemd-timesyncd.service active: no                        
#                  RTC in local TZ: no

# 5 sec later
timedatectl status         
#                       Local time: Mo 2019-03-11 15:25:35 CET
#                   Universal time: Mo 2019-03-11 14:25:35 UTC
#                         RTC time: Fr 2015-11-20 15:14:51    
#                        Time zone: Europe/Berlin (CET, +0100)
#        System clock synchronized: no                        
# systemd-timesyncd.service active: no                        
#                  RTC in local TZ: no

If there is no sychronisation service, what is keeping it in sync?

  • is this a VM with vmware tools installed? – Jeff Schaller Mar 11 at 14:39
  • @JeffSchaller Yup. Good catch, didn't think this would be important. Expanding the question. It's virtual box with guest additions actually. – TheMeaningfulEngineer Mar 11 at 14:50
2

If there is no sychronisation service, […]

But there is. It is built into the VirtualBox service that runs in the guest operating system.

The VBoxService service in the guest operating system unfortunately does a lot of things all in one, and stopping it entirely eliminates everything that it does. The only fine-grained control available, since control via native service management tools is not, is Oracle's tool:

VBoxManage setextradata "VM name" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1

This does not disable the synchronization service thread per se. It makes the hypervisor call that the thread invokes return failure. The synchronization service thread continues to run. It just repeatedly fails to obtain the host time.

Further reading

0

This seems to be caused by a service from the VM to sync with the host system. In my case (Virtualbox) disabling the service solved the problem.

systemctl stop vboxadd-service.service

There are more sophisticated solutions specified in other answers/comments but they require executing a step on the host side. For my case this was simpler to document given that all the testing related to this mock needs to be executed on the guest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.