Jump to content
Forums in Read-Only Mode - Please use Reddit ×
  • 0

Starting a qemu virtual machine at boot


hick518

Question

2 answers to this question

Recommended Posts

  • 0

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

×
×
  • Create New...