-1

I have created a Windows 2012 virtual machine using libvirt/QEMU. The hypervisor(bare metal) on which the VM is running is based on UTC time zone but the time zone in Windows VM should be Arizona time zone. I was able to fix the drift in the time using the below timer definition in the libvirt xml

<clock offset='localtime'>
    <timer name='hypervclock' present='yes'/>
    <timer name='rtc' tickpolicy='catchup' track='guest'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
</clock>

But as soon as I restart the VM, the time shifts back to UTC but the time zone still shows as Arizona time zone which is wrong. Both the time and timezone should be for Arizona. Am I missing any libvirt instructions to avoid this? Did anyone else face the same issue?

rakesh
  • 135
  • 3
  • 15

1 Answers1

-1

<clock offset='localtime'> instructs QEMU to set the guest time to match the host's view of localtime. Since you say the host localtime is set to UTC, the guest time will thus be set to UTC on every boot. Changes you make inside the guest only last until the next cold reboot.

You want the guest timezone to be different from the host timezone, so instead of "localtime" offset, you need "timzeone" offset. IIUC, Arizone is in MST, so something like this should do the job <clock offset='timezone' timezone='mst'>. See also https://libvirt.org/formatdomain.html#time-keeping

DanielB
  • 2,461
  • 1
  • 10
  • 13
  • Thanks @DanielB for your reply. Adding `` will solve the time but my other question is what if I dont want to hardcode the timezone in xml? If I set timezone to CEST then it should automatically pickup CEST after next reboot. similalry for any other time zone. I dont want to hardcode it but rather it should store what user selects and should retain it after reboot – rakesh Sep 14 '20 at 08:48
  • The problem is that by default when selecting a timezone Windows will update the BIOS clock to this timezone. Most other OS will not touch the BIOS clock and leave it in UTC, simply adjusting the OS system time to local time instead. You can force Windows to leave BIOS in UTC https://wiki.archlinux.org/index.php/System_time#UTC_in_Windows and then you can use `````` in libvirt and control timezone purely from the guest.. – DanielB Sep 14 '20 at 13:40