I have the following hierarchy of block devices.
In particular, nvme0n1p2 is a LUKS-encrypted partition (cryptoroot), which constitutes an LVM physical volume.
I use the physical volume for creating a volume group named lvm, and the volume group contains two logical volumes for swap and Btrfs root.
[nix-shell:~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1 259:0 0 1.8T 0 disk
├─nvme0n1p1 259:1 0 511M 0 part /boot
└─nvme0n1p2 259:2 0 1.8T 0 part
└─cryptoroot 254:0 0 1.8T 0 crypt
├─lvm-swap 254:1 0 32G 0 lvm [SWAP]
└─lvm-btrfs--root 254:2 0 1.8T 0 lvm /home
[nix-shell:~]$ sudo pvscan
PV /dev/mapper/cryptoroot VG lvm lvm2 [<1.82 TiB / 0 free]
Total: 1 [<1.82 TiB] / in use: 1 [<1.82 TiB] / in no VG: 0 [0 ]
[nix-shell:~]$ sudo vgscan
Found volume group "lvm" using metadata type lvm2
[nix-shell:~]$ sudo lvscan
ACTIVE '/dev/lvm/swap' [32.00 GiB] inherit
ACTIVE '/dev/lvm/btrfs-root' [<1.79 TiB] inherit
I created Btrfs filesystem on one of the subvolumes (/dev/lvm/btrfs-root) directly with three subvolumes for the filesystem root (subvol=/root), the home directories (subvol=/home), and the nix store (sobvol=/nix) as shown below.
[nix-shell:~]$ mount
/dev/mapper/lvm-btrfs--root on / type btrfs (rw,relatime,ssd,space_cache,subvolid=256,subvol=/root)
/dev/mapper/lvm-btrfs--root on /nix type btrfs (rw,relatime,ssd,space_cache,subvolid=258,subvol=/nix)
/dev/mapper/lvm-btrfs--root on /nix/store type btrfs (ro,relatime,ssd,space_cache,subvolid=258,subvol=/nix)
/dev/nvme0n1p1 on /boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)
/dev/mapper/lvm-btrfs--root on /home type btrfs (rw,relatime,ssd,space_cache,subvolid=257,subvol=/home)
...[snip]...
Problem
With this setup, nixos-generate-config does not generate LUKS entry (boot.initrd.luks.devices."cryptoroot".device = ...), which makes the system unbootable without manual modification to hardware-configuration.nix.
Apparently, /sys/class/block/dm-0, which I think corresponds to the LVM volume group, is on the LUKS device, and if I manually inserted boot.initrd.luks.devices according to /sys/class/block/dm-0 the system becomes bootable.
Steps To Reproduce
I try to recall the commands, but the exact steps might be inaccurate.
In the following steps, I assume the name of the physical device is nvme0n1.
Boot the system from a Live USB.
Create partitions on /dev/nvme0n1/.
parted /dev/nvme0n1 -- mklabel gpt
Create /dev/nvme0n1p1 for /boot by parted /dev/nvme0n1 -- mkpart ESP fat32 1MiB 512MiB
Create /dev/nvme0n1p2 for / by parted /dev/nvme0n1 -- mkpart primary 512MiB 100%
parted /dev/nvme0n1 -- set 1 esp on
Create a LUKS device /dev/mapper/cryptoroot on /dev/nvme0n1p2
cryptsetup luksFormat /dev/nvme0n1p2
cryptsetup luksOpen /dev/nvme0n1p2, which gives me /dev/mapper/cryptoroot
Set up LVM logical volumes on /dev/mapper/cryptoroot and populate filesystems such as /dev/lvm/btrfs-root on the logical volumes
pvcreate /dev/mapper/cryptoroot
vgcreate lvm /dev/mapper/cryptoroot
lvcreate --size 32G --name swap lvm
lvcreate --extents 100%FREE --name btrfs-root lvm
mkswap /dev/lvm/swap (swapon /dev/lvm/swap)
mkfs.btrfs /dev/lvm/btrfs-root
Mount btrfs-root for creating Btrfs subvolumes
mount -t btrfs /dev/lvm/btrfs-root /mnt
btrfs subvolume create /mnt/root
btrfs subvolume create /mnt/home
btrfs subvolume create /mnt/nix
umount /mnt
Mount the Btrfs subvolumes and the boot partition at the appropriate places
mount -o subvol=/root,compress=zstd,noatime /dev/mapper/cryptoroot /mnt
mkdir /mnt/home && mount -o subvol=/home,compress=zstd,noatime /dev/mapper/cryptoroot /mnt/home
mkdir /mnt/nix && mount -o subvol=/nix,compress=zstd,noatime /dev/mapper/cryptoroot /mnt/nix
mkdir /mnt/boot && mount nvme0n1p1 /mnt/boot
nixos-generate-config does not generate boot.initrd.luks.devices."cryptoroot".device = ....
Expected behavior
nixos-generate-config should generate an entry for boot.initrd.luks.devices."cryptoroot".device = ....
Additional context
My system does not contain /sys/class/block/lvm-btrfs--root/ as shown below, which confuses LUKS detection.
Describe the bug
Context
I have the following hierarchy of block devices. In particular,
nvme0n1p2
is a LUKS-encrypted partition (cryptoroot
), which constitutes an LVM physical volume. I use the physical volume for creating a volume group namedlvm
, and the volume group contains two logical volumes for swap and Btrfs root.I created Btrfs filesystem on one of the subvolumes (
/dev/lvm/btrfs-root
) directly with three subvolumes for the filesystem root (subvol=/root
), the home directories (subvol=/home
), and the nix store (sobvol=/nix
) as shown below.Problem
With this setup,
nixos-generate-config
does not generate LUKS entry (boot.initrd.luks.devices."cryptoroot".device = ...
), which makes the system unbootable without manual modification tohardware-configuration.nix
.As far as I understand,
nixos-generate-config
enumerates filesystem mounts and checks if the mounted filesystem is on a LUKS device by checking/sys/class/block/$deviceName
. In my case,$deviceName
islvm-btrfs--root
(the basename of/dev/mapper/lvm-btrfs--root
), though/sys/class/block/lvm-btrfs--root
does not exist, which makesnixos-generate-config
believe the device is not on a LUKS device (see additional context).Apparently,
/sys/class/block/dm-0
, which I think corresponds to the LVM volume group, is on the LUKS device, and if I manually insertedboot.initrd.luks.devices
according to/sys/class/block/dm-0
the system becomes bootable.Steps To Reproduce
I try to recall the commands, but the exact steps might be inaccurate. In the following steps, I assume the name of the physical device is
nvme0n1
./dev/nvme0n1/
.parted /dev/nvme0n1 -- mklabel gpt
/dev/nvme0n1p1
for/boot
byparted /dev/nvme0n1 -- mkpart ESP fat32 1MiB 512MiB
/dev/nvme0n1p2
for/
byparted /dev/nvme0n1 -- mkpart primary 512MiB 100%
parted /dev/nvme0n1 -- set 1 esp on
/dev/mapper/cryptoroot
on/dev/nvme0n1p2
cryptsetup luksFormat /dev/nvme0n1p2
cryptsetup luksOpen /dev/nvme0n1p2
, which gives me/dev/mapper/cryptoroot
/dev/mapper/cryptoroot
and populate filesystems such as/dev/lvm/btrfs-root
on the logical volumespvcreate /dev/mapper/cryptoroot
vgcreate lvm /dev/mapper/cryptoroot
lvcreate --size 32G --name swap lvm
lvcreate --extents 100%FREE --name btrfs-root lvm
mkswap /dev/lvm/swap
(swapon /dev/lvm/swap
)mkfs.btrfs /dev/lvm/btrfs-root
btrfs-root
for creating Btrfs subvolumesmount -t btrfs /dev/lvm/btrfs-root /mnt
btrfs subvolume create /mnt/root
btrfs subvolume create /mnt/home
btrfs subvolume create /mnt/nix
umount /mnt
mount -o subvol=/root,compress=zstd,noatime /dev/mapper/cryptoroot /mnt
mkdir /mnt/home && mount -o subvol=/home,compress=zstd,noatime /dev/mapper/cryptoroot /mnt/home
mkdir /mnt/nix && mount -o subvol=/nix,compress=zstd,noatime /dev/mapper/cryptoroot /mnt/nix
mkdir /mnt/boot && mount nvme0n1p1 /mnt/boot
nixos-generate-config
does not generateboot.initrd.luks.devices."cryptoroot".device = ...
.Expected behavior
nixos-generate-config
should generate an entry forboot.initrd.luks.devices."cryptoroot".device = ...
.Additional context
My system does not contain
/sys/class/block/lvm-btrfs--root/
as shown below, which confuses LUKS detection.Rationale
I chose this setup for the following reason:
Basically, I followed this article and this comment without adopting the "Erase your darlings" part.
Notify maintainers
Metadata
This is the metadata for the bootable system.
Maintainer information: