16

I have a LUKS/LVM volume that was unfortunately removed without being correctly unmounted.

I made a dd backup of my entire encrypted Ubuntu 16.04 installation. Then fresh installation of different Ubuntu version with a live USB inside the LUKS volume on the computer, booted into it, and plugged in the drive with the dd backup to copy data over manually.

It couldn't unlock another drive with the same UUID and encryption key (being a dd backup) and spat the dummy. The drive neither unlocked nor ejected. The drive was then mistakenly cold-yanked while I was trying to find out how to safely remove it.

Now whenever I mount this drive on a different computer, I can unlock without any problem, but when I try to mount the partition inside it says

Error mounting /dev/dm-4 at /media/user/57960113-31ce-4ced-8654-1fadf6012947:
Command-line 'mount -t "ext4" -o "uhelper=udisks2,nodev,nosuid" "/dev/dm-4" "/media/user/57960113-31ce-4ced-8654-1fadf6012947" ' exited with non-zero exit status 32:
mount: mount /dev/mapper/ubuntu1604-ubuntu1604root on /media/user/57960113-31ce-4ced-8654-1fadf6012947 failed:
Structure needs cleaning

This backup is now the only copy of my data. I have dd'd it to another drive so I can experiment without making things worse.

How do I fix this?

0
18

Your file system is broken. You need to fix it so that your OS can properly read/write it.

Therefore, we need to utilise a tool named fsck.

As per it's man page:

Name

fsck - check and repair a Linux file system

Synopsis

fsck [-sAVRTMNP] [-C [fd]] [-t fstype] [filesys...] [--] [fs-specific-options]

Description

fsck is used to check and optionally repair one or more Linux file systems. filesys can be a device name (e.g. /dev/hdc1, /dev/sdb2), a mount point (e.g. /, /usr, /home), or an ext2 label or UUID specifier (e.g. UUID=8868abf6-88c5-4a83-98b8-bfc24057f7bd or LABEL=root). Normally, the fsck program will try to handle filesystems on different physical disk drives in parallel to reduce the total amount of time needed to check all of the filesystems.

A basic usage of the command would be:

sudo fsck.ext4 /dev/sda[NUMBER]

However, do note that this process can be a lengthy one.

4
  • 3
    Thank you for your contribution. Please add some words explaining why you did that and what does the command, to gather knowldge. – Marc Vanhoomissen May 1 '17 at 16:07
  • 3
    sudo fsck.ext4 -y /dev/sdaX – blueray Mar 14 '19 at 1:35
  • The -y otherwise it will ask you to confirm repairing every single inode :-) – SeanFromIT Sep 23 '19 at 0:50
  • well I started getting this problem AFTER running fsck (and repairing thousands of errors). Before that it was mounting fine. – Sridhar Sarnobat Sep 2 '20 at 2:56
7

Just as written, you can clean the partition (after a backup, as you already did), by typing

sudo e2fsck /dev/dm-4

e2fsck checks the file system's integrity.

Afterwards, you should be able to mount it again.

2
  • 2
    Be prepared to type 'y' a bunch of times with this command. Or include the -y switch to answer yes to all prompts. – RyanNerd Jun 28 '18 at 18:57
  • @RyanNerd: sure, but sometimes it helps to have a look at the messages – serv-inc Jun 29 '18 at 8:47
3

You can also run gparted. The Partition will be displayed with an exclamation mark.

  • Select in the upper right corner the correct hdd
  • right click on the partition marked with a exclamation mark
  • choose "check"
  • gparted will ask you if you're sure und try to run a repair on the file system. e2fsck. Be aware, that this operation could take some time and you should NOT interrupt it, once it has started.
1

If your file system type is XFS, then you need to execute the following command:

sudo xfs_repair /dev/to/disk

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.