Windows VM time not updated after hibernate/resume

JamesA

New Member
Jun 5, 2022
13
0
1
I am new to Proxmox. Just moved over from Hyper-V to PVE for all the features!

One thing I have noticed is that if I hibernate my Windows VMs, when they next resume they have the time from when I hibernated them and it’s not updated. I have to restart the windows time service then the VMs update their time.

I have QEMU agent enabled and the latest guest tools installed. Does the agent not update the time after a hibernate/resume like Hyper-v did? Or am I missing something?

Thanks!
 
Just to add this is a test home lab, hence the hibernating of machines as host is powered off each day. Maybe not production real world..

Can’t believe I am having to do this.. but this is the workaround I used because VM cannot update BIOS time after hibernate / resume.

1) Set my domain controller to update their time source from time.windows.com. If you have multiple DC make sure you only do on the PDC.

2) Created a GPO which has a scheduled task that runs on every domain server that updates the time every 5 mins. This task runs indefinitely. This means when the VM resumes it only has to wait max of 5 mins before updating the time. The schedule task just runs this:

w32tm /resync

I would love to know if anyone else has done any better ideas?

@proxmox any plans to update VM time? I think hyper V does this using their time sync service.
 
So I had a look into this today but no luck!

When you hibernate and then start the VM in Proxmox there are no windows events shown. The VM seems to think that nothing has happened..

I think this is going to need someone to create a time sync service that can check with the hypervisor somehow like how Hyper-V works maybe..
 
Ah thanks for checking. Most my VMs are windows, few Linux. What a shame Proxmox don’t have something to do this. :-( be a great feature request maybe..
 
Ok great a year old :) won’t hold my breath on that one then ha ha.

Do you think this is the best workaround I am using then? When the VM does not know it’s been suspended/resumed I can’t think of any other option really.

Be great if Proxmox had like start scripts that can run on the VM so when the VM resumed it would trigger a script which could update the time.
 
I have hit another snag with my workaround! If you have the VM suspended for too long the time resync now won’t happen. You get an error:

“The computer did not resync because the required time change was too big”

