KVM: Start a Virtual Machine / Guest At Boot Time

by on July 14, 2010 · 6 comments· LAST UPDATED February 1, 2011

in , ,

There are various ways to start virtual machines at at boot time. This means you don't have to type virsh start vmName command. This can be done by marking a vm as autostart. To configure a domain to be automatically started at boot. It will create an softlink at /etc/libvirt/qemu/autostart/. So if your VM name is debianlenny1, your config file name should be /etc/libvirt/qemu/debianlenny1.xml and the softlink should be created at /etc/libvirt/qemu/autostart//debianlenny1.xml

KVM: Autostart a Domain / VM Command

Type the following command:

virsh autostart vmName
virsh autostart debianlenny1

Sample outputs:

Domain debianlenny1 marked as autostarted

Also, make sure /etc/init.d/libvirtd service is stared on boot:
chkconfig libvirtd on

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 6 comments… read them below or add one }

1 Matt April 16, 2012 at 2:48 am

Also note that to disable autostarting use the –disable flag:

virsh # autostart footest –disable
Domain footest unmarked as autostarted

Reply

2 Low Jiunn Yik June 4, 2012 at 9:27 am

Thank you for this guide. It is useful for me.

Reply

3 scott November 10, 2012 at 3:52 am

hi
i see that you posted some time ago so i don’t know if you still monitor this but i am hoping someone can help me out.
i am capable of doing what you said above and the 6 virtual machines (VMs) all boot when the (bare metal) server boots up; however, they are in a cluster and for whatever reason – in order for the VMs to boot up consistently and not hang – i have to boot the 1st VM 1st and after it starts the quorum (somewhere around “starting crond”) i can start the remaining VMs and all VMs consistently boot up. also, when shutting the VMs down, i have to shutdown all of the VMs except the 1st VM – in order for the VMs to shutdown consistently and not hang / give corosync dlm lock errors – and after all the other VMs have shutdown i can shutdown the 1st VM and this works consistently.
SO…
i cannot simply tell all VMs to automatically boot up when the server boots up…i have to create a service to tell the VMs to boot up / shutdown in the order i specified with a “sleep” in between. i write this service no problem but i am getting errors and none of the VMs are starting up. i made sure to put my service at the very end “S99service_name” in the /etc/rc.d/rc3.d file. i am wondering if it is being killed by the libvirtd or fence-virt services even though they’re set to “S98″??
at what point in time / what service is responsible for performing the “virsh start VM” command? i’m guessing wherever that is i should put my service.
thanks
scott

Reply

4 John Airey January 17, 2013 at 3:42 pm

Scott – have you tried putting the startup commands in /etc/rc.d/rc.local with sleep in between them. That is executed when everything else has started, it’s where I would start.

Reply

5 scott January 17, 2013 at 5:14 pm

hi john
thanks for responding.
i have since gotten someone involved and it is resolved. there were a number of problems. 1) we were using rhel 6 which requires the use of a certain format at the beginning of the service files 2) i forget which of the services (it could have been libvirtd or fence-virt) but it was attempting to start the VMs as well. i think this is what prevented the service files that i created from working.
scott

Reply

6 Kiriam August 5, 2014 at 6:06 pm

Leave a Comment

Tagged as: , , , , , ,

Previous Faq:

Next Faq: