Virsh
connect URIs
virsh -c qemu+ssh://dapple/system list --all
Storage
Create storagepool
Create LVM pool:
virsh pool-define-as libvirt logical --source-name dapple-vg --target /dev/mapper/system_crypt
virsh pool-autostart libvirt
Edit files inside a shutdown VM from the host
virt-edit baseimage.dfi.local /etc/default/grub
rename machine
virsh dumpxml name_of_vm > /tmp/name_of_vm.xml
Undefine the old vm to prevent an error because of an duplicate UUID.
virsh undefine name-of-vm
Edit the xml file then import it.
virsh define /tmp/name_of_vm.xml
List / dominfo
virsh list --all
virsh dominfo debian-vpn
Show all domains memory:
virsh domstats --balloon
virsh domstats --balloon |grep -E '(Domain|balloon.max)'
Modify VMs
Add memory
export DOM=dapple-media-controlplane
virsh dominfo $DOM | grep memory
virsh shutdown $DOM
virsh setmaxmem $DOM 12G --config
virsh setmem $DOM 12G --config
virsh start $DOM
Add a vCPU
See Modifying the number of virtual CPUs
virsh vcpucount $DOM
virsh shutdown $DOM
virsh setvcpus $DOM 3 --maximum --config
virsh setvcpus $DOM 3 --config
virsh start $DOM
Modify description
virsh desc --config --new-desc "K3s agent: Gitlab agent and runner, tym-flow CI and prod deployment" $DOM
virsh desc --current --new-desc "K3s agent: Gitlab agent and runner, tym-flow CI and prod deployment" $DOM
Modify auto-start behaviour
Enable autostart:
$ virsh autostart $DOM
Domain '$DOM' marked as autostarted
Disable autostart:
$ virsh autostart --disable jump
Domain 'jump' unmarked as autostarted
List domains marked as autostart:
virsh list --autostart --all
Add a data disk to existing domain
virsh vol-create-as <POOL> <NAME> 12G --format qcow2 --allocation 30G
qcow2:
virsh vol-create-as virtimages try.pixelated-project.org.data.img 14G --format qcow2 --allocation 14G
virsh attach-disk try.pixelated-project.org \
--source /var/lib/libvirt/images/try.pixelated-project.org.data.img \
--target vdb --persistent
lvm:
virsh vol-create-as lvm try.pixelated-project.org.data.img 20G
virsh attach-disk try.pixelated-project.org --source /dev/n097h049/try.pixelated-project.org.data.img --target vdb --persistent
virsh detach-disk try.pixelated-project.org --target vdb
virsh vol-delete --pool virtimages try.pixelated-project.org.data.img
Remove domain
virsh undefine --managed-save --remove-all-storage DOMAIN
Find IP of VM
Oneliner:
for mac in `virsh domiflist platform-test.dfi.local ΒΈ
| grep -o -E "([0-9a-f]{2}:){5}([0-9a-f]{2})"` ; do
arp -e |grep $mac |grep -o -P "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" ; done
as function:
virt_ip () {
for mac in `virsh domiflist $1 |grep -o -E "([0-9a-f]{2}:){5}([0-9a-f]{2})"`
do
arp -e |grep $mac |grep -o -P "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
done
}