# libvirt: command to start up all guest virtual machines which have auto-start enabled

I'm using Debian Jessie as a virtual machine host using libvirt/qemu/kvm.

I've set some of the guest virtual machines to automatically start when the host OS boots up, this is working fine.

For maintenance purposes, I'm running "service libvirt-guests stop" to shut all the guests down (but not the host).

Once I've done my maintenance, I want to easily boot all the guests up again (without rebooting the host).

Is there a single command that will start all the guest VMs up again? I'm interested in knowing about both:

1. a command to start all the autostart-marked guests up again

2. a command to start all the guests up again that were running before I ran "service libvirt-guests stop"

Rebooting the host OS would achieve #1, but I don't want to reboot the host.

I tried, "service libvirt-guests start" but it doesn't seem to do it.

Like @jason-harris solution. But simpler and start only marked for autostart.

for i in $(virsh list --name --autostart); do virsh start$i; done


UPD: I tested it on libvirt 3.2.0 (CentOS 7.4.1708)

• Thanks! I don't currently have a host system to test this on, but it looks exactly like what I was after. And simpler than the other solutions. – LaVache May 15 '18 at 10:53
#! /bin/bash

xmlfiles=( $(find /etc/libvirt/qemu/autostart/ -name '*.xml') ) for f in "${xmlfiles[@]}" ; do
domain=$(xml2 <$f | awk -F= '$1 == "/domain/name" {print$2}')

# only start domain if it's not already running
if ! virsh list | grep -q " ${domain} .*running" ; then virsh start "$domain"
#else
# optionally reboot domain otherwise
#virsh reboot "$domain" fi done  This script requires the xml2 utility (in package xml2 in debian and probably ubuntu too). It uses xml2 to extract the domain name(s) from all XML files in libvirt's qemu autostart directory, and runs virsh start on them if they're not already running. Save it somewhere in your PATH, as something like virsh-autostart.sh (or whatever makes sense to you) and make it executable with chmod. I don't believe there is a simple command to do that (but it would be great!). I do this fairly often and it is usually just a quick script / one line command using a for loop and some awk. Keep in mind that if your hypervisor is connected to other hypervisors, you might want to sever that link temporarily so you don't inadvertently interfere with other VMs on other hypervisors. I haven't seen many people actually utilize this though, but I wanted to point that out. For instance, you could type the following to achieve the result you want, assuming you want to turn everything back on. This assumes you are root: for i in virsh list --all|awk '{print$2}'|grep -v Name; do virsh start $i; done  The command breaks down like this: virsh list --all  Shows all of the virtual machines, whether they are on or not. awk '{print$2}'|grep -v Name


We are taking out the unneeded columns and only printing the column with the virtual machine names. Then we take out the header row with grep since it isn't actually a virtual machine.

virsh start \$i


Turns on the virtual machine.

And this is all wrapped around a general for loop.

I use systemctl restart libvirtd.service. Works without a flaw in CentOS 7 (host).

On Debian Stretch:

systemctl restart libvirtd


didn't do the job. Libvirt actually restarted its service but all qemu processes and the OS's inside kept running.

This worked:

systemctl stop libvirt-guests   # stops VMs
systemctl restart libvirtd      # starts VMs agains


You can also use KVM_AutoBoot ( https://github.com/eduardolucioac/kvm_autoboot ) to start one or several virtual machines at server boot using KVM (libvirt). It is also possible to define an interval between the start of a virtual machine and the next one.

NOTE: Although KVM_AutoBoot does not answer what you want exactly in the way that you want, it can be used to automatically boot KVM's virtual machines defined in a list at server boot or when you you start (systemctl start kvm_autoboot.service) it.

Thanks! =D