On my previous computer, I had my / /home and swap inside an encrypted lvm, and outside the lvm I had the /boot and /boot/efi. I then created an image. I think I did like this: dd if=/dev/sda of=lvm.img bs=4M but I don't remember. I could check it in .bash_history, if I just could decrypt the image first...

I have been trying to follow this guide: https://gist.github.com/talaj/721d50791e95ea585316ea0571822fa7

First I examined the file:

# file lvm.img 
lvm.img: DOS/MBR boot sector; partition 1 : ID=0xee, start-CHS (0x0,0,2), end-CHS 

(0x3ff,254,63), startsector 1, 250069679 sectors, extended partition table (last)

# fdisk -lu lvm.img
Disk lvm.img: 119.2 GiB, 128035676160 bytes, 250069680 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: 9FEF2EAF-1AE7-47B1-A446-7B3EBCB24A54

Device       Start       End   Sectors   Size Type
lvm.img1      2048   3907583   3905536   1.9G EFI System
lvm.img2   3907584   7813119   3905536   1.9G Linux filesystem
lvm.img3   7813120 250068991 242255872 115.5G Linux LVM

So it certainly looks like it contains what it should. How should I do to view the partitions inside lvm.img3 and mount them?

I started with this:

# kpartx -av lvm.img 
add map loop0p1 (253:3): 0 3905536 linear 7:0 2048
add map loop0p2 (253:4): 0 3905536 linear 7:0 3907584
add map loop0p3 (253:5): 0 242255872 linear 7:0 7813120

Continued with this:

# cryptsetup luksOpen /dev/mapper/loop0p3 mylvm

Hmmmm? I did not need to enter passphrase? Whatever. Contiuning the guide.

# vgscan
  Reading volume groups from cache.
  Found volume group "fedora" using metadata type lvm2
  Found volume group "fedora_desktop-ld77fgg" using metadata type lvm2

# vgchange -a y fedora_desktop--ld77fgg
  Volume group "fedora_desktop--ld77fgg" not found
  Cannot process volume group fedora_desktop--ld77fgg

And now I'm stuck...

I'm using Fedora, but if it matters I could switch to another distribution.


As telcoM pointed out in an answer I had made a very silly mistake, and I don't understand how. Nevertheless I still have problems. I corrected my last command by changing the double dash to a single dash:

# vgchange -a y fedora_desktop-ld77fgg
  4 logical volume(s) in volume group "fedora_desktop-ld77fgg" now active

And then

# mount /dev/fedora_desktop-ld77fgg/03 /tmp/hej
mount: /tmp/hej: unknown filesystem type 'crypto_LUKS'.
  Found volume group "fedora_desktop-ld77fgg" using metadata type lvm2

# vgchange -a y fedora_desktop--ld77fgg

When the vgscan command tells you the name of the VG, you can use it as is with the vgchange command - you don't have to double the dashes.

A mini-summary of Logical Volume Manager (LVM):

  • In order to use LVM, you can initialize partitions or entire disks as LVM Physical Volumes (PVs)...
  • ... and you use one or more PVs to create a Volume Group (VG), which is basically treated as an uniform pile of raw storage space, which you can then freely slice into...
  • ..one or more LVM Logical Volumes (LVs). A single LV can span more than one PV: even if it's made out of many disjoint pieces, a filesystem placed on it will see it as a single logically continuous unit of storage. And a LV can be migrated from one place to another within the VG, while the LV is mounted and in use.

You'll need to do that only with pathnames: since the format is /dev/mapper/<VG name>-<LV name>, any unmodified single dashes in the pathname would make it ambiguous: any program processing the name would not know which dash is part of the name and which one separates the <VG name> and the <LV name> parts from each other.

It looks like you thought the order of containers was:

disk -> partition -> LUKS wrapper -> PV -> LV -> filesystem

but the lack of need to specify the passphrase when trying to run cryptsetup luksOpen and the error message when trying to mount /dev/fedora_desktop-ld77fgg/03 suggest that the actual order of things is:

disk -> partition -> PV -> LV -> LUKS wrapper -> filesystem

To confirm this, see if your cryptsetup luksOpen /dev/mapper/loop0p3 mylvm actually created a /dev/mapper/mylvm device or not. I suspect it might have not done anything at all.

Instead, you should now do:

# cryptsetup luksOpen /dev/fedora_desktop-ld77fgg/03 myfs
<answer the passphrase prompt>
# mount /dev/mapper/myfs /tmp/hej
  • Thank you, but that did not solve the problem. See my updated question. – klutt Apr 25 '19 at 14:03
  • Please see my updated answer. – telcoM Apr 25 '19 at 14:21
  • Thank you very much. It worked perfectly. – klutt Apr 25 '19 at 14:33
  • For future readers, I think it would be good if you explained the acronyms VG, LV and PV. – klutt Apr 25 '19 at 14:40
  • Done. How's that? – telcoM Apr 25 '19 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.