--- title: "KVM On Arch" date: 2021-10-07 draft: false tags: ["Arch", "linux", "kvm", "virtualmachine"] authors: ["trent"] post: 24 --- date: 2021-10-07 ## Introduction This is not intended to be a tutorial, but rather a walk-through of how I would install [libvirt/kvm on Arch Linux](https://wiki.archlinux.org/title/Libvirt){target="_blank"}. ## Packages * iptables-nft * dnsmasq * bridge-utils * openbsd-netcat * libvirt * qemu-headless * virt-install `virt-install` is not needed if connecting remotely with virt-manager, but it does provide `virt-clone`. ## Configuration * enable libvirtd service * `systemctl enable libvirtd` * add user to libvirt group * `usermod -a -G libvirt ` ### environment/bashrc ```cfg # ~/.bashrc export LIBVIRT_DEFAULT_URI="qemu:///system" ``` reboot the machine ## Network The default network is defined in `/etc/libvirt/qemu/networks/default.xml`. * Start the default network `virsh net-start default`. * Permanently enable the default network `virsh net-autostart default`. ## Jump Host With `virt-manager` Abstract your jump host in `~/.ssh/config` ```cfg # ~/.ssh/config Host jumphost Hostname Port 22 User Host kvmhost Hostname ProxyJump jumphost Port 22 User ``` Now you can connect `virt-manager` to @kvmhost ## Console Access Enable serial console on guest. `systemctl enable serial-getty@ttyS0.service` ## Nested KVM I was going to try to figure out how to permantly set the cpu mode default such that all virtualmachines will be capable of nested virtualization, but it already is. Perhaps that is the default in `virt-manager` now? Anyway, in case you want to make sure [nested virtualization](https://wiki.archlinux.org/title/KVM#Nested_virtualization){target="_blank"} is enabled in the host kernel. ## Clone Ip Address Conflict I found a great tutorial [for assigning ip addresses](https://bobcares.com/blog/virsh-set-ip-address/){target="_blank"}. The problem we need to solve here is that virtual machine clones won't necessarily solicit a unique ip address, although a clone will have a new `mac address`. So, you clone a vm: * `virt-clone --original arch --name archone --auto-clone` Get the clone's mac address: * `virsh dumpxml archone | grep mac` ### Now assign the clone a dhcp reservation: * `virsh net-edit default` Notice that I tighten up the dhcp range, and add a reservation outside the new dhcp range. ```xml default 8013c9a5-606f-48a0-a3ec-1cf097e76fb1 ``` ### Restart Default Network * `virsh net-destroy default` * `virsh net-start default`