In my case, the problem was that I had a file in the autostart folder and not a link.
root@kvm1630:/etc/libvirt/qemu # ls -l
-rw------- 1 root root 7982 févr. 18 15:17 hebergement.xml
root@kvm1630:/etc/libvirt/qemu # ls -l autostart/
-rwx------ 1 root root 6195 avril 16 2021 hebergement.xml*
Solution: delete the file and create a symbolic link.
root@kvm1630:/etc/libvirt/qemu # rm autostart/hebergement.xml
rm: remove regular file 'autostart/hebergement.xml'? y
Then run the command again to make the VM autostart:
root@kvm1630:/etc/libvirt/qemu # virsh autostart hebergement
Domain hebergement marked as autostarted
root@kvm1630:/etc/libvirt/qemu # ls -l autostart/
lrwxrwxrwx 1 root root 33 févr. 18 15:49 hebergement.xml -> /etc/libvirt/qemu/hebergement.xml
We finally check that the VM is indeed autostart.
root@kvm1630:/etc/libvirt/qemu # virsh dominfo hebergement
Id: 9
Name: hebergement
UUID: 74590197-8b3a-4bed-95e6-653ce7c456af
OS Type: hvm
State: running
CPU(s): 1
CPU time: 6614,7s
Max memory: 8388608 KiB
Used memory: 8388608 KiB
Persistent: yes
Autostart: enable
Managed save: no
Security model: none
Security DOI: 0
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:
root@kvm1630:/etc/libvirt/qemu # colordiff hebergement.xml autostart/hebergement.xml
46,83c48
< <source file='/var/lib/libvirt/images/hebergement.bimg-20220218-151710'/>
< <backingStore type='file'>
< <format type='qcow2'/>
< <source file='/var/lib/libvirt/images/hebergement.bimg-20220218-141710'/>
< <backingStore type='file'>
< <format type='qcow2'/>
< <source file='/var/lib/libvirt/images/hebergement.bimg-20220218-131710'/>
< <backingStore type='file'>
< <format type='qcow2'/>
< <source file='/var/lib/libvirt/images/hebergement.bimg-20220218-121709'/>
< <backingStore type='file'>
< <format type='qcow2'/>
< <source file='/var/lib/libvirt/images/hebergement.bimg-20220218-111709'/>
< <backingStore type='file'>
< <format type='qcow2'/>
< <source file='/var/lib/libvirt/images/hebergement.bimg-20220218-101711'/>
< <backingStore type='file'>
< <format type='qcow2'/>
< <source file='/var/lib/libvirt/images/hebergement.bimg-20220218-091738'/>
< <backingStore type='file'>
< <format type='qcow2'/>
< <source file='/var/lib/libvirt/images/hebergement.bimg-20220218-091200'/>
< <backingStore type='file'>
< <format type='qcow2'/>
< <source file='/var/lib/libvirt/images/hebergement.bimg-20220218-082151'/>
< <backingStore type='file'>
< <format type='qcow2'/>
< <source file='/var/lib/libvirt/images/hebergement.qcow2'/>
< <backingStore/>
< </backingStore>
< </backingStore>
< </backingStore>
< </backingStore>
< </backingStore>
< </backingStore>
< </backingStore>
< </backingStore>
< </backingStore>
---
> <source file='/var/lib/libvirt/images/hebergement.bimg-20210415-011726'/>
hope it helps
Ernest.