Tag Archives: English

How to repair a LUKS encrypted partition

Today I’ve found a problem with an Ubuntu VM that refused to run. The disk was encripted with LUKS, the swap and the system partitions.

The problem was that the System’s partition was corrupted and the bootloader (grub) couldn’t find the partition for booting resulting in initramfs prompt:

initramfs error

The first step for repairing these partitions is to grab an Ubuntu Live CD and boot from it.

Once you’ve booted first you need to install the required tools:

1. Install the tools needed to deal with encrypted partitions
2. Insert the module

Then find the encrypted partion and open it.

1. Identify the encrypted disk and partition:

In my case it is sda5. Next:

1. Open the Encrypted partition and give it a name, in this case my_named_partition (you’ll have to type the passphrase).

Now we’ve unlocked that encrypted partition, so it’s a matter of dealing with the LVM

1. Install the tools we need.
2. Enable the module.

At this point we can use several tools:

1. Scans for all volume groups
2. Makes the VG Ubuntu active (if you don’t give it a volume group as an argument, It’ll make them all active)
3. Lists the logical volumes and their /dev path

We’ll try to repair that partition with fsck

1. Scan and Fix

Depending on the errors and the quantity of them will take more or less time.

Finally if you want to grab some files you’ll need to mount the partition. You can do it with:

1. Create a directory to mount the partition.
2. Mount the partition.

Finally to reverse the process:

1. Unmount the partition
2. Remove the directory created.
3. (Only if you want to reverse the active state of that partition)
4. Close the encrypted partition