This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| kvm [2021/05/21 05:30] – [Change network settings] vissie | kvm [2023/06/01 00:52] (current) – [Debian] vissie | ||
|---|---|---|---|
| Line 6: | Line 6: | ||
| Some network advanced stuff: [[https:// | Some network advanced stuff: [[https:// | ||
| < | < | ||
| - | sudo apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils | + | |
| + | sudo apt install | ||
| + | # Some apps does not get installed with --no-install-recommends and seemds to be added: qemu-utils dnsmasq | ||
| + | # ovmf is for uf | ||
| sudo systemctl status libvirtd.service | sudo systemctl status libvirtd.service | ||
| sudo virsh net-list --all | sudo virsh net-list --all | ||
| sudo modprobe vhost_net | sudo modprobe vhost_net | ||
| + | |||
| </ | </ | ||
| Line 17: | Line 21: | ||
| sudo virsh net-start default | sudo virsh net-start default | ||
| sudo virsh net-autostart default | sudo virsh net-autostart default | ||
| + | |||
| </ | </ | ||
| + | |||
| + | =====Stop all iptables rules===== | ||
| + | I had issues where these rules were interfering with my iptables manual rules. This worked | ||
| + | So edit your network (virsh net-edit) to <forward mode=' | ||
| + | |||
| + | |||
| If you want to offload the mechanism of “virtio-net” and want to improve the performance of KVM VMs then add “vhost_net” kernel module on your system using the beneath command, | If you want to offload the mechanism of “virtio-net” and want to improve the performance of KVM VMs then add “vhost_net” kernel module on your system using the beneath command, | ||
| Line 24: | Line 35: | ||
| echo " | echo " | ||
| lsmod | grep vhost | lsmod | grep vhost | ||
| + | |||
| </ | </ | ||
| < | < | ||
| + | |||
| host_net | host_net | ||
| vhost 49152 1 vhost_net | vhost 49152 1 vhost_net | ||
| tap 28672 1 vhost_net | tap 28672 1 vhost_net | ||
| tun 49152 2 vhost_net | tun 49152 2 vhost_net | ||
| + | |||
| </ | </ | ||
| + | |||
| Note: If you want a normal user to use virsh commands then add that user to libvirt and libvirt-qemu group using the following commands | Note: If you want a normal user to use virsh commands then add that user to libvirt and libvirt-qemu group using the following commands | ||
| + | |||
| < | < | ||
| sudo adduser pkumar libvirt | sudo adduser pkumar libvirt | ||
| sudo adduser pkumar libvirt-qemu | sudo adduser pkumar libvirt-qemu | ||
| + | |||
| </ | </ | ||
| + | |||
| To refresh or reload group membership run the followings, | To refresh or reload group membership run the followings, | ||
| + | |||
| < | < | ||
| newgrp libvirt | newgrp libvirt | ||
| newgrp libvirt-qemu | newgrp libvirt-qemu | ||
| + | |||
| </ | </ | ||
| + | |||
| + | ======Setup Bridges Network====== | ||
| + | sudo vim / | ||
| + | <sxh bash; gutter: false> | ||
| + | # This file describes the network interfaces available on your system | ||
| + | |||
| + | source / | ||
| + | |||
| + | # The loopback network interface | ||
| + | auto lo | ||
| + | iface lo inet loopback | ||
| + | |||
| + | # The primary network interface | ||
| + | # allow-hotplug enp0s31f6 | ||
| + | #iface enp0s31f6 inet dhcp | ||
| + | #auto enp0s31f6 | ||
| + | |||
| + | auto br0 | ||
| + | iface br0 inet dhcp | ||
| + | bridge_ports enp0s31f6 | ||
| + | bridge_stp off | ||
| + | bridge_fd 0 | ||
| + | bridge_maxwait 0 | ||
| + | </ | ||
| ====== Allow ping in host====== | ====== Allow ping in host====== | ||
| Line 116: | Line 160: | ||
| virt-manager | virt-manager | ||
| sudo virsh edit debiantesting | sudo virsh edit debiantesting | ||
| + | sudo virsh undefine paulawin10 ## Kill or destroy a domain | ||
| </ | </ | ||
| + | ===== Upgrading ===== | ||
| + | To increase the number of CPUs: | ||
| + | virsh setvcpus < | ||
| + | If you get an error that you exceeded the maximum number, first do: | ||
| + | virsh setvcpus < | ||
| + | Then repeat the above: | ||
| + | virsh setvcpus < | ||
| + | To increase the memory size: | ||
| + | virsh setmaxmem < | ||
| + | virsh setmem < | ||
| + | |||
| + | I'll test this at some point too: | ||
| + | sudo virsh setvcpus --domain test --maximum 2 --config | ||
| + | sudo virsh setvcpus --domain test --count 2 --config | ||
| + | sudo virsh reboot test | ||
| + | |||
| + | Please remember to SWITCH OFF the VM, and back on for the changes to take affect. | ||
| + | ====error: Requested operation is not valid: cannot undefine domain with nvram==== | ||
| + | < | ||
| ===== List all supported os-variants ===== | ===== List all supported os-variants ===== | ||
| < | < | ||
| Line 138: | Line 202: | ||
| </ | </ | ||
| + | |||
| + | < | ||
| + | qemu-system-x86_64 \ | ||
| + | -boot d \ | ||
| + | -cdrom " | ||
| + | -bios / | ||
| + | -nodefaults \ | ||
| + | -enable-kvm \ | ||
| + | -smp 8 \ | ||
| + | -device intel-hda \ | ||
| + | -device hda-duplex \ | ||
| + | -device virtio-vga-gl \ | ||
| + | -net nic \ | ||
| + | -net user, | ||
| + | -cpu host \ | ||
| + | -m 4096 \ | ||
| + | -display sdl,gl=on \ | ||
| + | -hda Android.img | ||
| + | </ | ||
| ===== Stop a running domain ===== | ===== Stop a running domain ===== | ||
| < | < | ||
| Line 145: | Line 228: | ||
| ===== Change network settings ===== | ===== Change network settings ===== | ||
| + | |||
| To get a list of all domains and ip detail run: | To get a list of all domains and ip detail run: | ||
| - | < | + | |
| + | < | ||
| + | sudo virsh net-dhcp-leases default | ||
| + | |||
| + | </ | ||
| If you need the mac adress, try: | If you need the mac adress, try: | ||
| - | < | + | |
| - | You can edit network settings by editing the default network with | + | < |
| - | < | + | sudo virsh domifaddr viswin10 |
| + | |||
| + | </ | ||
| + | |||
| + | You can edit network settings by editing the default network with | ||
| + | |||
| + | < | ||
| + | sudo virsh net-edit default | ||
| + | |||
| + | </ | ||
| As an example, here are my network settings for my 2 VMs (the lines starting with <host are what you're looking for): | As an example, here are my network settings for my 2 VMs (the lines starting with <host are what you're looking for): | ||
| + | |||
| < | < | ||
| < | < | ||
| Line 171: | Line 271: | ||
| </ip> | </ip> | ||
| </ | </ | ||
| + | |||
| </ | </ | ||
| - | After making the desired changes, run | + | |
| - | < | + | After making the desired changes, run |
| + | |||
| + | < | ||
| + | sudo virsh net-destroy default && sudo virsh net-start default && sudo systemctl restart libvirtd.service | ||
| + | |||
| + | </ | ||
| to restart the network (best done with no VMs running). | to restart the network (best done with no VMs running). | ||
| + | |||
| + | Or..... | ||
| + | |||
| + | |||
| + | < | ||
| + | |||
| + | |||
| + | =====Convert===== | ||
| + | qemu-img convert -f vdi -O qcow2 ./ | ||
| + | |||
| + | |||
| ====== GUI ====== | ====== GUI ====== | ||