1

I got myself a new hard drive and installed the most current version of Linux Mint. Now I wanted to transfer the files from the old disk (I had no recent backup) but there are several issues

  • the LVMs' names are conflicting (Linux Mint uses mint-vg for the name) from my new internal system and the external drive
  • the disk itself is encrypted
  • my /home is encrypted as well
  • the new drive is encrypted as well

How can I recover my data?

3

Mounting the drive

(I use a USB-casing for SATA drives, you might as well install the drive in your PC)

When encrypting the disk while installing Mint the drive will contain a partitioning scheme (using fdisk -l /dev/sdb) such as

/dev/sdb1 -> Bootable, about 500M in size, Id 83, Type "Linux" /dev/sdb2 -> Not-bootable, rest of your disk's capacity, Id 5, Type "Extended" /dev/sdb5 -> Not-bootable, rest of your disk's capacity, Id 83, Type "Extended"

After you found the partition try to mount it using

sudo cryptsetup luksOpen /dev/sdb5 exthdd

Where exthdd can actually be anything, but it must not exist under dev/mapper, so you might check this first.

You will be asked for your passphrase for the partition, so have it ready. If you lost this, there is no help for you...

Running lsblk again you should see something like mint--vg-root and mint--vg-swap_1 under exthdd.

Handling the conflicting LVM names

When the device is unlocked via cryptsetup luksOpen, run

sudo lvscan

which will show you something like

inactive '/dev/mint-vg/root' [UVW GiB] inherit inactive '/dev/mint-vg/swap_1' [XYZ GiB] inherit ACTIVE '/dev/mint-vg/root' [ABC GiB] inherit ACTIVE '/dev/mint-vg/swap_1' [DEF GiB] inherit

As you can see you have mint-vg twice under /dev directory, which leaves you to access only one of these (in my case it pointed to the external hard drive).

Fortunately the underlying volume groups are distinct by an ID (VG UUID). We can retrieve these IDs running

sudo vgdisplay

which will show you something like this (output abbreviated):

--- Volume group ---
 VG Name        mint-vg
 ...
 VG Size        UVW GiB
 ...
 VG UUID        UVW-ID

 --- Volume group ---
 VG Name        mint-vg
 ...
 VG Size        ABC GiB
 ...
 VG UUID        ABC-ID

In my case I was able to solve the difference by looking for the size of the hard drives, of course you can check the ID of your current VG before mounting the external drive.

Now that we have the ID (UVW-ID) we can rename the VG using

sudo vgrename UVW-ID newvgname

You should get a

Volume group "NAME-OF-UVW" successfully renamed to newvgname

Checking lsblk should reveal you with two entries under sdb5, newvgname-swap_1 and newvgname-root.

Decrypting and mounting your home directory

If you check /dev/mapper now, you will find two new nodes

/dev/mapper/newvgname-root /dev/mapper/newvgname-swap_1

Run

sudo mount /dev/mapper/newvgname-root /your/mount/point

and check the result

ls /your/mount/point - voilà, you should now have access to the device.

Now go to the /home diretory and look for the hidden directory .ecryptfs. Inside you should find a directory user - where user is the user name you are looking for.

Now run

sudo ecryptfs-recover-private /your/mount/point/home/.ecryptfs/user/.Private/

You will be prompted for the password for the account of user:

INFO: Found [/your/mount/point/.ecryptfs/user/.Private/].
Try to recover this directory? [Y/n]: Y
INFO: Found your wrapped-passphrase
Do you know your LOGIN passphrase? [Y/n] Y
INFO: Enter your LOGIN passphrase...
Passphrase: _
Inserted auth tok with sig [...] into the user session keyring
INFO: Success! Private data mounted at [/tmp/ecryptfs.ABCXYZ]

Yet, if you lost this password, there is little to no hope for you.

You can now go to /tmp/ecryptfs.ABCXYZ and see the contents of the home directory.

Unmounting

Unmount everything in the reverse order.

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.