KVM

From The World according to Vissie
Jump to navigation Jump to search

Install on Debian

https://linuxhint.com/install_kvm_debian_10/

Some network advanced stuff:

https://www.linuxtechi.com/install-configure-kvm-debian-10-buster/
sudo apt install qemu-kvm
sudo systemctl status libvirtd.service
sudo virsh net-list --all
sudo modprobe vhost_net

Allow ping in host

sudo groupadd unpriv_ping
sudo usermod --append --groups unpriv_ping vissie
getent group unpriv_ping | cut -f 3 -d :
#111
sudo vim /etc/sysctl.conf
...
net.ipv4.ping_group_range = 1003 1003

...
sysctl -p

or

sudo sysctl -w net.ipv4.ping_group_range='0 2147483647'

Create HDDs

# create a file "disk_image" with format qcow2 and 40GB of max space
qemu-img create -f qcow2 disk_image 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,hostfwd=tcp::5555-:22 -hda ./kvmdeb.img

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, start QEMU with a command like:

qemu-system-x86_64 disk_image -nic user,hostfwd=tcp::10022-:22

VNC

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,hostfwd=tcp::5555-:22 -hda ./kvmdeb.img -vnc 127.0.0.1:0
sudo netstat -npl | grep qemu
vncviewer 127.0.0.1:0

Some commands

Working with domains

virsh list --all
virsh start server01
virsh vncdisplay server01

List all supported os-variants

apt-get install libosinfo-bin
osinfo-query os

Start a install

sudo virt-install --name kvmdeb \
   --os-type linux \
   --os-variant debian10 \
   --ram 2048 \
   --disk /kvm/disk/kvmdeb.img,device=disk,bus=virtio,size=20,format=qcow2 \
   --graphics vnc,listen=0.0.0.0 \
   --noautoconsole \
   --hvm \
   --cdrom /kvm/iso/debian-10.5.0-amd64-netinst.iso \
   --boot cdrom,hd

Stop a running domain

virsh managedsave kvmdeb --verbose


GUI

Try the GUI stuff some time....

virt-manager

virt-manager 

Spice

sudo apt install virt-viewer