Skip to content

Instantly share code, notes, and snippets.

@sfloess
Last active February 14, 2024 16:16
Show Gist options
  • Save sfloess/153103130c3716f2ff3ef815b1fabaad to your computer and use it in GitHub Desktop.
Save sfloess/153103130c3716f2ff3ef815b1fabaad to your computer and use it in GitHub Desktop.
Virtualization

KVM

Installing

Debian

  • apt install qemu qemu-kvm qemu-system qemu-utils
  • apt install libvirt-clients libvirt-daemon-system virtinst
  • apt install ovmf netcat-openbsd

More information can be found here.

Red Hat Based

Commands

  • Start a VM: virsh start [VM name]
  • Stop a VM: virsh shutdown [VM name]
  • Rename VM: virsh domrename [old name] [new name]
  • Remove VM: virsh undefine --remove-all-storage [VM name]
  • Running VMs: virsh list
  • List all VMs: virsh list --all
  • Export VM def: virsh dumpxml [VM name]
  • VM image files: /var/lib/libvirt/images

Clone VM

  • virt-clone -o [original] -n [new]--auto-clone
  • virt-sysprep --hostname [new hostname] -d [new]

Example:

  • virt-clone -o debian-server -n workstation --auto-clone
  • virt-sysprep --hostname workstation -d workstation

Resize qcow2

To resize a qcow2 image:

  • qemu-img resize [qcow2 file] +[size]
  • cp [qcow2 file] [qcow2 new file]
  • virt-resize –expand [partition] [qcow2 new file] [qcow2 file]

Example:

  • qemu-img resize undercloud.qcow2 +20G
  • cp undercloud.qcow2 undercloud-orig.qcow2
  • virt-resize –expand /dev/sda1 undercloud-orig.qcow2 undercloud.qcow2

QEMU

  • Open Up to Outside Connections /etc/libvirt/qemu.conf:
vnc_listen = 0.0.0.0

spice_listen = 0.0.0.0
  • Audio /etc/libvirtd/qemu.conf:
vnc_allow_host_audio = 1

nographics_allow_host_audio = 1

Xen

Bhyve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment