Note: Realistically, a tutorial like this only makes sense if you're looking at the dialogue boxes while reading it. So, open Virt-Manager in one window and the tutorial in another (or on your phone). I think you'll find everything comes together pretty easily. The folks who designed Virt-Manager did a good job with the GUI. If you need help, feel free to open a thread on the Forum. Please post in the support section, though, not here.
Overview. In a nutshell, we're going to:
- Install Virt-Manager.
- Configure Virt-Manager.
- Create a VM.
- Configure the VM.
Installation. Sources differ somewhat on which packages they recommend for installing Virt-Manager. I've been happy with this command string (recommended by CwF):
Code: Select all
sudo apt install virt-manager qemu-system-x86 qemu-utils libvirt-daemon-system
Configuration. To open Virt-Manager, select from Menu (add to panel, if you like). Click on QEMU/KVM (a connection, in Virt-Manager lingo). Now you can access settings through the menu at top, e.g., File > New Virtual Machine.
By default, Virt-Manager stores VHDs in /var/lib/libvirt/images. VHDs are very large. As in, a 30 GB VHD = a file that size. This isn't usually a problem if you're using a single large system partition, but if you have split off home and/or data to a separate partition, your system partition probably doesn't have room for VHD files. The solution is to open Edit > Connection Details > Storage and add a new location ("pool") for VHDs. If feasible, a separate partition makes backup of regular data files simpler, but a mere folder on an already-present home or data partition also works.
Authorization. By default, Virt-Manager requires an admin password (root or sudo) to open. Generally, though, you want to run it as a regular user. There are a couple ways to do that, including user-session and polkit. The simplest (imho) is to add yourself to the libvirt group, sudo adduser $USER libvirt. Other users, even those without admin privileges, can be given Virt-Manager access by adding them to the same group. Be aware, although members of the libvirt group may use Virt-Manager without password authorization, the VM files (including VHDs) will be owned by user-root.
Autostart Network. Virt-Manager uses a virtual network adapter to give VMs internet access (piggy-backing on the host's access). By default, the virtual adapter is disabled (kinda silly). Enable with Edit > Connection Details > Virtual Networks > tick box to Autostart On Boot; click Apply. Won't take effect, though, until reboot host. Enable for this boot with sudo virsh net-start default.
For virtualization to work, it must be enabled in the firmware (UEFI/BIOS). Most computers ship with virtualization enabled by default, but a few do not. If unsure, open firmware settings and find the relevant entry. On some computers, an admin password must be set before settings can be modified (see computer manual for how-to).
Creating a VM. For your first VM, create a test box you won't mind deleting if it doesn't work out. From the main page, File > New Virtual Machine. Opens a wizard with five steps:
1. How to install. Usually local install media (for a new VM), but also can re-use an existing VHD (fresh start for VM settings).
2. Choose ISO (for new VM). Click Browse, which will take you to the Storage page mentioned above. First time, add a pool for location where you generally save ISO files. The same pool can be used for future installations. Select ISO from list; click Choose Volume. Will return to Step 2 box. Choose OS to install, meaning type of OS. AFAICT, automatically detect (the default) never works. Instead, untick and use search box. For Bookworm, I use debiantesting, which apparently Deb12 was when Virt-Manager was last updated. Click Forward button.
3. Choose memory and CPU settings. As a rule of thumb, assign half the available resources to the VM, reserving the other half for host. If that's not enough for either side, you shouldn't be using virtualization. Consider dual boot or full install to USB drive instead. Conversely, a super-duper gaming rig might be able to split RAM and CPU three or four ways.
4. Storage (VHD). Tick Select or create custom storage, then click Manage. Will take you (again) to the Storage page. Now is when you will select the pool created during the Virt-Manager configuration stage. Click + button to create a new VHD file; enter name, replacing debiantesting (for example) with a useful identifier, e.g., Deb12-Gnome. Leave format as qcow2 (unless you have very good reason for choosing raw). Don't bother with a backing store. Select capacity; my preference for most current Linux systems is 30 GB; can get away with 20 GB (the default) if don't plan to install much. I leave Allocate Now unticked (same as quick format, afaict, not dynamic disk sizing as in VBox). Click Choose Volume; will return to Step 4 box; click Forward.
5. Ready to begin. Enter VM name, usually the same one as used for the VHD, again replacing OS type (which is the default). Notice box to Customize configuration. This where you can select boot mode (UEFI instead of BIOS, the default). You also can set up a shared folder (see below), if planning to use one. Click Begin Installation (upper-left).
IMHO, there's not much reason for ordinary folks to use UEFI mode. It's mainly intended for developers, so they can confirm apps, drivers, etc. are secure boot compatible (or test registering them with MOK). FYI, there's a UEFI mode without secure boot (last option in a dropdown on the Configuration box), but it's incompatible with internal snapshot (see below).
Installer will go through the same steps as a regular installation. VHD will be assigned a device ID of vda (as distinguished from sda). Can be partitioned the same as a regular drive (GPT or MBR), including encryption. It's even possible to have more than one VHD, or share a VHD between two VMs. For now, just run the installer. Sometimes the installer session hangs at shutdown (rather than rebooting); in that case, use Force Off (menu or icon).
Configure VM. Most configurations come in with the operating system, same as installing to bare metal, but a few things are different for VMs.
First, a quick spin around the block. Open VM-Page; select run, either from menu (first row) or by clicking icon (second row). Usually Virt-Manager will switch automatically to Console view (showing the VM's desktop), but sometimes have to switch manually. Indeed, can switch manually at any time among Console view (desktop), Details (hardware and system info) and Snapshots while the VM is running. Also can switch to Virt-Manager itself or any other app running on the host. Will switch automatically if mouse-click somewhere outside Console (e.g., an icon on host's panel). Or tap Left-Ctrl+Left-Alt simultaneously, then Alt-Tab to cycle through open apps on host.
Display mode. By default, the VM desktop will display about 2/3's normal size, readable but smaller than the available space. There is a full screen mode, but it's relatively low resolution. (If enter accidentally, escape is with a pop-up at upper-center of screen, only visible when moused over.) The better solution is to install two packages in the VM: sudo apt install qemu-guest-agent spice-vdagent. Debian's standard installer will have installed the first one automatically, so only need to add the second. Reboot. From menu, select View > Scale Display > Auto resize. [This works with Gnome, Cinnamon and Flashback, but not the other desktops; there are workarounds for the latter, but they're a bit complicated.] By the way, the agent packages also enable copy to/from the host (using clipboard).
Shared Folders. A neat trick for accessing files on host. From the VM-Page, open Hardware Settings. Click Memory; tick box to enable sharing; click Apply. Click Add Hardware (lower-left); select Filesystem (two-thirds of the way down list); select source path (from Storage); give a label, e.g. data-files (misleadingly, called target path, but it's really just a label); click Finish. Boot VM. Create mount point. Can mount the share manually or add to fstab. For example, I have a data partition which mounts to /data/files on host. Storage label for the share in Virt-Manager is data-files (creative, eh?). Mount point for the share is a folder in Home called Data. Mount with:
Code: Select all
sudo mount -t virtiofs data-files $HOME/Data # to test, before adding to fstab
echo "data-files /home/pbear/Data virtiofs noatime,nofail 0 0" | sudo tee -a /etc/fstab
Other tips. Not trying to cover everything, but a few pointers.
USB devices. Can be attached to a VM with Virtual Machine > Redirect USB device. Works with drives, printers, and other peripherals. Works in a live session as well as an installed system. Device isn't available to host while attached to a VM. Storage media can be shared simultaneously, though, by adding host's /media folder (or other mount location) as a shared folder (I don't bother).
Snapshots. A handy feature of VMs is the ability to try something - installing an app, say - then unwind the trial with the click of a button. If you're familiar with snapshot in VBox, be aware Virt-Manager does it a little differently. Rather than a separate file with changes, Virt-Manager snapshots are internal, using a copy-on-write mechanism similar to btrfs. (QEMU can do external snapshots, but they're not supported by Virt-Manager.) To revert, right-click snapshot and select Start; or tap Run button at lower-left. To keep changes, simply delete the snapshot.
Windows. The walk-through above assumes both host and guest are running Linux. Virt-Manager can accommodate a Windows guest, but the steps are a bit different. Also, unless using GPU passthrough, performance reportedly isn't as good as VBox, so I'm continuing to use that for my Win10 VM. If you want to pursue Windows-in-Virt-Manager, there are many articles on the internet.
References: Website, GitHub, KVM, QEMU, libvirt, virsh, Debian, Arch, Gentoo, Manjaro, GPU passthrough.
Edited to clarify a few points, reflect feedback, and correct a few grammar or diction errors.