1

I like to set up a new guest but do not want to start it immediately. I use virt-install with these options:

virt-install \
    --connect qemu:///system \
    --import \
    --virt-type kvm \
    --name somevm \
    --os-variant win7 \
    --memory 2048 \
    --vcpus 1 \
    --disk /home/bla/VirtualMachines/somevm.qcow2,format=qcow2,device=disk \
    --network network=default \
    --noautoconsole \
    --sound default

But virt-install will always start the VM. I can not find any option in the man page to disable the automatic start. I would rather not call virsh destroy somevm right after the install, although the VM will probably not be booted up yet... Is it possible to prevent the start of the guest with virt-install or is there another tool which can do the same but do not start the guest?

I also found some kind of workaround: instead of using --import, you can install the VM with --pxe. If no PXE server is available, then this should give enough time to destroy the guest using virsh.

reox
  • 165
  • 2
  • 10

3 Answers3

5

Use the option --noreboot

virt-install \
   ..
   ..
   --noautoconsole \
   --video vga \
   --memballoon none \
   --noreboot

UPDATE:
Added the --memballoon option for those who spin up a Windows VM. Memballoon doesn't really work on Windows.

MrCalvin
  • 354
  • 1
  • 6
  • 18
4

The --print-xml option to virt-install might get closer to what you want. You could then feed the XML it prints into the virsh define command to create, but not start, the guest.

Alternatively checkout the virt-xml tool which is simply a friendly way to build up an XML document from args like those you'd give to virt-install

DanielB
  • 1,618
  • 7
  • 7
0

I mentioned a case that might be useful for your goal in this link:

In essence, if you have an existing disk image with everything already installed (you might have created this before, or cloned it from an existing KVM guest), stored in /var/lib/libvirt/images/debian10.qcow2, you can automate the creation of a new KVM virtual machine by importing that image with virt-install and its options --noautoconsole, e.g.,

virt-install --virt-type kvm --name debian10 --disk /var/lib/libvirt/images/debian10.qcow2 --import --os-variant debian10 --vcpus 1 --memory 1024 --noautoconsole

The domain (or the virtual machine) named debian10 will be created without asking for any interaction, virt-install will exit quickly as mentioned in its manual

--noautoconsole: Don't automatically try to connect to the guest console...
Note, virt-install exits quickly when this option is specified...

Since you have the image with everything already installed, the termination of virt-install causes no problem, rather a desired behaviour in this case. Afterwards, you can shutdown the guest VM with the virsh destroy or virsh shutdown command. At this point, you can modify the XML file of the guest VM gracefully with virsh edit, or in a direct manner on its source file (usually stored at /etc/libvirt/qemu/)