hick518 Posted January 29, 2020 Report Share Posted January 29, 2020 I created a virtual machine using qemu. What's the proper way to automatically start it at boot time, and stop it at shutdown? Do I need to use libvirt for this? If so, how do I make libvirt aware of my existing qemu image? Link to comment Share on other sites More sharing options...
0 hick518 Posted January 29, 2020 Author Report Share Posted January 29, 2020 I'm still interested to know if there's a way to do it with just qemu, but here's how to do it using libvirt: 1) Install and run libvirt emerge -a libvirt virt-manager rc-update add libvirtd default /etc/init.d/libvirtd start 2) Import the qemu disk into libvirt. virt-install --name vmname --memory 1024 --disk /path/to/disk.qcow2 --import After the import, the vm will be powered on. Note that this can also be done in the gui, virt-manager. 3) Tell libvirt to automatically start the vm. virsh autostart vmname This creates a symbolic link in /etc/libvirt/qemu/autostart 4) You can test by shutting down the vm, stopping the libvirtd daemon, then starting the libvirtd daemon. Verify the status of the vm: virsh list --all This can also be verified in the virt-manager gui. 5) Make sure libvirtd is set to start on boot. rc-status | grep libvirtd rc-update add libvirtd default 6) On shutdown of the host, make sure the guests don't just get virtually powered off. rc-update add libvirt-guests default /etc/init.d/libvirt-guests start By default the guests will have their state saved, and any guest that is saved / shut down by the libvirt-guests service will be automatically started on the next boot (even if it was not set to autostart in step 3). Link to comment Share on other sites More sharing options...
0 lego12239 Posted October 20, 2020 Report Share Posted October 20, 2020 (edited) I use custom scripts: https://bugs.funtoo.org/browse/FL-6305 Edited October 20, 2020 by lego12239 Link to comment Share on other sites More sharing options...
Question
hick518
I created a virtual machine using qemu. What's the proper way to automatically start it at boot time, and stop it at shutdown? Do I need to use libvirt for this? If so, how do I make libvirt aware of my existing qemu image?
Link to comment
Share on other sites
2 answers to this question
Recommended Posts