Skip to content

Instantly share code, notes, and snippets.

@jfstenuit
Last active February 3, 2023 08:05
Show Gist options
  • Save jfstenuit/3bb9d302a52f08e6980dbec3ab4372af to your computer and use it in GitHub Desktop.
Save jfstenuit/3bb9d302a52f08e6980dbec3ab4372af to your computer and use it in GitHub Desktop.
Quick reference for KVM on headless linux
apt install qemu-kvm libvirt-daemon-system libvirt-clients virtinst cpu-checker libguestfs-tools libosinfo-bin
virsh console deb-elastic
virsh destroy <name>
virsh domifaddr <name>
virsh dominfo <name>
virsh dumpxml <name> | grep "mac address" | awk -F\' '{ print $2}'
virsh edit <name>
virsh guestinfo <name>
virsh list --all
virsh list|awk '$1>0 {print $2}'
virsh net list
virsh net-dhcp-leases default
virsh net-info default
virsh net-list
virsh restore <name>
virsh resume <name>
virsh save <name> <savename>
virsh setmem <name> 12G
virsh start <name>
virsh undefine <name>
virsh vncdisplay <name>
virt-install --os-variant list
qemu-img resize /data/libvirt/images/approach.qcow2 +10G
guestmount -a /data/libvirt/images/deb-spiderfoot.qcow2 -m /dev/sda1 /mnt/work
qemu-img create -f qcow2 /data/libvirt/images/mac_hdd.img 128G

osinfo-query os
#!/bin/sh

NAME="$1"
if [ "$NAME" == "" ]; then
        echo "Name required"
        exit 1
fi
export ISO="/data/libvirt/iso/Windows10-Enterprise-x64-enUS-21H2.iso"
export VM_IMG="/data/libvirt/images/${NAME}.qcow2" # VM image on disk
sudo virt-install \
--virt-type=kvm \
--name $NAME \
--ram 4096 \
--vcpus=2 \
--os-type=windows \
--os-variant=win10 \
--hvm \
--cdrom=${ISO} \
--network=bridge=br0,model=e1000e \
--graphics vnc \
--noautoconsole --accelerate --noapic \
--disk path=${VM_IMG},size=20,bus=sata,format=qcow2,sparse=yes
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/data/libvirt/images/win10.qcow2'/>
      <target dev='sda' bus='sata'/>
      <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
    </disk>
    <interface type='bridge'>
      <mac address='00:D0:B7:72:2f:a9'/>
      <source bridge='br0'/>
      <model type='e1000e'/>
      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
    </interface>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment