1

I created a backup of my LUKS-encrypted Ubuntu installation's entire boot drive as a squashfs file.

The backup was performed by using Streaming Compression into a pseudo file, resulting in a compressed file that contains an image of the entire drive.

mksquashfs empty-dir nvme_backup.img.squashfs -p 'nvme.img f 444 root root dd if=/dev/nvme0n1 bs=4M'

lsblk

NAME                          MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sdj                             8:144  0 119.2G  0 disk
+-sdj1                          8:145  0 119.2G  0 part
nvme0n1                       259:0    0 223.6G  0 disk
+-nvme0n1p1                   259:1    0   487M  0 part  /boot
+-nvme0n1p2                   259:2    0     1K  0 part
+-nvme0n1p5                   259:3    0 118.8G  0 part
  +-sdb5_crypt                253:0    0 118.8G  0 crypt
    +-ubuntu--nvme--vg-root   253:1    0 110.8G  0 lvm   /
    +-ubuntu--nvme--vg-swap_1 253:2    0     8G  0 lvm
      +-cryptswap1            253:3    0     8G  0 crypt [SWAP]
sudo mount /dev/sdj1 /media/backup
sudo mount nvme_backup.img.squashfs /media/backup/mountpoint/ # mount the squashfs
cd mountpoint
sudo kpartx -va nvme.img # find the partitions and loop-mount them
add map loop1p1 (253:10): 0 997376 linear 7:1 2048
add map loop1p2 (253:11): 0 2 linear 7:1 1001470
add map loop1p5 (253:12): 0 249067520 linear 7:1 1001472

lsblk

NAME                          MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
loop0                           7:0    0 111.4G  0 loop  /media/backup/mountpoint
loop1                           7:1    0 119.2G  1 loop
+-loop1p1                     253:10   0   487M  1 part
+-loop1p2                     253:11   0     1K  1 part
+-loop1p5                     253:12   0 118.8G  1 part
sdj                             8:144  0 119.2G  0 disk
+-sdj1                          8:145  0 119.2G  0 part  /media/backup
nvme0n1                       259:0    0 223.6G  0 disk
+-nvme0n1p1                   259:1    0   487M  0 part  /boot
+-nvme0n1p2                   259:2    0     1K  0 part
+-nvme0n1p5                   259:3    0 118.8G  0 part
  +-sdb5_crypt                253:0    0 118.8G  0 crypt
    +-ubuntu--nvme--vg-root   253:1    0 110.8G  0 lvm   /
    +-ubuntu--nvme--vg-swap_1 253:2    0     8G  0 lvm
      +-cryptswap1            253:3    0     8G  0 crypt [SWAP]
sudo cryptsetup luksOpen /dev/mapper/loop1p5 root
Enter passphrase for /dev/mapper/loop1p5:

sudo lvscan

  WARNING: Not using device /dev/gpt-auto-root for PV xCIFJX-luFH-kOpr-9HvF-fz5E-PeTf-c8YZyo.
  WARNING: PV xCIFJX-luFH-kOpr-9HvF-fz5E-PeTf-c8YZyo prefers device /dev/mapper/sdb5_crypt because device is used by LV.
  ACTIVE            '/dev/ubuntu-nvme-vg/root' [110.75 GiB] inherit
  ACTIVE            '/dev/ubuntu-nvme-vg/swap_1' [<7.99 GiB] inherit

lsblk -o name,mountpoint,size,type,ro,label,uuid | grep CIF

  +-root                                               118.8G crypt  1             xCIFJX-luFH-kOpr-9HvF-fz5E-PeTf-c8YZyo
  +-sdb5_crypt                                         118.8G crypt  0             xCIFJX-luFH-kOpr-9HvF-fz5E-PeTf-c8YZyo

So I can't mount the LVM because the UUID of the /dev/mapper/sdb5_crypt and /dev/mapper/root PVs are the same, which makes sense because it is a clone.

How can I mount the LVM to get files out of it, keeping in mind that it's all on a read-only loop mounted squashfs, so I can't just change the UUID or name?

Z0OM
  • 3,149
localhost
  • 243

1 Answers1

1

I see three options for handling this problem (unless btrfs is involved; that would cause additional problems with UUID conflicts):

(Docker) container

Create only /dev/mapper/loop1p5 in the container so that the LVM stuff does not see the other devices.

mknod /dev/mapper/loop1p5 b 253 12 # major and minor ID  of the host device

dmsetup (ignore LVM)

Do not use the LVM tools; create the device mapper device manually. Adjust the output (i.e. the base device must be changed from sdb5_crypt (253:0) to root (253:?)) of

dmsetup table ubuntu--nvme--vg-root

and use it as input for dmsetup create with a new device name.

create a snapshot and change the UUIDs and VG name (dmsetup)

This probably looks ugly and would make most people faint... I will not provide all the steps here because I would have to look up a lot and it's probably not going to be used anyway. I will just describe what to do:

  • Create a small (few MiB) block device.

  • Create a "copy device" for /dev/mapper/root, something like

    dmsetup table root | dmsetup create root_copy
    
  • load (dmsetup load) a snapshot configuration into root. This contains references to the "copy device" and the CoW (copy-on-write) device.

  • activate the new configuration

    dmsetup suspend root ; dmsetup resume root
    

Now you can make small changes to the "read-only" data. The changes will be written to the CoW device only.

Hauke Laging
  • 90,279