Stop Ubuntu From Automatically Updating the Time

6,132

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:

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.

Solution 3

Quick Answer: Disconnect your network connection :)

Solution 4

You could also look at 'libfaketime', which is packaged in Ubuntu/Debian.

It allows you to fake system time for a program without having to change the system-wide time (by intercepting the system calls by using LD_PRELOAD)

Solution 5

You can run VBoxManage setextradata <guest-vm-name> "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1 on your host OS to disable automatic time sync.

Share:
6,132

Related videos on Youtube

Dan Rosenstark
Author by

Dan Rosenstark

When I was born, I knew nothing about programming. Projects MIDI Designer Pro for iPad, iPhone, iPod touch—dream | create | play your Perfect MIDI Controller on iOS MJDJ—Desktop Java application for MIDI Morphing (transforming) Handsonic Editor—Powerful and popular editor for the Roland Handsonic HPD-15 The KBase—A multi-hierarchical text editor (.Net standalone and Web versions) Technical rambles (blog) Contact Contact me via MIDIdesigner.com

Updated on September 17, 2022

Comments

  • Dan Rosenstark
    Dan Rosenstark over 1 year

    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.

    • Admin
      Admin over 14 years
      Why you are trying to do this, what is the purpose?
    • Admin
      Admin over 14 years
      development, simulating situations.
  • Dan Rosenstark
    Dan Rosenstark over 14 years
    I'm not even sure how to do that, since it seems to be getting time from... the VirtualBox host? Or perhaps... not sure, but disconnecting the Internet did not help.
  • Jeffrey Vandenborne
    Jeffrey Vandenborne over 14 years
    If you're using a wired network, check out the network icon in the top panel (I assume you didn't tweak your desktop) click it and choose disconnect.
  • Dan Rosenstark
    Dan Rosenstark over 14 years
    Problem is that nntp continues, it seems, as it does gradual updates. In any case, the time sync does not stop without internet connectivity.
  • Jeffrey Vandenborne
    Jeffrey Vandenborne over 14 years
    sudo apt-get remove ntpdate
  • Dan Rosenstark
    Dan Rosenstark over 14 years
    I'll try cutting the network connection on the guest then.
  • Jeffrey Vandenborne
    Jeffrey Vandenborne over 14 years
    Smart thinking there, everything is so clear now, cheers!
  • Nick Meyer
    Nick Meyer over 14 years
    @Yar, I'm not sure it goes through the virtual network connection on the guest. It probably gets the hosts' system clock value through the VirtualBox process.
  • Jeffrey Vandenborne
    Jeffrey Vandenborne over 14 years
    @Nick Isn't there a config file or configuration dialog available for the vbox guest additions? Maybe he can change the time syncing there. coming from vmware, I don't got a lot of experience with this.
  • Dan Rosenstark
    Dan Rosenstark over 14 years
    this was great stuff, but: 1) While I am running as a VirtualBox guest, the VBoxService is not loaded (I never did the extensions, I guess) 2) vboxadd-service does not exist 3) even killing both network connections causes the time to be restored in a matter of seconds
  • Nick Meyer
    Nick Meyer over 14 years
    @Jeffrey, I'm not sure; I've never tried to configure them. I would have to refer to the VirtualBox documentation. @Yar, What version of VirtualBox are you running? The name may have changed (I verified my answer against 3.1.0) since previous versions. Double-check the documentation for your VBox version.
  • Dan Rosenstark
    Dan Rosenstark over 14 years
    sudo /etc/init.d/vboxadd-timesync stop worked! Thanks so much ~quack
  • Dan Rosenstark
    Dan Rosenstark over 14 years
    Wow, datefudge works perfectly on Ubuntu as well. Very sweet. Thanks again!
  • Dan Rosenstark
    Dan Rosenstark over 14 years
    Just for my notes if you don't mind: datefudge "Wed Dec 16 15:20:28 EST 2008" ruby script/console
  • Dan Rosenstark
    Dan Rosenstark over 14 years
    Thanks Nick, got to this too late. VirtualBox version is 3.0.12, but ~quack's answers worked.
  • Radu Maris
    Radu Maris over 10 years
    The only thing missing at the beginning of the answer is: "Don't be evil when using this info".