3

I've installed Ubuntu 16.04.1 LTS in VirtualBox and tried to change the time zone via timedatectl set-timezone Europe/Berlin as root user. Unfortunately, this didn't work and I got the output

Failed to set time zone: Access denied

I know about the option to manually remove the /etc/localtime link and create a new link to /usr/share/zoneinfo/Europe/Berlin, but this is not very practical and I don't understand why timedatectl does not work.

Further system information which might help:

$ ls -la /etc | grep localtime
lrwxrwxrwx 1 root    root       27 Feb 14 07:48 localtime -> /usr/share/zoneinfo/Etc/UTC
$ ls -la /usr/share/zoneinfo/Europe/ | grep Berlin
-rw-r--r-- 1 root root 2335 Dec  7 10:59 Berlin

EDIT: I noticed additional strange behavior. Although the Access denied error is thrown, the time zone is changed. And after a while it is set back to UTC :/

root@ces:/home/vagrant# timedatectl
      Local time: Tue 2017-02-14 11:27:31 CET
  Universal time: Tue 2017-02-14 10:27:31 UTC
        RTC time: Tue 2017-02-14 08:17:50
       Time zone: Europe/Belgrade (CET, +0100)
 Network time on: yes
NTP synchronized: no
 RTC in local TZ: no
root@ces:/home/vagrant# timedatectl set-timezone Europe/Berlin
Failed to set time zone: Access denied
root@ces:/home/vagrant# timedatectl
      Local time: Tue 2017-02-14 11:27:40 CET
  Universal time: Tue 2017-02-14 10:27:40 UTC
        RTC time: Tue 2017-02-14 08:17:59
       Time zone: Europe/Berlin (CET, +0100)
 Network time on: yes
NTP synchronized: no
 RTC in local TZ: no
root@ces:/home/vagrant# timedatectl
      Local time: Tue 2017-02-14 10:28:32 UTC
  Universal time: Tue 2017-02-14 10:28:32 UTC
        RTC time: Tue 2017-02-14 08:18:50
       Time zone: Etc/UTC (UTC, +0000)
 Network time on: yes
NTP synchronized: no
 RTC in local TZ: no

EDIT: I'm installing the system automatically using packer. This includes using a preseed file which includes the following lines:

d-i clock-setup/utc boolean true
d-i clock-setup/utc-auto boolean true
d-i time/zone string UTC

Removing the last line kind of solves the problem, but it leads to a question during the install process (the timezone is estimated and I should confirm by pressing "yes") which destroys the automation.

0
1

Assuming that you have the Guest Additions installed ... from the VirtualBox manual: "The VirtualBox Guest Additions ensure that the guest's system time is synchronized with the host time." Further on: "There are several parameters which can be tuned."

Disabling the Guest Additions time synchronization:
Once installed and started, the VirtualBox Guest Additions will try to synchronize the guest time with the host time. This can be prevented by forbidding the guest service from reading the host clock:

VBoxManage setextradata "VM name" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1  

Now you know the root cause for what you call "strange behavior" and once you turned off the default setting which automatically synchronizes the guest time with the host time, you should be able to set the time zone within the guest system permanently.

Reference: Official VirtualBox manual Chapter 9.14 -> Fine-tuning timers and time synchronization

11
  • Unfortunately the VBoxManage command didn't solve the problem, I still get 'Access denied'. As I am firing Virtualbox up via vagrant, are there any other mechanisms I have to consider? I even tried to include the command into my Vagrantfile, but it didn't work either. – Robert Feb 16 '17 at 14:32
  • The time settings are not persistent, although I've made the right setting: VBoxManage getextradata "xyz_default_1487255766394_70950" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" leads to Value: 1 – Robert Feb 20 '17 at 7:32
  • @Robert This seems most probably to be more a bug within the VirtualBox application rather than in the Ubuntu operating system ... so, you should contact the VirtualBox developers - or ask for a solution in the VirtualBox forums. :) – cl-netbox Feb 20 '17 at 12:41
  • Is there any security module like SELinux or something active in Ubuntu by default? Could this maybe lead to problems altering the timezone? – Robert Feb 23 '17 at 12:57
  • @Robert apparmor is the security module in Ubuntu, but if that is the root cause ... ? :) – cl-netbox Feb 23 '17 at 13:27

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.