LVM under runInLinuxVM

I’m writing a custom disk image builder based on make-disk-image.nix with support for LVM and LUKS.

Unfortunately, I’ve hit a roadblock as I can’t seem to create LVM logical volumes under the builder VM.

When I do something like lvcreate -L4G -n myVol myVg, I get:

++ parted -s /dev/vda -- mklabel msdos mkpart primary 2048s 100%                                                                                                          
++ pvcreate /dev/vda1                                                                                                                                                     
  Physical volume "/dev/vda1" successfully created.                                                                                                                       
++ vgcreate system /dev/vda1                                                                                                                                              
  Volume group "system" successfully created                                                                                                                              
++ lvcreate -L 128M -n boot system                                                                                                                                        
  /dev/system/boot: not found: device not cleared                                                                                                                         
  Aborting. Failed to wipe start of new LV.

I initially thought of doing it like the original one does and set up all the partitions during prepareImage (which is executed in the host Nix system) but realized that it won’t work because doing so would be impure and the Nix builder user cannot execute LVM commands anyway, so I needed to do it inside the builder VM.

I do understand that the builder VM is running a very minimal NixOS system (I’ve read the stage1/2 init scripts) and some research says it might have to do with udev not running. But before I attempt to turn runInLinuxVM inside-out and write my own version, I wanted to hear if somebody has had success with this topic before.

Specifying -Zn during lvcreate seems to work, I’m able to create LUKS containers on top of the LVs as well. Although I do wonder what the effects of not zeroing out the LV are.

Do you happen to still have this image builder lying around? I’m attempting something similar and would be glad about some inspiration. :slight_smile:

I do, but you should check out Disko instead for a more comprehensive disk partitioning/formatting solution.

That looks very promising, thank you very much! Now I just need to figure out how to use it with nixos-generators. :smiley: