"Structure needs cleaning" error - cannot mount partition

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?


Solution 1:

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.

Solution 2:

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.

Solution 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.

Solution 4:

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

sudo xfs_repair /dev/to/disk