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
- CentOS / Redhat: Install KVM Virtualization Software
- CentOS / Redhat: KVM Bridged Network Configuration
- KVM virt-manager: Install CentOS As Guest Operating System
- KVM virt-install: Install FreeBSD / CentOS As Guest Operating System
- KVM: Install CentOS / RHEL Using Kickstart File (Automated Installation)
- Troubleshooting KVM Virtualization Problem With Log Files
- KVM Virsh: Redirect FreeBSD Console To A Serial Port
- KVM: Starting / Stopping Guest Operating Systems With virsh Command
- Linux KVM: Disable virbr0 NAT Interface
- FreeBSD / OpeBSD Running in KVM Does Not Accept FTP Traffic
- KVM: Start a Virtual Machine / Guest At Boot Time
- KVM virt-install: Install OpenBSD As Guest Operating System
- Linux KVM: OpenBSD Guest Hangs At Starting tty Flags
- KVM Virtualization: Start VNC Remote Access For Guest Operating Systems













{ 5 comments… read them below or add one }
Also note that to disable autostarting use the –disable flag:
virsh # autostart footest –disable
Domain footest unmarked as autostarted
Thank you for this guide. It is useful for me.
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
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.
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