From 7219d81468abab148f786a4bd03a39e5ac53f3d3 Mon Sep 17 00:00:00 2001 From: Trent Palmer Date: Fri, 8 Oct 2021 00:15:57 -0700 Subject: [PATCH] add kvm-on-arch.md --- docs/posts/kvm-on-arch.md | 125 ++++++++++++++++++++++++++++++++++++++ mkdocs.yml | 2 + 2 files changed, 127 insertions(+) create mode 100644 docs/posts/kvm-on-arch.md diff --git a/docs/posts/kvm-on-arch.md b/docs/posts/kvm-on-arch.md new file mode 100644 index 0000000..9f17961 --- /dev/null +++ b/docs/posts/kvm-on-arch.md @@ -0,0 +1,125 @@ +--- +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` diff --git a/mkdocs.yml b/mkdocs.yml index 451a22b..ee76aad 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -24,6 +24,7 @@ markdown_extensions: nav: - Home: - Home: index.md + - "KVM On Arch": posts/kvm-on-arch.md - "RaspberryPi LTE-Failover Router With DNS Caching": posts/raspberrypi-lte-failover-router-with-dns-caching.md - "Flutter Integration Test Server in Debian 11 Nspawn Container": posts/debian-11-nspawn-flutter-integration-test-server.md - "Debian 11 TT-RSS": posts/debian-11-ttrss.md @@ -61,6 +62,7 @@ nav: - FreeCodeCampChallenges: https://trentspalmer.github.io/fcc-challenges/ - DeviceLayout: https://trentpalmer.work/6a57bbe24d8244289610bf57533d6c6f/ - Posts: + - "KVM On Arch": posts/kvm-on-arch.md - "RaspberryPi LTE-Failover Router With DNS Caching": posts/raspberrypi-lte-failover-router-with-dns-caching.md - "Flutter Integration Test Server in Debian 11 Nspawn Container": posts/debian-11-nspawn-flutter-integration-test-server.md - "Debian 11 TT-RSS": posts/debian-11-ttrss.md