LibVirt¶
KVM Virtual Machines¶
Build a Linux machine¶
virt-install \
--connect qemu:///system \
--virt-type kvm \
--name testkvm \
--memory 2048 \
--disk /media/KVM/pool/testkvm.qcow,format=qcow2,size=10 \
--cdrom /media/source/pool/template/iso/debian-12.1.0-amd64-netinst.iso \
--network bridge=vmbr1 \
--graphics vnc \
--os-type linux \
--os-variant debiantesting
Build a Windows machine¶
virt-install \
--connect qemu:///system \
--virt-type kvm \
--name UESX01 \
--memory 4096 \
--disk /media/KVM/pool/uesx01.qcow,format=qcow2,size=60 \
--cdrom /media/source/pool/template/iso/Windows.7.SP1.ENG.x86-x64.ACTiVATED.iso \
--network bridge=vmbr1 \
--graphics spice \
--os-variant=win7
virt-install \
--connect qemu:///system \
--virt-type kvm \
--name UESX02 \
--memory 4096 \
--disk /media/KVM/pool/uesx02.qcow,format=qcow2,size=60 \
--cdrom /media/source/pool/template/iso/Win10_22H2_English_x64v1.iso \
--network bridge=vmbr1 \
--graphics spice \
--os-variant=win10
virt-install \
--name demo \
--memory 512 \
--disk /home/user/VMs/mydisk.img \
--import
virt-install --connect qemu:///session \
--virt-type kvm
--name integradb
--memory 4096
--disk /media/KVM/elph-pool/db_gst_apr_2025.qcow2
--import
--network bridge=vmbr0
--osinfo detect=on,require=off
virt-install --connect qemu:///system
--name vmname
--memory 49152
--boot uefi
--machine q35
--disk /home/elph/kvm/elph-pool/gst/disk.qcow2
--import
--controller type=scsi,model=virtio-scsi,driver.iommu=on
--controller type=virtio-serial,driver.iommu=on
--rng /dev/random,driver.iommu=on
--memballoon driver.iommu=on
--vcpus 16
--network bridge=vmbr0,model=virtio,driver.iommu=on
--graphics spice
--graphics vnc
--os-info win2k19
Setup Tunnel¶
ssh elph@akbal.hbues.net -f -N -L *:5900:localhost:5900 -L *:5901:localhost:5901 -L *:5902:localhost:5902 -L *:5903:localhost:5903
Note
https://192.200.100.162:9090/machines
user : usr
pass : pass
ssh elph@192.200.100.162 -f -N -L *:5900:localhost:5900 -L *:5901:localhost:5901 -L *:5902:localhost:5902 -L *:5903:localhost:5903
insstallar spicy:
sudo apt install spice-client-gtk
connectar:
spicy -h localhost -p 5900
Machine Management¶
List Machines¶
virsh -c qemu:///system list --all
Id Name State
----------------------------------
8 testkvm shut off
Start a Machine¶
virsh -c qemu:///system start testkvm
Domain testkvm started
Get Connection info¶
virsh -c qemu:///system vncdisplay testkvm
127.0.0.1:0
Note
Other available virsh subcommands include:
reboot
to restart a virtual machine;shutdown
to trigger a clean shutdown;destroy
, to stop it brutally;suspend
to pause it;resume
to unpause it;autostart
to enable (or disable, with the #.#.disable option) starting the virtual machine automatically when the host starts;undefine
to remove all traces of the virtual machine from libvirtd.
All these subcommands take a virtual machine identifier as a parameter.
Full deletion¶
virsh -c qemu:///system undefine testkvm --remove-all-storage --delete-snapshots
Connect to Machine¶
Note
this connection should be automatically started. If not, or if we operate remotely, virt-viewer can be run from any graphical environment to open the graphical console (note that the root password of the remote host is asked twice because the operation requires 2 SSH connections):
virt-viewer --connect qemu+ssh://root@server/system testkvm
root@server's password:
root@server's password:
virt-viewer --connect qemu:///system UESX01
Create Storage Pool¶
# create pool
virsh pool-define-as --name kvm --type dir --target /path/to/pool/ --build
# init pool
virsh pool-start kvm
# set autostart
virsh pool-autostart kvm
virsh pool-create-as srv-kvm dir --target /media/KVM/pool/