Stop Ubuntu From Automatically Updating the Time

I just need to set the date temporarily. I run this

date 051918002010.00

and it sticks for just 5 seconds or so. Then it syncs with the time server. I have tried:

ps aux | grep ntp

but there is nothing there.

I need a correct answer now, more than a more detailed answer later :)

Edit: As answerers quickly discovered, my Ubuntu is running in a VirtualBox, which turned out to be relevant for some versions of the answer. Thanks to everybody.


Solution 1:

It sounds like you're really looking for a way to run a program so that the program thinks it's running under a different date and time.

An earlier question was asked about this: Linux RunAsDate analogue? Below is the answer I gave there. Note you seem to be attempting Option 3.

The ntpdate package isn't a daemon and should not be updating your system time automatically (it should run once at boot and no more). I'm not overly familiar with VirtualBox, but I'd guess you've either got ntpd installed or the VirtualBox Guest Additions are syncing the time directly from the host OS, in which case you'll need to disable them, or use one of the wrapper libraries mentioned below in Option 2.

Update: It looks like the VirtualBox Guest Additions install /usr/sbin/vboxadd-timesync -- I'd guess this is the executable that syncs the guest clock with that of the host. Check to see if it's installed a startup script (possibly /etc/init.d/vboxadd-timesync); if so, you can stop the sync with sudo /etc/init.d/vboxadd-timesync stop. If no startup script, you can probably just kill the process.


What RunAsDate does is the following:

RunAsDate intercepts the kernel API calls that returns the current date and time (GetSystemTime, GetLocalTime, GetSystemTimeAsFileTime), and replaces the current date/time with the date/time that you specify.

Under Linux you have some options to accomplish the same thing:

  1. If you can get a Windows version of the program, you might be able to run RunAsDate under Wine (but watch out for a recent bug).

  2. Find a wrapper library to do this, or write your own. Some options are given below.

  3. Use a Virtual Machine. This is overkill, but since an OS in guest VM is completely separate from the underlying host, you can set it's system time to something completely different. It may be quicker to setup than the other options.


Option 2 can be accomplished by different methods, depending on the what you're trying to run. DaveParillo's answer below links to a DIY approach that explains the different methods and includes code for an executable. Some other options include:

  • datefudge, available in Debian/Ubuntu repositories and other places.

  • Time-Fake perl module, also in Debian repositories as package libtime-fake-perl.

  • FakeTime Preload Library (aka libfaketime, freshmeat link), a library that can intercept system calls in dynamically-linked binaries. Available in Debian repositories for Squeeze and Sid.

Solution 2:

Since your comment response to Dan McG seems to indicate that you're running Ubuntu as a VirtualBox guest, if you've installed the VirtualBox guest additions, then they will automatically sync the guest's time with the host's.

ps -ef | grep VBoxService

should show the VirtualBox guest additions service running.

You could then try:

sudo /etc/init.d/vboxadd-service stop

to stop it until reboot.