KVM: Start a Virtual Machine / Guest At Boot Time

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
systemctl enable libvirtd

How do I disable autostarting a domain/VMs

The syntax is:
virsh autostart VMNameHere --disable
To disable auto starting freebsd vm, enter:
virsh autostart freebsd --disable
Sample outputs:

Domain freebsd unmarked as autostarted
This entry is 11 of 14 in the CentOS / Redhat (RHEL) KVM Virtulization series. Keep reading the rest of the series:
  1. CentOS / Redhat: Install KVM Virtualization Software
  2. CentOS / Redhat: KVM Bridged Network Configuration
  3. KVM virt-manager: Install CentOS As Guest Operating System
  4. KVM virt-install: Install FreeBSD / CentOS As Guest Operating System
  5. KVM: Install CentOS / RHEL Using Kickstart File (Automated Installation)
  6. Troubleshooting KVM Virtualization Problem With Log Files
  7. KVM Virsh: Redirect FreeBSD Console To A Serial Port
  8. KVM: Starting / Stopping Guest Operating Systems With virsh Command
  9. Linux KVM: Disable virbr0 NAT Interface
  10. FreeBSD / OpeBSD Running in KVM Does Not Accept FTP Traffic
  11. KVM: Start a Virtual Machine / Guest At Boot Time
  12. KVM virt-install: Install OpenBSD As Guest Operating System
  13. Linux KVM: OpenBSD Guest Hangs At Starting tty Flags
  14. KVM Virtualization: Start VNC Remote Access For Guest Operating Systems

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 6 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
6 comments… add one
  • Matt Apr 16, 2012 @ 2:48

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

    virsh # autostart footest –disable
    Domain footest unmarked as autostarted

  • Low Jiunn Yik Jun 4, 2012 @ 9:27

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

  • scott Nov 10, 2012 @ 3:52

    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.
    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.

  • John Airey Jan 17, 2013 @ 15:42

    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.

  • scott Jan 17, 2013 @ 17:14

    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.

  • Kiriam Aug 5, 2014 @ 18:06

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum