The VirtualBox logo, licensed under GPLv2

Fake time in Virtualbox

With programs like faketime (for GNU/Linux systems) or RunAsDate 🗄️ (for Windows systems), it is possible to execute a program in the date and time that you specify, without changing the system clock.

The technique is not perfect, because a program can generally bypass those wrappers; the most obvious way would be to query a webpage that reports the current time.

There is one particular group of application I’m interested with, that fortunately does not rely on the web to work properly: old 32 bit programs that cannot be updated (mostly because the source code is not available).

Those programs might be affected by the Year 2038 problem, thus an easy technique to avoid issues will be to set the clock in the past. NOTE: you might resort to a similar technique to avoid the Year 2000 and Year 2022 problem.

This approach might not work for all programs, for example it would not be feasible for a calendar application, a program that comunicates with over programs over the internet, or anything that prints the current time and you rely on the output.

While faketime/RunAsDate are good enough for different types of program, some programs might not them fool themself, the readme contains some examples 🗄️, and the only way to ensure they work with some time in the past, is to change the time of the operating system, and remove any network access.

Since it is often undesired to work on a system with a clock set incorrectly, a virtual machine is often preferred.

If you use VirtualBox, chances are you are also installing the Guest Additions 🗄️.

They provide different useful features, and they also synchonize the clock of the guest system with the clock of the host.

Thus, if you are changing the clock inside the virtual machine, do not be surprised if the time updates from alone to the current time.

I did not find a way to change this setting from the GUI, but it is possible to disable this feature from the command line 🗄️

vboxmanage setextradata "$NAME_OF_VIRTUAL_MACHINE" 'VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled' 1

Once this command is set, the clock will not be synchronized anymore while the machine is running.

Another useful feature, also only available fro the command-line, is to change the guest BIOS time while starting the virtual machine programmatically.

vboxmanage modifyvm "$NAME_OF_VIRTUAL_MACHINE" --biossystemtimeoffset "$NEGATIVE_AMOUNT_OF_MILLISECONDS"

Unfortunately it is only possible to set an offset, not a fixed point in time.

Thus, if you want your virtual machine to always start as if it is the first January 2000, you need to execute

vboxmanage modifyvm "$NAME_OF_VIRTUAL_MACHINE" --biossystemtimeoffset  $(( ("$(date '+%s' --date '2000-01-01T01:01:01')" - "$(date '+%s')")*1000 ))

With this setup, no matter if a system component or a third party program needs to operate in the past, it should not be an issue.

Together with immutable machines, this makes it possible to create a snapshot frozen in time of the desired environment.


Do you want to share your opinion? Or is there an error, some parts that are not clear enough?

You can contact me anytime.