Storing KVM Virtual Machine Disks on a NAS (Proxmox / libvirt)

April 27, 2022
English
中文
interestring

Prerequisites

The concepts and software you should know before reading:

Concepts

  • Basic use of KVM
  • Basic use of a NAS
  • Familiarity with the shell mount command
  • Common disk formats

Software

  • KVM
  • cifs-utils
  • An .iso file for any operating system

Preface & Background (a bit of a rant)

My main machine broke recently, so I brought up a spare Ubuntu host. That machine's disk is only 256G, so whenever I absolutely need Windows I run it as a KVM virtual machine.
As everyone knows, Windows software and the operating system itself are both rather large, so I wondered: could the whole virtual machine just be thrown onto the NAS? That question is where the following pitfalls, detours and fixes came from.

Pitfall 1 — Permission problems when KVM uses a NAS mount point

This happened when I chose to create a new virtual machine and wanted to use a NAS directory as the VM installation directory.
Intuitively it looked like KVM simply lacked the permission, so I first tried sudo virt-manager, raising the KVM management GUI to ROOT level — yet even running as ROOT gave the very same error. After some searching I found that the default user of the libvirtd service is different from the current system user, and that user = and group = in /etc/libvirt/qemu.conf must be changed before anything takes effect. Still, always running KVM with ROOT privileges is not elegant. The final solution was to mount the NAS share manually and specify the uid of the mount point, with the command: mount -t cifs -o username=<nas user>,vers=3.11,nobrl,uid=libvirt-qemu //<nas domain>/<nas path> /<path>/<your>/<store> Link to the original solution

Pitfall 2 — Disk type problems when mounting the NAS manually

Mounting the NAS manually can produce the error shown above. This is because /sbin/mount.cifs has not been created (you can check with ls -l /sbin/mount.cifs). Installing it with sudo apt install cifs-utils solves the problem.

Link to the original solution

At this point, setting the virtual machine installation directory through the KVM GUI no longer runs into permission problems. Note that the installation directory you select must be the /<path>/<your>/<store> part of the mount command, not the one the system discovers automatically — otherwise the permission problem comes straight back.