RackNerd Billboard Banner

Configuring a New KVM on Arch Linux Using QEMU CLI

If you’re running Arch Linux and want full control over your virtual machines, skipping the GUI and working directly with the QEMU CLI is the way to go. This post walks you through setting up a new Kernel-based Virtual Machine (KVM) using QEMU from the command line. No fluff—just the essential steps to get a VM up and running fast.

📌 Prefer a graphical interface? Check out Create a New KVM on Arch Linux Using virt-manager.

Prerequisites

Before diving in, make sure your system is ready:

1. Hardware Virtualization Support

Check that your CPU supports virtualization:

egrep -c '(vmx|svm)' /proc/cpuinfo

If the output is 0, your CPU doesn’t support virtualization, or it’s disabled in BIOS.

2. Install Required Packages

If you haven’t already installed KVM tools on Arch, follow the steps in How to Install a KVM in Arch Linux for a full setup.

Or use:

sudo pacman -S qemu virt-manager virt-viewer dnsmasq vde2 bridge-utils openbsd-netcat
sudo systemctl enable --now libvirtd

You can skip virt-manager and virt-viewer if you’re strictly CLI-only.

Add your user to the libvirt group:

sudo usermod -aG libvirt $(whoami)

Log out and back in to apply group changes.


Step-by-Step: Launch a New VM with QEMU CLI

1. Create a Disk Image

Use QEMU’s qemu-img tool to create a virtual hard disk:

qemu-img create -f qcow2 ~/vms/arch_vm.qcow2 20G

This creates a 20GB disk image using the efficient QCOW2 format.

2. Download an ISO

Grab your preferred Linux ISO. For example, to get the Arch Linux ISO:

curl -O https://mirror.rackspace.com/archlinux/iso/latest/archlinux-x86_64.iso

3. Boot the Installer

Now run QEMU with appropriate flags to boot from the ISO and start the install:

qemu-system-x86_64 \
  -enable-kvm \
  -m 4096 \
  -cpu host \
  -smp 2 \
  -boot d \
  -cdrom archlinux-x86_64.iso \
  -drive file=~/vms/arch_vm.qcow2,format=qcow2 \
  -net nic -net user \
  -display gtk

Key options:

  • -enable-kvm: Enables KVM acceleration.
  • -m 4096: Allocates 4GB RAM.
  • -cpu host: Uses your host CPU features.
  • -smp 2: Two CPU cores.
  • -boot d: Boots from CD-ROM first.
  • -net user: Simple user-mode networking.
  • -display gtk: Opens a GTK window for easy interaction.

Swap -display gtk with -nographic for a headless install.


Optional: Enable Bridged Networking

For full LAN access (instead of NAT):

  1. Create a bridge interface (br0).
  2. Use -netdev bridge,id=hn0,br=br0 and -device virtio-net-pci,netdev=hn0.

But for most simple use cases, -net user works fine.


Final Notes

Once the VM boots, follow the regular Arch installation process inside the QEMU window. After that, you can create scripts or aliases to boot the VM without the installer:

qemu-system-x86_64 \
  -enable-kvm \
  -m 4096 \
  -cpu host \
  -smp 2 \
  -drive file=~/vms/arch_vm.qcow2,format=qcow2 \
  -net nic -net user \
  -display gtk

Wrapping Up

QEMU + KVM on Arch Linux gives you a powerful, lightweight way to run virtual machines without the overhead of a full virtualization suite. You stay in control, and everything is scriptable. If you’re comfortable in the terminal, it’s hard to beat.

Let me know in the comments if you want a follow-up on snapshot management, bridged networking, or headless automation.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

RackNerd Billboard Banner
Copy link