{{admin guides}}

Server =

The following commands should be executed as the <code>root</code> user. This is going to be a headless system so no graphical components are necessary; <code>--no-install-recommends</code> will prevent them from being installed and lead to a lighter OS.
apt install --no-install-recommends qemu-kvm qemu-utils libvirt-clients libvirt-daemon-system netcat-openbsd dnsmasq

After installing these, the <code>libvirt</code> processes will start automatically so we can connect to it locally.

We also want a ''nonroot'' user for managing these VMs.
useradd -m <name> -s /bin/bash -G libvirt
mkdir /home/<name>/.ssh
cp ~/.ssh/authorized_keys /home/<name>/.ssh
chown -R <name>: /home/<name>

The next line is only necessary if you use [https:github.com/kovidgoyal/kitty/ kitty] as your terminal.
cp -r ~/.terminfo /home/<name>/
cp ~/.bashrc /home/<name>/
chown -R <name>: /home/<name>

Before setting your local machine up for managing VMs, download an image or two. I always recommend [https:www.debian.org/distrib/netinst Debian] of course. Depending on what application it'll be used for, you may want to consider [https:www.debian.org/devel/debian-installer/ Debian Testing] as it will have more up-to-date packages. I also recommend [https:alpinelinux.org/downloads/ Alpine Linux] if you want something more lightweight. Keep in mind, however, that this will require more setup. Unfortunately, some applications have a hard requirement for [https:ubuntu.com/download/server Ubuntu] so you may want to download that as well. All of these images should be stored in <code>/var/lib/libvirt/images</code>

Local =

{{Note|Switch this to [https:www.libvirt.org/manpages/virsh.html virsh] and document process|error}}
virt-manager will be used to manage these VMs and it can be installed on virtually (heh) any Linux system.
apt-get install virt-manager (Debian/Ubuntu)
pacman -S virt-manager (Arch)
yum install virt-manager (Fedora)
emerge virt-manager (Gentoo)
pkg_add virt-manager (OpenBSD)

Open the ''Virtual Machine Manager'' application then go to <code>File</code> -> <code>Add connection</code>. Set the first field to <code>QEMU/KVM</code>, check the SSH box, fill in <code>Username</code> with what you used above for <code><name></code>, and your hostname is whatever you have set in your SSH config. I also recommend checking <code>Autoconnect</code> but it's not absolutely necessary.

VM creation is very specific to the service you'll be running in it. However, here is a general overview. To create a new VM, click the button in the top left then choose <code>Local install media</code> then click <code>Browse</code>. You'll be able to choose your <code>.iso</code> there. After making your selection, clear the text in the <code>Choose the operating system . . .</code> field then start typing the name of whatever the OS. In the case of <code>debian-10.4.0-amd64-netinst.iso</code>, you'd want to type <code>Debian</code> then select <code>Debian 10</code>. Continue and allocate whatever RAM/CPU you want to give the server; The defaults will generally be adequate but you may want to bump them up a little. Storage is even more specific to the service but 30 GB will ''typically'' do well unless you're running a storage or media server. In those cases, you'll want a ''lot'' more. Continuing, name the volume whatever you'd like (<code>nc1</code> for Nextcloud, <code>ws1</code> for a webserver, something along those lines), and optionally tick the box to <code>Customise configuration before install</code>. I do recommend this as you'll be able to delete some extraneous features like a virtual sound card.

VM config ==

#Boot Options
##✅ Start virtual machine on host boot up
#Right-click and remove <code>Sound <card></code>

Unless you know you want to change something else, leave the rest as it is for now and click <code>✅ Begin Installation</code> at the top of that window. Once it's finished, you'll be dropped to the OS's installer screen. See the related guides for Debian, Alpine, and Ubuntu.

Category:Admin guides