This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
kvm [2023/05/30 11:15] – vissie | kvm [2023/06/01 00:52] (current) – [Debian] vissie | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
+ | ===== Debian | ||
+ | <color red> | ||
+ | |||
+ | Some network advanced stuff: [[https:// | ||
< | < | ||
- | sudo groupadd unpriv_ping | + | |
- | sudo usermod | + | sudo apt install |
- | getent group unpriv_ping | cut -f 3 -d : | + | # 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 virsh net-list --all | ||
+ | sudo modprobe vhost_net | ||
</ | </ | ||
+ | |||
+ | As we can see in above output, default network is inactive so to make it active and auto-restart across the reboot by running the following commands, | ||
+ | |||
< | < | ||
- | + | sudo virsh net-start default | |
- | sudo vim / | + | sudo virsh net-autostart default |
</ | </ | ||
- | <sxh bash; gutter: false> … | + | =====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=' | ||
- | net.ipv4.ping_group_range = 1003 1003 | ||
- | … </ | + | |
+ | 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, | ||
< | < | ||
- | sysctl | + | echo " |
+ | lsmod | grep vhost | ||
</ | </ | ||
+ | < | ||
- | <color red>or </ | + | host_net |
- | + | vhost 49152 1 vhost_net | |
- | < | + | tap 28672 1 vhost_net |
- | sudo sysctl -w net.ipv4.ping_group_range=' | + | tun 49152 2 vhost_net |
</ | </ | ||
- | ====== Create HDDs ====== | + | 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 |
- | <sxh bash; gutter: false> # create a file " | + | <code> |
+ | sudo adduser pkumar libvirt | ||
+ | sudo adduser pkumar libvirt-qemu | ||
- | </sxh> | + | </code> |
- | ====== Running a VM ====== | + | To refresh or reload group membership run the followings, |
< | < | ||
- | sudo qemu-system-x86_64 -vga qxl -enable-kvm -m 2048 -smp 2 -cpu host -soundhw es1370 -device virtio-mouse-pci -device virtio-keyboard-pci -serial mon:stdio -boot menu=on -net nic -net user, | + | newgrp libvirt |
+ | newgrp libvirt-qemu | ||
</ | </ | ||
- | ====== | + | ======Setup Bridges Network====== |
+ | sudo vim / | ||
+ | <sxh bash; gutter: false> | ||
+ | # This file describes the network interfaces available on your system | ||
- | QEMU can forward ports from the host to the guest to enable e.g. connecting from the host to an SSH server running on the guest. For example, to bind port 10022 on the host with port 22 (SSH) on the guest, start QEMU with a command like: | + | source / |
- | < | + | # The loopback network interface |
- | qemu-system-x86_64 disk_image -nic user, | + | 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====== | ||
+ | < | ||
+ | sudo groupadd unpriv_ping | ||
+ | sudo usermod --append --groups unpriv_ping vissie | ||
+ | getent group unpriv_ping | cut -f 3 -d : | ||
</ | </ | ||
+ | < | ||
+ | sudo vim / | ||
+ | </ | ||
+ | <sxh bash; gutter: false> | ||
+ | ... | ||
- | ====== SPICE ====== | + | net.ipv4.ping_group_range |
- | <color red> | + | ... |
+ | </sxh> | ||
< | < | ||
+ | sysctl -p | ||
+ | </ | ||
- | sudo apt install spice-client-gtk | + | <color red>or </ |
+ | < | ||
+ | |||
+ | ====== Create HDDs ====== | ||
+ | <sxh bash; gutter: false> | ||
+ | # create a file " | ||
+ | qemu-img create -f qcow2 disk_image.img 40G | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====== Running a VM ====== | ||
+ | < | ||
+ | sudo qemu-system-x86_64 -vga qxl -enable-kvm -m 2048 -smp 2 -cpu host -soundhw es1370 -device virtio-mouse-pci -device virtio-keyboard-pci -serial mon:stdio -boot menu=on -net nic -net user, | ||
</ | </ | ||
- | You wanted copy and paste between | + | ====== Port Forward ====== |
+ | QEMU can forward ports from the host to the guest to enable e.g. connecting from the host to an SSH server running on the guest. | ||
+ | For example, to bind port 10022 on the host with port 22 (SSH) on the guest, | ||
+ | < | ||
+ | ====== SPICE ====== | ||
+ | <color red> | ||
+ | < | ||
+ | |||
+ | You wanted copy and paste between host and guest right? ;) | ||
+ | We need to add a virtio-serial device to the guest, and open a port for the spice vdagent. We also need to install the spice vdagent in guest. Be sure the agent is running (and for future, started automatically). | ||
+ | First the guest side, since the guest is running. | ||
< | < | ||
sudo apt install xserver-xorg-video-qxl spice-vdagent qemu-guest-agent | sudo apt install xserver-xorg-video-qxl spice-vdagent qemu-guest-agent | ||
sudo systemctl start spice-vdagent | sudo systemctl start spice-vdagent | ||
sudo systemctl enable spice-vdagent | sudo systemctl enable spice-vdagent | ||
- | |||
</ | </ | ||
Line 74: | Line 143: | ||
====== VNC ====== | ====== VNC ====== | ||
- | |||
< | < | ||
sudo apt install tigervnc-viewer | sudo apt install tigervnc-viewer | ||
sudo qemu-system-x86_64 -vga qxl -enable-kvm -m 2048 -smp 2 -cpu host -soundhw es1370 -device virtio-mouse-pci -device virtio-keyboard-pci -serial mon:stdio -boot menu=on -net nic -net user, | sudo qemu-system-x86_64 -vga qxl -enable-kvm -m 2048 -smp 2 -cpu host -soundhw es1370 -device virtio-mouse-pci -device virtio-keyboard-pci -serial mon:stdio -boot menu=on -net nic -net user, | ||
sudo netstat -npl | grep qemu | sudo netstat -npl | grep qemu | ||
- | |||
</ | </ | ||
- | |||
< | < | ||
Line 88: | Line 154: | ||
===== Working with domains ===== | ===== Working with domains ===== | ||
< | < | ||
- | |||
virsh list --all | virsh list --all | ||
virsh start server01 | virsh start server01 | ||
Line 96: | Line 161: | ||
sudo virsh edit debiantesting | sudo virsh edit debiantesting | ||
sudo virsh undefine paulawin10 ## Kill or destroy a domain | sudo virsh undefine paulawin10 ## Kill or destroy a domain | ||
- | |||
</ | </ | ||
===== Upgrading ===== | ===== Upgrading ===== | ||
- | |||
To increase the number of CPUs: | To increase the number of CPUs: | ||
- | + | | |
- | < | + | |
- | virsh setvcpus < | + | |
- | + | ||
- | </ | + | |
If you get an error that you exceeded the maximum number, first do: | If you get an error that you exceeded the maximum number, first do: | ||
- | + | | |
- | < | + | |
- | virsh setvcpus < | + | |
- | + | ||
- | </ | + | |
Then repeat the above: | Then repeat the above: | ||
- | + | | |
- | < | + | |
- | virsh setvcpus < | + | |
- | + | ||
- | </ | + | |
To increase the memory size: | To increase the memory size: | ||
- | + | | |
- | < | + | virsh setmem < |
- | virsh setmaxmem < | + | |
- | virsh setmem < | + | |
- | + | ||
- | </ | + | |
I'll test this at some point too: | I'll test this at some point too: | ||
- | + | | |
- | < | + | sudo virsh setvcpus --domain test --count 2 --config |
- | sudo virsh setvcpus --domain test --maximum 2 --config | + | sudo virsh reboot test |
- | 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. | 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==== | |
- | ==== error: Requested operation is not valid: cannot undefine domain with nvram ==== | + | < |
- | + | ||
- | < | + | |
- | sudo virsh undefine --nvram nameofvm | + | |
- | + | ||
- | </ | + | |
===== List all supported os-variants ===== | ===== List all supported os-variants ===== | ||
- | |||
< | < | ||
apt-get install libosinfo-bin | apt-get install libosinfo-bin | ||
osinfo-query os | osinfo-query os | ||
- | |||
</ | </ | ||
===== Start a install ===== | ===== Start a install ===== | ||
- | |||
< | < | ||
sudo virt-install --name kvmdeb \ | sudo virt-install --name kvmdeb \ | ||
Line 169: | Line 200: | ||
| | ||
| | ||
- | |||
</ | </ | ||
- | ===== Stop a running domain ===== | ||
+ | < | ||
+ | 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 ===== | ||
< | < | ||
virsh managedsave kvmdeb --verbose | virsh managedsave kvmdeb --verbose | ||
- | |||
</ | </ | ||
+ | |||
===== Change network settings ===== | ===== Change network settings ===== | ||
Line 235: | Line 283: | ||
to restart the network (best done with no VMs running). | to restart the network (best done with no VMs running). | ||
- | Or….. | + | Or..... |
- | < | ||
- | sudo virsh net-update default add-last ip-dhcp-host "< | ||
- | </ | + | < |
- | ===== Convert ===== | ||
- | < | + | =====Convert===== |
- | qemu-img convert -f vdi -O qcow2 ./ | + | qemu-img convert -f vdi -O qcow2 ./ |
- | </ | ||
====== GUI ====== | ====== GUI ====== | ||
===== virt-manager ===== | ===== virt-manager ===== | ||
- | |||
< | < | ||
virt-manager | virt-manager | ||
- | |||
</ | </ | ||
===== Spice ===== | ===== Spice ===== | ||
- | |||
< | < | ||
sudo apt install virt-viewer | sudo apt install virt-viewer | ||
- | |||
</ | </ | ||