You are not logged in.

#1 2019-11-18 21:08:20

mousy
Member
Registered: 2019-10-07
Posts: 10

Repair corrupted files

Hello everyone.

I copied some text files on encrypted usb drive as backup. Now that I need backup, I realized that most of files are size of 0kb and when I open them, they are empty. So, I did some research and tried to run fsck. When I run it, I get back error:
/dev/sda is in use.
e2fsck: Cannot continue, aborting.

I tried umonunt /dev/sda, but no luck with that.

Do you guys have any suggestions? Please help!

Offline

#2 2019-11-18 21:21:02

seth
Member
Registered: 2012-09-03
Posts: 50,003

Re: Repair corrupted files

/dev/sda is no partition but a disk and typically not hold a filesystem. Also it's usually the drive that has your root filesystem, not some usb key.

=> Output of "lsblk"?

Also brace yourself, the data is most likely gone. Anyway, please elaborate on "encrypted usb drive". What kind of device/encryption is that actually?

Online

#3 2019-11-18 21:28:38

mousy
Member
Registered: 2019-10-07
Posts: 10

Re: Repair corrupted files

Output of lsblk is:

NAME                             MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda                                8:0    1   7.5G  0 disk 
└─sda1                             8:1    1   7.5G  0 part 
  └─luks-7892d13e-2c5a-4812-8ff6-cd209f33e213
                                 254:4    0   7.4G  0 crypt /run/media/user/Usb


Device is usb pen, encryption is luks, as you can see above.

Last edited by mousy (2019-11-18 21:30:21)

Offline

#4 2019-11-18 21:35:47

seth
Member
Registered: 2012-09-03
Posts: 50,003

Re: Repair corrupted files

Ok, you'll have to luksopen the partition (sda1), see https://serverfault.com/questions/37509 … ypted-disk

nb. that fsck will rather not recover anything, but you could try your luck w/ https://wiki.archlinux.org/index.php/Fi … d_PhotoRec as well.
I'm however afraid that the data had never been written itfp. :-(

Online

#5 2019-11-18 21:57:49

mousy
Member
Registered: 2019-10-07
Posts: 10

Re: Repair corrupted files

Thank you for your help smile
Will try my luck with testdisk.

Offline

#6 2019-12-09 16:09:06

mousy
Member
Registered: 2019-10-07
Posts: 10

Re: Repair corrupted files

Here I would like to continue discussion about how it happened this to me.

Recently I used same USB key for file transfer from one computer to another. When I copy text files on usb (no sub-folder location) I can verify transferred files with opening them and reading data. When I eject usb key, re-insert it and open it, I find all transferred files are 0kb in size and empty. I tried this several times and every single time I get same result.
When I transfer files to sub-folders on usb, files remain un-corrupted and functional as they should.

My question is: could this be USB flaw, or is this because I use dm-crypt with usb?

Offline

#7 2019-12-09 16:28:17

Zod
Member
From: Hoosiertucky
Registered: 2019-03-10
Posts: 629

Re: Repair corrupted files

Offline

#8 2019-12-09 18:57:54

mousy
Member
Registered: 2019-10-07
Posts: 10

Re: Repair corrupted files

Yes, this could cause the issue. How can I disable this?

What I found interesting was if I saved files in sub-folder it worked fine, and if files were placed on .../usb/ they did not write properly.

Offline

#9 2019-12-09 20:38:22

seth
Member
Registered: 2012-09-03
Posts: 50,003

Re: Repair corrupted files

If you properly unmount the device, it's synced before the unmount completes (which is why this can take some time if there's a lot of data to flush)

The subfolder thing is weird.
What if you copy a file into a subfolder and then move it from there to the root path of the device (ie. /run/media/USBKEY/)?

Online

#10 2019-12-12 17:59:46

mousy
Member
Registered: 2019-10-07
Posts: 10

Re: Repair corrupted files

From now on I will properly unmount device! It was costly lesson for me sad
Is there any other setting that can be changed, so system by default acts same way as windows do (disable ‘Write Caching’)?

Yes, this subfolder thing its also very weird to me big_smile Tried to copy files with terminal and it worked fine. But it would be nice if there is way to disable write caching.

Offline

#11 2019-12-12 21:05:13

seth
Member
Registered: 2012-09-03
Posts: 50,003

Re: Repair corrupted files

You can either mount (many filesystems) "sync" (check the manpages, there's no way to globally control that for udisks, so forget about your filemanager doing this w/o an fstab entry for the device) or lower/disable the write cache.
https://lonesysadmin.net/2013/12/22/bet … rty_ratio/

Neither is advisable reg. performance and with NAND memory, this will actually lower the drives live expectance.
Also several filesystems (incl. fat & ntfs) will set "dirty" bits and recognize that they were not properly unmounted and might act up on that.

tl;dr - forget about this, always unmount drives.
Windows has the same feature, called "savely remove drive" or so and it's meant to be used there as here (actually FAT are the only "filesystems" where you could get away w/ a sync mount and cold ejects, but they'll set a dirty bit just the same)

Online

#12 2019-12-14 16:10:41

mousy
Member
Registered: 2019-10-07
Posts: 10

Re: Repair corrupted files

Got it. Thank you for explaining this stuff.

Offline

Board footer

Powered by FluxBB