I am trying to set up LVM on LUKS. Here is what I did:

head -c 100M /dev/zero > test-file
losetup /dev/loop0 test-file
cryptsetup luksFormat /dev/loop0
cryptsetup open /dev/loop0 cryptlvm
gdisk /dev/mapper/cryptlvm

Then I put a GPT and a single partition 8e00 LVM on there.

fdisk -l /dev/mapper/cryptlvm
# => /dev/mapper/cryptlvm-part1  2048 200670  198623  97M Linux LVM


pvcreate /dev/mapper/cryptlvm-part1
# => Device /dev/mapper/cryptlvm-part1 not found.

The partition doesn't show up in lsblk either. Folks seem to generally advocate usage of a partition table underneath LVM to make sure partitioning programs see something is there, so I wanted to adhere to that. Putting LVM on a partition on top of a GPT worked without problems when I skipped the LUKS container.

When I try to set up a LUKS container on the partition only this works fine too, i.e. gdisk and then cryptsetup onto the LVM partition.

I expected that it should be possible to put a partitioning scheme inside a LUKS container and then use LVM on a single partition in there. I'd appreciate any hints or explanation as to why this (seemingly) is not possible.

  • 1
    There seems to be a misunderstanding of some kind. The partition table should be on the drive itself. It's unusual to put one between LUKS and LVM. Jun 20, 2020 at 13:06
  • So I either leave partitioning out or I'll have to leave the GPT unencrypted?
    – MrMeeSeeks
    Jun 20, 2020 at 13:10

1 Answer 1


Linux kernel, afaik the only part handling partitions, won't try to discover a partition within a partition, so the attempt stops here.

Just create the PV directly on the cryptlvm mapping. The device mapping plays the role of a container instead of the partition.

# cryptsetup open /dev/loop0 cryptlvm
# pvcreate /dev/mapper/cryptlvm
  Physical volume "/dev/mapper/cryptlvm" successfully created.
# pvs /dev/mapper/cryptlvm
  PV                   VG Fmt  Attr PSize  PFree 
  /dev/mapper/cryptlvm    lvm2 ---  98.00m 98.00m

You can then proceed with vgcreate:

# vgcreate testvg /dev/mapper/cryptlvm 
  Volume group "testvg" successfully created
# vgs testvg
  VG     #PV #LV #SN Attr   VSize  VFree 
  testvg   1   0   0 wz--n- 96.00m 96.00m

Normally the system (here probably a mix of kernel, events, and userspace) should detect and activate the VG automatically. If you transfer the result on an other system, you might possibly also have to fiddle then with pvscan, vgscan or vgchange -ay ... after opening the LUKS volume, I didn't test it further.

Should you really want to continue with your initial attempt for obscure reasons, you can use kpartx to detect partitions within anything. It will create a new device mapping, at which point, you'll use pvcreate on the device mapping (rather than a "simple" partition) anyway. No common Linux distribution will ever do this, so this would have to be all "detected" and handled manually.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .