Note: These instructions were created using Fedora 20, Windows 7 and and Virtual Box 4.3.28.
If you want to change your time information for your Fedora 20 image running inside Virtual Box, you’ve come to the right place. On a recent project, we needed to make Fedora think it was running in a time zone on the other side of the planet. The instructions we found for changing Fedora’s date, time and time zone were pretty straight forward, however, they didn’t quite work. We could get Fedora to accept our change, but it would only last for a few seconds before the time was automatically adjusted by two hours. We had remote synchronization disabled, so nothing should have been resetting the time. After hunting around for a couple hours, we finally realized Virtual Box was trying to adjust the time in Fedora (the guest) to match the time on our Windows host.
First shutdown your Virtual Box image
On your Windows host, open your command prompt and navigate to your Virtual Box folder (this folder might be different on your machine):
cd C:\Program Files\Oracle\VirtualBox
Disable Virtual Box Host - Guest time synchronization. The command below worked for us, but there’s a possibility it might not be a silver bullet. We got the following command from this thread and there are other suggested solutions if the command below doesn’t work:
VBoxManage setextradata [name_of_box_here] "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" "1"
Hopefully, the above command will break the link between Virtual Box and Fedora. If you want to renable the time synchronization in the future, execute:
VBoxManage setextradata [name_of_box_here] "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" "0"
Now fire up your Fedora VM and open a terminal. Some of the commands below may need to be executed as root so you might need to do a sudo su to become root. Try running with regular sudo first. (Most of the commands below were taken from the Fedora docs.
To see your current time information, execute:
timedatectl # show current time info
Now turn off remote time synchronization (which is different from the Virtual Box time sync we disabled above). This will tell Fedora to stop trying to automatically update the time with it’s remote time servers:
sudo timedatectl set-ntp no # set to 'yes' (without the apostrophes) to re-enable
To find a list of available time zones, execute:
sudo timedatectl list-timezones # Show all time zones sudo timedatectl list-timezones | grep America # Filter time zone list
After selecting a time zone, you can set it with:
sudo timedatectl set-timezone America/New_York # Switch to Eastern time sudo timedatectl set-timezone Pacific/Guam # Swith to Guam time
Now set the date and time using a combination of yyyy-mm-dd hh:mm:ss. The time date/time should be in the context of the whatever time zone is set. So, if the time zone is “America/New_York”, then 15:05:00 means it is 3:05pm on a clock on the wall in New York.
1 2 3
sudo timedatectl set-time "2016-04-14 15:05:00" # Set date and time sudo timedatectl set-time 2016-04-14 # Set date, this will set your time to 00:00:00 sudo timedatectl set-time 15:05:00 # Set time, leave date alone
We hope you found this article useful. If you see any mistakes, missing features or ways to improve it, please let us know in the comments below so we can update its contents. If you're willing to link to us, we would sincerely appreciate it!