The setup is an encrypted LVM container/PV that holds a few ext4 partitions. I am moving these to a new machine, but there is more room on the disk. So, I have created a bigger encrypted LVM container/PV. I have a dd dump of the old container (whole GPT partition holding the LVM PV, still encrypted), but the actual disk is gone.

How can I best restore the data, and be able to resize (enlarge) partitions while I do it - or at least create new ones inside the larger PV?

There should still be only one PV on the new disk because of the number of encryption passwords to be entered during boot. I have searched a bit but did not find this situation answered.

  • You have an LVM physical volume inside a dmcrypt container, right? – Gilles 'SO- stop being evil' May 17 '15 at 21:23
  • Thanks, yes, I do. Current status is that I have created a new container with a new PV and VG, new Volumes inside, then rsynced the data onto it. To do that, I dded und gunziped the gzipped backup into a single file on a removable hard disk. On the new computer, I cryptsetup luksOpened the file, renamed the VG in it (using UUIDs because the backup's VG name was the same as in the new disk), then (afterwards!) lvscan and lvchange -a yed the new volumes, mounted them individually (with -o ro option for speed && safety), then rsync -auved the contents onto the new disks, done. – Ned64 May 19 '15 at 9:05
  • 1
    Another way would probably have been to dd the whole dmcrypt container onto the new, larger partition, then resize the dmcrypt container, resize the LVM PV&VG in it, then resize the Volumes inside the VG, then resize the ext4/brtfs partitions inside the Volumes. I felt it may be easier to re-create the setup and rsync the data. That way it was easier to spread the size increase to the ext4/btrfs partitions. – Ned64 May 19 '15 at 9:25

The luks encryption header does not depend on or record the size of the underlying device. If you simply dd an encrypted partition into a larger encrypted partition, then when you open the new larger partition with cryptsetup luksOpen, its underlying size will be larger, too.

If you are using that to store an LVM physical volume, then just run pvresize /dev/mapper/plaintext (or whatever the decrypted PV partition is). If you don't specify a size, pvresize just takes up the whole physical partition.

That said, perhaps a nicer way to do what you want to do is to set up the new larger encrypted partition as a new partition, then pvcreate it, then add it to your volume group. At that point you can start to get rid of the old partition with pvmove /dev/mapper/oldplaintext followed by pvremove /dev/mapper/oldplaintext. The advantage of this approach is that you can still use your file system while the data is being copied over.

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.