Jacobs "Blog"

Using qemu-kvm

Here I attempt to use qemu-kvm. I will be documenting every question I have. The contents of this post will change over time. I'm only leaving it live incase it helps someone or incase I need to reference it quickly.

How do I create a VM?

Script I have been using:

virt-install \
--virt-type=kvm \
--name git \
--ram 1024 \
--vcpus=1 \
--virt-type=kvm \
--hvm \
--cdrom=/var/lib/libvirt/boot/CentOS-7-x86_64-Minimal-1804.iso \
--network=bridge=br0,model=virtio \
--graphics vnc \
--disk path=/var/lib/libvirt/images/git.qcow2,size=15,bus=virtio,format=qcow2

How do I "manage" a VM?

Depends how you want to define "manage". I have the following "manage-vm" script sitting in my directory from when I had to make changes previously:

#qemu-system-x86_64 \
#    -enable-kvm \
#    -M q35 \
#    -m 2G \
#    -usb -usbdevice host:16b2:1001 \
#    -usb -usbdevice host:0529:0001 \
#    -usbdevice tablet \
#    -net nic \
#    -net bridge,br=br0 \
#    -vga qxl \
#    -spice port=5930,disable-ticketing \
#    -device virtio-serial-pci \
#    -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
#    -chardev spicevmc,id=spicechannel0,name=vdagent \
#    -drive file=/mnt/data/win-patch.img,if=virtio

qemu-system-x86_64 \
    -device usb-1:3 \
    #-drive file=/var/lib/libvirt/images/fahn.qcow2

I have been commenting out parts I dont need changing. If I recall correctly, I was attempting to pass a USB Receive for wireless speakers through to a VM. I have paused this idea until my NUC is running and because I'll be purchasing a raspberry pi for music playing in the office.

How do I list all inactive VMs?

virsh list will list all vm's which are currently active. virsh list --all will show everything installed with it's state:

# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     centos7                        shut off
 -     fun                            shut off
 -     git                            shut off
 -     web                            shut off

How do I start a VM?

We can see that 'web' has a state of 'shut off', so how do we change that?

virsh (start|stop) <vm name>
# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     web                            running
 -     centos7                        shut off
 -     fun                            shut off
 -     git                            shut off