Tuesday, 28 January 2020

virtualbox - 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.



Answer



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:



No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...