Cannot mount LVM volumes after manually decrypting LUKS partition
I’ve got a full drive image 2022-06-11_fedora.iso
that I’m trying to manipulate its partitions on another computer. (e.g. resize LVM logical volumes, move ESP, and expand /boot
partition).
I cannot seem to mount the LVM volumes after decrypting the LUKS partition.
How can I mount the LVM volumes after decrypting the LUKS partition that they sit on in order to manipulate the volumes with the LVM command suite?
fdisk of image contents
3 partitions:
2022-06-11_fedora.iso1
is/boot
2022-06-11_fedora.iso2
is ESP2022-06-11_fedora.iso3
is LVM on LUKS
$ fdisk -l 2022-06-11_fedora.iso
Disk 2022-06-11_fedora.iso: 238.47 GiB, 256060514304 bytes, 500118192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier:
Device Start End Sectors Size Type
2022-06-11_fedora.iso1 2048 514047 512000 250M Linux filesystem
2022-06-11_fedora.iso2 514048 808959 294912 144M EFI System
2022-06-11_fedora.iso3 808960 500117503 499308544 238.1G Linux filesystem
Decrypting third partition
$ sudo cryptsetup plainOpen --offset=808960 2022-06-11_fedora.iso cryptdisk
Enter passphrase for 2022-06-11_fedora.iso:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 238.5G 0 loop
└─cryptdisk 253:2 0 238.1G 0 crypt
sda 8:0 0 1.8T 0 disk
└─sda1 8:1 0 1.8T 0 part
nvme0n1 259:0 0 1.8T 0 disk
├─nvme0n1p1 259:1 0 487M 0 part /boot/efi
├─nvme0n1p2 259:2 0 3.8G 0 part /recovery
└─nvme0n1p3 259:3 0 1.8T 0 part
└─cryptdata 253:0 0 1.8T 0 crypt
└─data-root 253:1 0 1.8T 0 lvm /
$ sudo fdisk -l /dev/mapper/cryptdisk
Disk /dev/mapper/cryptdisk: 238.09 GiB, 255646326784 bytes, 499309232 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Trying to mount /dev/mapper/cryptdisk
$ sudo mount /dev/mapper/cryptdisk /mnt/crypt
mount: /mnt/crypt: wrong fs type, bad option, bad superblock on /dev/mapper/cryptdisk, missing codepage or helper program, or other error.
How can I mount the LVM volumes after decrypting the LUKS partition?
First of all, this
sudo cryptsetup plainOpen --offset=808960 2022-06-11_fedora.iso cryptdisk
is wrong. If the third partition is really a LUKS partition you didn’t open it correctly, the plain mode in cryptsetup uses hash of the provided passphrase to decrypt the data which won’t work for LUKS.
Second: The /dev/mapper/cryptdisk
device is the LVM physical volume (or it would be if it was decrypted correctly) it is not mountable. You need to mount the logical volume(s) on it.
To do this correctly:
- Use
losetup
to create the loop device:sudo losetup -f 2022-06-11_fedora.iso --partscan
- You should now see all three partitions in the
lsblk
output. - Open the third partition with
sudo cryptsetup luksOpen /dev/loop0p3 cryptdisk
. - If you don’t see the logical volumes in the
lsblk
output, they were not automatically activated, usevgscan
to scan for the volume group and then usesudo vgchange -ay <vg name>
to activate it. - Mount the logical volume(s) in the VG. The path will be
/dev/mapper/<vgname>-<lvname>
(same as for your systemdata-root
LV).
Note: VG name is a unique identifier in LVM so if the VG on the image is also called data
, you won’t be able to activate it and you need to rename it first by identifying the correct VG by its UUID using vgrename <uuid> <new name>
. (You will notice this, LVM will complain about having two VGs in the system with the same name.)