root@virtual3:~# virsh autostart nstest
Domain nstest marked as autostarted
root@virtual3:~# virsh dominfo nstest
Id: -
Name: nstest
UUID: 8cf691cd-7246-442b-a26b-3580e24600c5
OS Type: hvm
State: shut off
CPU(s): 2
Max memory: 6291456 KiB
Used memory: 2097152 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: apparmor
Security DOI: 0
root@virtual3:~#
What am I doing wrong? The domain xml is listed in /etc/libvirt/qemu/autostart but still no autostart :(
Nothing in the logs :((
I was having the same problem (2/3/22) and found a solution now (2/7/22).
Problem: I was having the same problems too. It's never happened before. On one Centos 7 host, the first 3 VMs I had previously set to autostart was working fine (I could enable and disable autostart). But I had 4 others that had previously autostarted, now were set to not do so, and that I could not enable. I usually use the UI. If I click for autostart, save, and come back, it's not checked even though it should be. So I tried it per the command line it didn't work either and I discovered what you discovered above. Rebooting either the clients or the host machine makes no difference. Whether a client VM is running or shut off makes no difference.
Solution. It seems like something was getting out of sync. What, I'm not sure. The problem isn't apparently something saved in the virtual machine .xml file. While I never discovered exactly what was wrong, I did find figure out how to fix it. Anything set to autostart should have an entry in /etc/libvirt/qemu/autostart/ named something like machinename.xml containing a symbolic link to the virtual machine's xml configure file of the same name in /etc/libvirt/qemu/. Delete the symbolic link for the problematic clients in the /etc/libvirt/qemu/autostart directory (make sure you don’t delete the source xml in the qemu directory). Now when you try to turn on autostart either via the UI or with via ‘virsh autostart machinename’. I deleted the autostart/*xml files for the 4 problem clients, and then turned one on and off repeatedly via the UI, and the other 3 via the command line, and everything performs normal for me now...
In my case, the problem was that I had a file in the autostart folder and not a link.
Solution: delete the file and create a symbolic link.
Then run the command again to make the VM autostart:
We finally check that the VM is indeed autostart.
FYI, I use fi-backup a LibVirtKvm-script to create VM snapshots every hour... Consequence: the VM definition xml file is changed every hour like so:
hope it helps
Ernest.
It looks like you're expecting that setting 'autostart' will immediately start the VM. However, that's not the intended effect of autostart. Rather, it's solely there to ensure the VM starts automatically at boot time for the host. From the man page:
If you then want to actually start the VM immediately, you need to do so with
virsh start
.