VirtualBox

Ticket #11980 (new defect)

Opened 3 years ago

Last modified 3 months ago

guest additions should write system time to RTC after adjusting it

Reported by: yrro Owned by:
Priority: minor 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

37-save-system-time-to-rtc.patch Download (3.4 KB) - added by yrro 3 months ago.

Change History

comment:1 Changed 3 years ago by yrro

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 3 years ago by yrro (previous) (diff)

comment:2 Changed 22 months ago by yrro

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

Changed 3 months ago by yrro

comment:3 Changed 3 months ago by yrro

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

comment:4 Changed 3 months ago by frank

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 Changed 3 months ago by yrro

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.

www.oracle.com
ContactPrivacy policyTerms of Use