Cannot remove file: “Structure needs cleaning”

I have an external hard drive which is encrypted via LUKS. It contains an ext4 fs.

I just got an error from rsync for a file which is located on this drive:

rsync: readlink_stat("/home/some/dir/items.json") failed: Structure needs cleaning (117)

If I try to delete the file I get the same error:

rm /home/some/dir/items.json
rm: cannot remove ‘//home/some/dir/items.json’: Structure needs cleaning

Does anyone know what I can do to remove the file and fix related issues with the drive/fs (if there are any)?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

That is strongly indicative of file-system corruption. You should unmount, make a sector-level backup of your disk, and then run e2fsck to see what is up. If there is major corruption, you may later be happy that you did a sector-level backup before letting e2fsck tamper with the data.

Method 2

If it helps anyone, I had a similar issue (rsync/rsnapshot backups, on an affected file). I posted my problem/solution, here:

https://ubuntuforums.org/showthread.php?t=2348768&p=13627299#post13627299

SUMMARY:

rsnapshot (rsync) backup error on arch linux x86_64 system; a corrupted, deeply-nested file was throwing that error, also shown when I tried to delete that file:

sudo rm -fR hourly.5/

rm: cannot remove 'hourly.5/snapshot_root/mnt/Vancouver/temp/temp - old/temp - 09 (Dec 07, 2014 - Sep 02, 2015)/a_OLD-gmail/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1b6d72786f7469727a357a35686f6e7a696f5b7c767a727735787476">[email protected]</a>/[Gmail]/LINUX/rsync, rsnapshot; Other backups/19.bak': Structure needs cleaning

Here is the problem:

cd mnt/Vancouver/temp/temp - old/temp - 09 (Dec 07, 2014 - Sep 02, 2015)/a_OLD-gmail/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3a5bab0a7bca1bab2fdb2fda0a7a6b2a1a793b4beb2babffdb0bcbe">[email protected]</a>/[Gmail]/LINUX/rsync, rsnapshot; Other backups/

ls -l

ls: cannot access '19.bak': Structure needs cleaning
total 0
-????????? ? ? ? ?  ? 19.bak        ## << THAT IS THE PROBLEM!!

[ See also: https://www.reddit.com/r/linuxquestions/comments/4b47r2/has_anyone_ever_gotten_structure_needs_cleaning/ ]
My backup drive is /dev/sda1.

sudo umount /dev/sda1

sudo fsck.ext4 /dev/sda1  ## << accepted suggested fixes

Rebooted: all seems fine. Went into backups drive, deleted that problematic file:

/mnt/Backups/rsnapshot_backups/hourly.5/snapshot_root/mnt/Vancouver/temp/temp - old/temp - 09 (Dec 07, 2014 - Sep 02, 2015)/a_OLD-gmail/<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f5839c96819a879c94db94db868180948781b59298949c99db969a98">[email protected]</a>/[Gmail]/LINUX/rsync, rsnapshot; Other backups/19.bak

Q.E.D.?!
[Update: yes; that worked: my backups are running normally, again! 🙂 ]

Method 3

File systems sometimes are not in order and need cleaning. This can be done by fsck command. But remember, you must run fsck only to unmounted partitions to avoid risk of file corruption.

If your file system is ext4, try running this command :

fsck -AR -t ext4 -y

Method 4

I fixed this problem with this command in my proxmox shell:

  • stop the container
    pct stop 100
  • fsck container, this repair the problem, on some issues files that are corrupt on container system
    pct fsck 100
  • start the container
    pct start 100

Now backup and all is good!

Method 5

I got the same error message from rsync and same error message from rm when I tried to delete the file. Because the filesystem was the root filesystem there was no way to use fsck. But when I just rebooted the system the file was gone and the backup succeeded. I have no clue why this worked but at least that’s an easy fix and it’s worth to try a reboot first.

Method 6

Just recently had this problem myself, so I’ll add what I did here.

Ubuntu 20.04
3 disks (4tb each) – (sdd,sde and sdf) formatted with raid5 as md0.
MD0/raid was formatted with LUKS.
Luks contained LVM with 1 partition of ext4 mounted as /home.

looked like this:

sdd                     8:48   0   3.7T  0 disk  
└─md0                   9:0    0   7.3T  0 raid5 
  └─vgraid-lvraid     253:0    0   7.3T  0 lvm   
    └─luks-raid       253:4    0   7.3T  0 crypt /home
sde                     8:64   0   3.7T  0 disk  
└─md0                   9:0    0   7.3T  0 raid5 
  └─vgraid-lvraid     253:0    0   7.3T  0 lvm   
    └─luks-raid       253:4    0   7.3T  0 crypt /home
sdf                     8:80   0   3.7T  0 disk  
└─md0                   9:0    0   7.3T  0 raid5 
  └─vgraid-lvraid     253:0    0   7.3T  0 lvm   
    └─luks-raid       253:4    0   7.3T  0 crypt /home

No matter what I tried, couldn’t un-mount /home.

I ended up rebooting into a Live CD (Ubuntu 20.04), and used the ‘Try before installing’ option.

Mounted/activated md0 raid using

$ sudo mdadm --assemble --scan

Then started up gnome-disks

$ sudo gnome-disks

Using Disks, I mounted the LUKS volume, and this gave access to the EXT4 partition where I used gnome-disks to perform filesystem check and repair on the unmounted ext4 partition.

Rebooted back to normal, and all was fixed.

Method 7

It’s usual error when try remove .Trash-0 if you try remove windows in encoding CP1251 file system on Linux system. So fs is corrupt but this dosn’t metter. Fs of Windows always corrupt as see from Linux. But is not so. You may try open this file from windows os All will be well. And then remove it in windows. And only after that clean trash.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x