28

I am trying to manually set the computer's time in VirtualBox but it always resets itself to what it was before I changed it. How can I disable ntp and tell the system what time I want it to be?

  • Can you give some more details about your problem? Whattime do you want it to be and what time sets your computer? – qbi Apr 17 '11 at 7:05
  • 5
    I want to set an arbitrary wrong time on my computer. – Jeremy Bicha Apr 17 '11 at 7:11
29

I have found a solution. Read the following material: link

Basically if you have Windows host and Ubuntu guest, do the following:

  1. Find a name of your VM (Virtual Machine) - run VB (VirtualBox), select your VM, open settings, in 'General' tab check the name, e.g. in my case Ubuntu 12.04 32bit
  2. In Windows, start a command line interpreter, go to C:\Program Files\Oracle folder and click VirtualBox to select, then holding left shift key, do a mouse right-button click and select "Open command window here" menu, the interpreter has to be running now
  3. Paste the following command (change the VM name to your name!):

    VBoxManage setextradata "Ubuntu 12.04 32bit" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1

  4. Finally, start your Ubuntu guest and set the time and date manually.

  • 6
    this should definitely be the accepted answer! i didn't want to disable guest additions as i have a shared folder mounted in my ubuntu server 14 guest – Jon B Feb 5 '15 at 23:11
  • Unfortunately, it does not "freeze" the time on the guest system. In some scenarios though you want to completely freeze all time (like for doing reproducible builds). – VasyaNovikov Dec 6 '15 at 20:06
  • this just saved me a lot of time – elsadek May 2 '16 at 12:14
  • If your host OS is Ubuntu, the command is: vboxmanage setextradata "your_VM_name_here" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1 – Radu Maris Mar 3 '17 at 8:45
  • See this question, it worked when I tried it: stackoverflow.com/a/45724822/18149 The vboxadd-service needed an extra argument on the guest, mainly --disable-timesync – leeand00 Aug 18 '17 at 1:55
23

As mentioned in another answer, if you are running Ubuntu as a Guest under VirtualBox then you should be aware that the system time is automatically kept in sync by the Guest Additions (i.e., not through an option in the motherboard settings).

Your solution in that case is to disable the Guest Additions, which can be achieved by executing

sudo service vboxadd-service stop

or

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

You can then set the time as desired (from command line using date --set or using the system settings applet)

The VirtualBox service will be restarted at next reboot, or you can do it manually.

  • 3
    Off topic, but disabling/uninstalling Guest Additions allows you to set the system clock on Windows guest OSes as well – speckledcarp Feb 18 '14 at 21:14
  • 3
    In my version of Ubuntu the command was sudo service virtualbox-guest-utils stop. I guess the package was renamed? – Crashthatch Mar 30 '15 at 17:24
  • @Crashthatch your solution is the only one which works. thanks. – Bevor Dec 13 '18 at 12:35
11

The only way is to set the time in the Virtualbox motherboard using the command line:

VBoxManage modifyvm <name> --biossystemtimeoffset <msec>

For example, to set back the date 1 year:

VBoxManage modifyvm <name> --biossystemtimeoffset -31536000000
4

Well, if you want to set arbitrary dates, first you should disable or deinstall ntp.

  • To disable it, open a terminal and run sudo update-rc.d -f ntp remove
  • To deinstall it, use your favorite software management software

After that you can use the date-command to set your system time:

date -s "17 April 2011 12:34:56"
date --set="17 April 2011 12:34:56"

Both commands are equivalent. To only set the time you can use:

date +%T -s "12:34:56" 

The date-manpage has some more format controls. You can use them all to change the date

  • Ok, I've done that but sudo date -s only holds the date for a few seconds before reverting. By that, I mean, running date again shows the time I set working normally but the time indicator in the panel does not, and when I run date again, the time has switched to match the panel clock.....And trying to change the indicator-datetime clock doesn't work either. I think I'm going to have to open a bug. – Jeremy Bicha Apr 17 '11 at 18:23
  • Are you sure that deinstalled/disabled ntp? Do you some other automatic time management software (i.e. chrony) installed? – qbi Apr 20 '11 at 19:33
  • It's a new Natty install in VirtualBox and I purged anything ntp and did not install any other time management software. – Jeremy Bicha Apr 21 '11 at 0:40
  • 2
    Virtualbox „transfers“ the time from your host to the client. You'll have to change some options here. Maybe virtualbox.org/manual/ch03.html#settings-motherboard is helpful. – qbi Apr 21 '11 at 22:40
3

Click on the time & date section of the panel, then the Calendar will appear and underneath that the Time & Date Settings is there so click that.

Click on the Padlock icon and enter your password, then choose Set The Time to manually.

  • I'm going to go ahead and mark this as the best answer for most users. My specific problem was with VirtualBox. – Jeremy Bicha Apr 24 '11 at 6:34
1

In the Software Center look up ntpdate and remove it, or in terminal: sudo apt-get remove ntpdate

(You may have to reboot to fully disable ntp)

Then set your date.

  • Ok, I purged ntpdate and rebooted but I'm still unable to set the system clock and have it stick. – Jeremy Bicha Apr 17 '11 at 7:12
0

Based on the ".ps1" (Windows PowerShell script) example given in

https://superuser.com/questions/539880/using-virtual-box-is-it-possible-to-set-your-virtual-machine-time-to-be-differen

I've written a regular ".bat" script file to change the clock time at which the VirtualBox's virtual machine starts.

The desired start time is set at variable "TEMPO_START_TIMESTAMP" in epoch format. You can get your desired start time epoh equivalent at "http://www.timestampconvert.com/".

The name of the VirtualBox's virtual machine to be started is needed in variable "NOME" (same nomenchature used in the ".ps1" script above).

echo off
echo %time%

set NOME="Windows_7_x64"

set TEMPO_CS_2_MS=0
set TEMPO_S_2_MS=000

rem # Starts the VM always on the date 07/11/2014 - 11h58
rem http://www.timestampconvert.com/

set   TEMPO_START_TIMESTAMP=1415361480

for /f "delims=" %%x in ('cscript /nologo toEpoch.vbs') do set epoch=%%x
rem %epoch%

set TEMPO_CURRENT_TIMESTAMP=%epoch%
rem set TEMPO_CURRENT_TIMESTAMP=1544518714

set /A TEMPO_TEMP=(%TEMPO_START_TIMESTAMP%-%TEMPO_CURRENT_TIMESTAMP%)

call set TEMPO=%TEMPO_TEMP%%TEMPO_S_2_MS%
rem %TEMPO_TEMP%
rem %TEMPO%

c:\Progra~1\Oracle\VirtualBox\VBoxManage setextradata %NOME% "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1
c:\Progra~1\Oracle\VirtualBox\VBoxManage modifyvm %NOME% --biossystemtimeoffset %TEMPO%
c:\Progra~1\Oracle\VirtualBox\VBoxManage startvm %NOME%

You'll also need the current time in epoh format, for this use the following script (save as "toEpoch.vbs", this visual basic script is called from the ".bat" script above):

WScript.Echo DateDiff("s", "01/01/1970 00:00:00", Now())

To run the virtual machine, simply execute the ".bat" script file above. No need to open the "Oracle VM VirtualBox Administration" interface.

I hope this helps.

Regards

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.