Ditching Vagrant: VMs with KVM and Virsh on Debian
This post chronicles a developer's journey from the perceived overhead of Vagrant to direct KVM, libvirt, and virsh management for virtual machines on Debian. It offers a detailed, hands-on guide to automated VM setup using preseeding and virt-install. HN found value in this deep dive into foundational Linux virtualization, appealing to those seeking more control and less abstraction in their development environments.
The Lowdown
The author recounts their decision to move away from Vagrant, which they initially found convenient but later perceived as an unnecessary layer of abstraction for VM management. Driven by a desire for a deeper understanding and control, they transitioned to using KVM, libvirt, and its command-line interface, virsh, directly on Debian. This post serves as a practical guide to this transition, detailing the setup and common tasks.
- Vagrant's Over-abstraction: The author found Vagrant, despite its initial utility with VirtualBox and later libvirt, to be "too much software" and an unnecessary abstraction when KVM is natively integrated into the Linux kernel.
- KVM, libvirt, and virsh Explained: The core components are introduced: KVM as the kernel hypervisor, libvirt as the unifying management library/daemon for various virtualization platforms, and virsh as its command-line frontend. Installation and useful commands for each are provided.
- Automated VM Provisioning with Preseeding: A key section addresses a problem with serial output after a Debian upgrade, leading to the adoption of preseeding with
virt-install. This method enables deterministic, versionable VM creation by pre-answering installation questions. virt-installDeep Dive: A comprehensivevirt-installcommand example is broken down, explaining parameters like--connect,--name,--memory,--extra-args(for preseeding and console),--initrd-inject,--disk,--filesystem,--network, and--graphics.- Network and Storage Configuration: The article details how libvirt sets up networking (virbr0, DHCP, TAP devices) and how to mount shared directories using the 9P protocol, noting a permission issue workaround.
- SSH Agent Forwarding: A brief guide on enabling SSH agent forwarding into the new VMs is included.
The author concludes that virsh provides sufficient functionality for their VM creation needs, offering a more direct and less abstracted approach compared to Vagrant, providing a practical blueprint for others looking to embrace native Linux virtualization.
The Gossip
Container Contemplations
Some commenters questioned the necessity of full virtual machines for development, suggesting lighter alternatives. Ideas floated included containerization tools like distrobox/toolbox for isolation or looking towards systemd's vmspawn for a more integrated approach to managing system, containers, and VMs under a single, consistent roof.
Virt-manager's Vexing Virtues
A significant discussion emerged around `virt-manager`, the graphical front-end for libvirt. While some users reminisced about its utility, others expressed strong dissatisfaction, citing issues with hidden VM files, restrictive permissions, and a tedious VM creation workflow. Conversely, defenders highlighted its configurability, remote management capabilities over SSH, and the option to bypass OS presets for a generic installation.