Jump to content
  • 0

Starting a qemu virtual machine at boot


hick518
 Share

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 an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...