I have been loving using Proxmox. But I think I might try out ESXi or Hyper-V again because of this issue. It isn’t really fit for my needs.. :-(
 
I have hit another snag with my workaround! If you have the VM suspended for too long the time resync now won’t happen. You get an error:

“The computer did not resync because the required time change was too big”
I have this same issue with windows. server runs 24/7, but i pause the VM when not used as the windows idle consumption is the majority of the power usage when I'm sleeping and win vm is only for actual work work.
My workaround is to manually set the time within a couple hours if the sync fails and then resync.
It's a major pita, but works 95% of the time.
wake up, drink coffee, spin up vm, resync vm.
 
I have this same issue with windows. server runs 24/7, but i pause the VM when not used as the windows idle consumption is the majority of the power usage when I'm sleeping and win vm is only for actual work work.
My workaround is to manually set the time within a couple hours if the sync fails and then resync.
It's a major pita, but works 95% of the time.
wake up, drink coffee, spin up vm, resync vm.
Yea I actually gave up with Proxmox because of this issue until maybe they do something about it in the future.

I actually now use Fedora as the host running KVM/QEMU and then I use a remote Ubuntu workstation with Virt Manager.

To keep RTC time in the guest accurate across suspend/resume, set SYNC_TIME=1 in /etc/default/libvirt-guests, which calls virsh domtime --sync after the guest is resumed.

This causes the QEMU Guest Agent to call w32tm /resync /nowait in the guest

This works really well! Just have to make sure you are running QEMU agent in the virtual machine.

If Proxmox ever use this in their product I might come back to using it again as I did like ProxMox overall. But for now it’s not fit for my purpose.
 
Here is my workaround, with a Hookscript i sync the VM date/time with qemu guest-agent, at the post start event. It work for VM resume.

Set a hookscript to your VM options in proxmox gui :

1681736861656.png

The hookscript look like this :

Bash:
vmid="$1"
phase="$2"
file="/etc/pve/qemu-server/$vmid.conf"

if [[ "$phase" == "post-start" ]]; then

    # sync VM time after resume
    if grep -q "ostype: win10" $file; then
        echo "## Resync windows time ##"
        date=$(date +"%d-%m-%y")
        qm guest exec $vmid "cmd" "/c date $date & net start W32Time & w32tm /resync" || true
    else
        echo "## Resync Linux time ##"
        qm guest exec $vmid "service" "systemd-timesyncd" "restart" || true
    fi
 
fi

For windows i needed to set the correct date with "date" command, because if the windows VM hibernated for a long times (many days...) the "w32tm /resync" command wont work.
 
Last edited:
@cogis
Thanks for the info on this! I noticed you said you set the hook script using the GUI. I couldn’t find a UI way to do this so I tried your script updating the vm config using the terminal.

I tried a hibernate and resume on the Windows VM but the time is not updating.

Any chance you could provide a step by step how you have set the hook script to the VM in case I am doing something wrong?
 
Hi @JamesA
my bad, we can't set it with the GUI, only in the conf file located in : /etc/pve/qemu-server/

in the .conf file of the vm (ex: 101.conf)

i have this line :

hookscript: local:snippets/taskset-hook.sh

local is the name of your storage

The taskset-hook.sh can for example be at : /var/lib/vz/snippets/taskset-hook.sh


To be honest it work well on linux VM, on windows it works only sometimes ...

Maybe a windows service to develop than run every X minutes can be more reliable
 
Last edited:
Thanks @cogis managed to get the script executing now. I had to also enable the snippets folder on my datacenter local storage.

I have the script working now but in the Vm start logs I am seeing “The computer did not resync because no time data was available”

I think this is cause my VM has no internet and it’s set to get time from time.windows.com.

Will get the vm some internet and see if it helps.
 
I also had this issue, here is my last version with some workaround for windows, still not 100% reliable :


Bash:
if grep -q "ostype: win10" $file; then
        echo "## Resync windows time ##"
        date=$(date  --date="yesterday" +"%d-%m-%y")
        sleep 5
        qm guest exec $vmid "cmd" "/c net start W32Time &  date $date & net stop W32Time &  net start W32Time & w32tm /resync /nowait & timeout /t 10 & w32tm /resync /nowait" || true
    else
        echo "## Resync Linux time ##"
        qm guest exec $vmid "service" "systemd-timesyncd" "restart" || true
    fi
 
Yea that seems to work better. Only problem is that the VM bios time is only updated to the local PVE time when the VM is rebooted. So for the resync in windows to work correctly there has to be an external time source which is reliable for windows to update the time from.

I am going to test this later this week using a domain controller with external access for time source, then add a windows machine to the domain which will use the domain controller as time source. In theory this will work long as the domain controller can update its time source correctly.

I am currently using VMware ESXi and it does not have this issue. I think the guest tools have ways to correctly update the tile from the host. But I’d prefer Proxmox if honest.
 
So been testing this quite a bit. Your script does work until the VM has been off for a few days. After that when w32tm is called you get the error in windows that the there is too big of a time gap to correctly sync so it refuses to sync.

As the VMs are in a domain I found the best thing at the end of the script was to run this:

Net time /SET /Y

This then forces the VM to grab the date and time from the domain controller. But even this is not perfect as sometimes when the resync happens after it reverts the date and time back a day for some reason.

I wish Proxmox would add an option to auto sync the date/time of the VM when it resumes based on the host time like VMware and Hyper-V can do.

I can even do this in Ubuntu when using libvirt but Proxmox don’t use this. If this was Ubuntu all you have to do is edit this:

/etc/default/libvirt-guests

Then you would edit SYNC_TIME=1

When you then resume the VM from Virt Manager it calls virsh domtime - -sync after the VM gets resumed.

If anyone comes up with any other ways using a hookscript etc to do this please do share.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!