1

I made a bootable backup of my encrypted drive using dd:

> sudo dd if=/dev/sda of=/dev/sdc bs=64k status=progress

After checking that I can boot from the clone, I booted back into the original drive and tried to mount the clone using vgimportclone:

> sudo cryptsetup open /dev/sdc5 sdc5_crypt
> sudo lvm
lvm> vgimportclone /dev/mapper/sdc5_crypt
lvm> pvscan --cache
lvm> vgchange -a y
lvm> quit
> mount /dev/mapper/ubuntu--vg11-root /mnt

The VG names and VG & PV UUIDs on the clone are now different from those on the original drive, but the LV UUIDs are the same. The VG name for the original drive is ubuntu-vg and for the new drive it's ubuntu-vg11. I altered /boot/grub.cfg on the unencrypted partition of the cloned disk to reflect these changes and ensure it is still bootable. After checking that the clone is still bootable (it is), I booted back into the original drive, and tried mounting the clone:

> sudo cryptsetup open /dev/sdc5 sdc5_crypt
> mount /dev/mapper/ubuntu--vg11-root /mnt

At first it appeared to work, but on closer inspection of the contents of /mnt I realized that it had actually mounted the original LV there (which is already mounted on /, and had some new files added to it since first creating the clone). So the next thing I tried was changing the filesystem UUID of the clone using tune2fs:

umount /mnt
tune2fs -U random /dev/mapper/ubuntu--vg11-root

I checked that the filesystem UUID on the clone (/dev/mapper/ubuntu--vg11-root) differs from that of the original (/dev/mapper/ubuntu--vg-root) However the problem persists, so I assume it must be due to the identical LV UUIDs. Everything I've read online suggests it's not possible to change LV UUIDs, so I wonder is there any other way around this problem? How can I mount my cloned drive at the same time as the original?

1 Answer 1

1

I managed to change the UUID of the LVs on the clone, and get it to mount at the same time as the original without conflict. Here's how I did it:

  1. I attached a different drive with a copy of Ubuntu installed and booted into it.
  2. I attached the cloned drive, and opened the encrypted partition: sudo cryptsetup open /dev/sd5 sdc5_crypt
  3. This automatically created links for the LVs: /dev/mapper/ubuntu--vg11-root & /dev/mapper/ubuntu--vg11-swap
  4. I then removed the LVs on the clone: sudo lvremove ubuntu-vg11
  5. Then I checked the lvm archive, which keeps a record of all changes: sudo ls -l /etc/lvm/archive
  6. I made a note of the most recent archive file for the ubuntu-vg11 group, and edited it, altering the UUIDs of the LVs listed in the file.
  7. Then I restored the LVs from that archive file: sudo vgcfgrestore ubuntu-vg11 -f /etc/lvm/archive/ubuntu-vg11_00001-123456789.vg
  8. Check the UUIDs of the LVs: sudo lvscan && sudo lvdisplay (the newly altered LVs were not listed by lvs for some reason, but I was still able to mount them without problems).
  9. Check that they can be mounted OK: sudo mount /dev/mapper/ubuntu--vg11-root /media/sdc5
  10. Unmount and reboot: sudo umount /media/sdc5

It now seems to work fine, and I can mount both the clone and the original at the same time with no problems.

You must log in to answer this question.

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