User Tools

Site Tools


kvm

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
kvm [2021/05/21 05:30] – [Change network settings] vissiekvm [2023/06/01 00:52] (current) – [Debian] vissie
Line 6: Line 6:
 Some network advanced stuff: [[https://www.linuxtechi.com/install-configure-kvm-debian-10-buster/|https://www.linuxtechi.com/install-configure-kvm-debian-10-buster/]] Some network advanced stuff: [[https://www.linuxtechi.com/install-configure-kvm-debian-10-buster/|https://www.linuxtechi.com/install-configure-kvm-debian-10-buster/]]
 <code> <code>
-sudo apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils+ 
 +sudo apt install --no-install-recommends qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virtinst dnsmasq qemu-utils ovmf 
 +#  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
 +
 </code> </code>
  
Line 17: Line 21:
 sudo virsh net-start default sudo virsh net-start default
 sudo virsh net-autostart default sudo virsh net-autostart default
 +
 </code> </code>
 +
 +=====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='open'/>.
 +
 +
  
 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 "vhost_net" | sudo  tee -a /etc/modules echo "vhost_net" | sudo  tee -a /etc/modules
 lsmod | grep vhost lsmod | grep vhost
 +
 </code> </code>
 <code> <code>
 +
 host_net               24576  0 host_net               24576  0
 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
 +
 </code> </code>
 +
 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
 +
 <code> <code>
 sudo adduser pkumar libvirt sudo adduser pkumar libvirt
 sudo adduser pkumar libvirt-qemu sudo adduser pkumar libvirt-qemu
 +
 </code> </code>
 +
 To refresh or reload group membership run the followings, To refresh or reload group membership run the followings,
 +
 <code> <code>
 newgrp libvirt newgrp libvirt
 newgrp libvirt-qemu newgrp libvirt-qemu
 +
 </code> </code>
 +
 +======Setup Bridges Network======
 +  sudo vim /etc/network/interfaces
 +<sxh bash; gutter: false>  
 +# This file describes the network interfaces available on your system
 +
 +source /etc/network/interfaces.d/*
 +
 +# 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   
 +</sxh>
  
 ====== 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
 </code> </code>
  
 +===== Upgrading =====
 +To increase the number of CPUs:
 +  virsh setvcpus <vm_name> <vcpu_count> --config
 +If you get an error that you exceeded the maximum number, first do:
 +  virsh setvcpus <vm_name> <vcpu_count> --config --maximum
 +Then repeat the above:
 +  virsh setvcpus <vm_name> <vcpu_count> --config
 +To increase the memory size:
 +  virsh setmaxmem <vm_name> <memsize> --config
 +  virsh setmem <vm_name> <memsize> --config
 +
 +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====
 +<code>sudo virsh undefine --nvram nameofvm</code>
 ===== List all supported os-variants ===== ===== List all supported os-variants =====
 <code> <code>
Line 138: Line 202:
 </code> </code>
  
 +
 +<code>
 +qemu-system-x86_64 \
 +  -boot d \
 +  -cdrom "Bliss-v14.10-x86_64-OFFICIAL-opengapps-20221027.iso" \
 +  -bios /usr/share/ovmf/x64/OVMF.fd \
 +  -nodefaults \
 +  -enable-kvm \
 +  -smp 8 \
 +  -device intel-hda \
 +  -device hda-duplex \
 +  -device virtio-vga-gl \
 +  -net nic \
 +  -net user,hostfwd=tcp::5555-:5555 \
 +  -cpu host \
 +  -m 4096 \
 +  -display sdl,gl=on \
 +  -hda Android.img
 +</code>
 ===== Stop a running domain ===== ===== Stop a running domain =====
 <code> <code>
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:
-<code>sudo virsh net-dhcp-leases default</code>+ 
 +<code> 
 +sudo virsh net-dhcp-leases default 
 + 
 +</code> 
 If you need the mac adress, try: If you need the mac adress, try:
-<code>sudo virsh domifaddr viswin10</code> + 
-You can edit network settings by editing the default network with  +<code> 
-<code>sudo virsh net-edit default</code>+sudo virsh domifaddr viswin10 
 + 
 +</code> 
 + 
 +You can edit network settings by editing the default network with 
 + 
 +<code> 
 +sudo virsh net-edit default 
 + 
 +</code> 
 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):
 +
 <code> <code>
 <network> <network>
Line 171: Line 271:
   </ip>   </ip>
 </network> </network>
 +
 </code> </code>
-After making the desired changes, run  + 
-<code>sudo virsh net-destroy default && sudo virsh net-start default && sudo systemctl restart libvirtd.service</code>+After making the desired changes, run 
 + 
 +<code> 
 +sudo virsh net-destroy default && sudo virsh net-start default && sudo systemctl restart libvirtd.service 
 + 
 +</code> 
 to restart the network (best done with no VMs running). to restart the network (best done with no VMs running).
 +
 +Or.....
 +
 +
 +<code>sudo virsh net-update default add-last ip-dhcp-host "<host mac='52:54:00:b0:59:5e' name='maurits-cloud' ip='192.168.122.10'/>" --live --config</code>
 +
 +
 +=====Convert=====
 +  qemu-img convert -f vdi -O qcow2 ./Lineage.vdi ./Lineage.qcow2
 +
 +
 ====== GUI ====== ====== GUI ======
  
kvm.1621600212.txt.gz · Last modified: 2021/05/21 05:30 by vissie