crc-org / vfkit

Apache License 2.0
140 stars 26 forks source link

How to use timesync option? #190

Closed seanenck closed 1 month ago

seanenck commented 2 months ago

I've read the usage and understand the intention of the --timesync flag and maybe have qemu guest agent setup properly in my (Alpine Linux) VM but I don't get time sync (getting errors, see below), and am just trying to understand what specific values to specify for vfkit invocation and qemu-ga to see time sync actually work

If I simply specify --timesync without a corresponding --device virtio-vsock during vfkit, I get the following error: error connecting to vsock port 7890: VM has too many/not enough virtio-vsock devices (0)

Which, I think, makes sense given I think I do need to specify a --device virtio-vsock from what it seems. Though I think this should likely be a configuration error as the user is asking for something that will potentially never work (and --timesync erroring here is at debug level by default so time sync will just silently fail).

So, to get time sync to work, I'd be interested to see a working vfkit host invocation with --timesync and --device virtio-vsock (and associated options for each) and the guest's qemu-ga invocation, can someone provide this?

cfergeau commented 2 months ago

The timesync option should add a virtio-vsock device if needed. crc is using -timesync vsockPort=1234 together with this qemu-guest-agent unit file:

$ cat /etc/systemd/system/qemu-guest-agent.service
[Unit]
Description=QEMU Guest Agent
IgnoreOnIsolate=True

[Service]
UMask=0077
EnvironmentFile=/etc/sysconfig/qemu-ga
ExecStart=/usr/bin/qemu-ga \
  --method=vsock-listen \
  --path=3:1234 \
  --blacklist=${BLACKLIST_RPC} \
  -F${FSFREEZE_HOOK_PATHNAME}
Restart=always
RestartSec=0

[Install]
WantedBy=default.target

An alternative to -timesync is to have chronyd in the guest, and to add makestep 1 -1 to its configuration.

cfergeau commented 2 months ago

The timesync option should add a virtio-vsock device if needed.

This automatic addition is currently broken in git, https://github.com/crc-org/vfkit/pull/191 should fix it. In the mean time, you can add another virtio-vsock device to your VM, this should workaround the issue and allow timesync to work.

seanenck commented 2 months ago

Thanks for putting the pieces together for me.