[SOLVED] Failed to run: mkfs.ext4 when creating new instance on LVM volume

Hi. My distro is NixOS 20.09 using lxd 4.5 and lxc 4.0.4. Basically I would like to use LVM as a storage backend.

I have a thin storage pool configured:

$ sudo lvs
  LV                                                                      VG   Attr       LSize   Pool       Origin Data%  Meta%  Move Log Cpy%Sync Convert
  containers                                                              pool twi-aotz--  20.00g                   0.00   10.59                           
  images_219b18ffc182595bc3491680b9ad06022f1e200a12d707fa419a2202014eb017 pool Vwi-a-tz--  <9.32g containers        0.00                                   
  win10_vm                                                                pool -wi-ao---- 100.00g                                                          
$ lxc storage show lvm_pool
  lvm.thinpool_name: containers
  lvm.vg.force_reuse: "true"
  lvm.vg_name: pool
  source: pool
  volatile.initial_source: pool
description: ""
name: lvm_pool
driver: lvm
used_by: []
status: Created
- none

The volume images_219b18ffc182595bc3491680b9ad06022f1e200a12d707fa419a2202014eb017 is the one created during instantiation just before failing to run mkfs.ext4.

$ lxc launch images:archlinux arch -s lvm_pool
Creating arch
Error: Failed instance creation: Create instance from image: Error creating LVM logical volume: Error making filesystem on LVM logical volume: Failed to run: mkfs.ext4 /dev/pool/images_219b18ffc182595bc3491680b9ad06022f1e200a12d707fa419a2202014eb017 -E nodiscard,lazy_itable_init=0,lazy_journal_init=0: 

I have already seen #7858 but I don’t believe it’s the same problem here. I can run mkfs.ext4 successfully in my terminal using the same arguments as above.

A similar failure to run mkfs.ext4 also occurs if I try to move or copy a container from my default storage to the lvm_pool storage.

I would greatly appreciate any guidance, thanks.

It looks like the issue was with NixOS, more specifically e2fsprogs was not in the path of the lxd daemon. I will leave the solution here in case other Nix users have this problem:

In /etc/nixos/configuration.nix add the following line to put the necessary programs in lxd’s path.

systemd.services.lxd.path = with pkgs; [ lvm2 thin-provisioning-tools e2fsprogs ];