VirtualBox

Opened 11 years ago

Last modified 8 years ago

#11980 new defect

guest additions should write system time to RTC after adjusting it

Reported by: Sam Morris Owned by:
Component: other Version: VirtualBox 4.2.16
Keywords: Cc:
Guest type: Linux Host type: Windows

Description

When booting a Linux distribution using systemd, the system time is not automatically written to the RTC during shutdown. For further information & rationale, see <http://lists.freedesktop.org/archives/systemd-devel/2011-May/002526.html>.

As a result, booting my system under VirtualBox results in the following:

Jul 22 03:46:06 wintermute kernel: rtc_cmos rtc_cmos: setting system clock to 2013-07-22 02:46:03 UTC (1374461163)
...
Jul 22 03:46:07 wintermute systemd-fsck[443]: /dev/sdb1: Superblock last write time is in the future.
Jul 22 03:46:07 wintermute systemd-fsck[443]: (by less than a day, probably due to the hardware clock being incorrectly set).  FIXED.
Jul 22 03:46:07 wintermute systemd-fsck[443]: /dev/sdb1: clean, 340335/39321600 files, 138917904/157286139 blocks
...
Jul 22 03:46:08 wintermute systemd[1]: Started LSB: VirtualBox Linux Additions.
Jul 22 13:57:43 wintermute systemd[1]: Time has been changed

After boot, we can observe the RTC is still wrong:

$ date
Mon 22 Jul 14:10:15 BST 2013

# hwclock -r
Mon 22 Jul 2013 03:58:44 BST  -0.070616 seconds

After the guest editions have set the system clock from the host clock, they should set the hardware clock to match. That is, perform the equivalent of hwclock --systohc.

Attachments (1)

37-save-system-time-to-rtc.patch (3.4 KB ) - added by Sam Morris 8 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by Sam Morris, 11 years ago

Workaround: write the system time to the RTC during shutdown by creating /etc/systemd/system/vbox-hwclock.service and then running running systemctl daemon-reload && systemctl enable vbox-hwclock.service.

[Unit]
Description=Save system time to RTC
Documentation=https://www.virtualbox.org/ticket/11980
Before=shutdown.target
DefaultDependencies=no

[Service]
ExecStart=/sbin/hwclock --systohc
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=shutdown.target
Last edited 11 years ago by Sam Morris (previous) (diff)

comment:2 by Sam Morris, 10 years ago

Updated version of the above service:

[Unit]
Description=Save system time to RTC before shutdown
Documentation=https://www.virtualbox.org/ticket/11980
Before=final.target
DefaultDependencies=no

[Service]
ExecStart=/sbin/hwclock --systohc
Type=oneshot

[Install]
WantedBy=final.target

by Sam Morris, 8 years ago

comment:3 by Sam Morris, 8 years ago

This patch modifies VBoxService to write the system time to the RTC after it updates the system time.

comment:4 by Frank Mehnert, 8 years ago

Thank you for bringing this problem to our attention. Your patch might work but I would rather not synchronize the RTC every time the system clock is updated because this could happen every 5 seconds. I think the better approach is to use the adjtimex() system call and to clear the STA_UNSYNC status flag. Doing so will start a kernel thread which will automatically synchronize the system clock to the RTC every 11 minutes. As an alternative we could also synchronize the RTC once when VBoxService is terminated. We have to think about this a bit more.

comment:5 by Sam Morris, 8 years ago

Hi frank, that's fair enough and I agree that relying on '11 minute mode' is a superior solution. Thanks for looking at the issue!

Note: See TracTickets for help on using tickets.

© 2023 Oracle
ContactPrivacy policyTerms of Use