77

Whenever I unmount a USB drive with Nautilus and plug it to a Windows machine, I receive a warning that the drive needs to be repaired.


(the same message like in this screenshot)

For 10+ years working with windows I never had a corrupted or damaged USB drive but during the last two years three of my USB drives became inoperative, so I cannot prove it, but it's obvious that this is related to Ubuntu's (un)mount behavior.

A friend told me I can prevent such damage using udisks and sync, but I hope this is not the way to do it, mounting drives with shell commands in 2016.

Braiam
  • 67,791
  • 32
  • 179
  • 269
  • 1
    I would try two tests to figure out the root-cause: 1) Can you prevent the error from appearing if you call sync in a shell before unmounting in Ubuntu? (unlikely) 2) Try writing only one file at a time, unmount, then check if this file can be read on windows and its contents are up-to-date, despite seeing this warning. 2) means the issue is most likely with Windows being fussy saying "we found errors" about some non real issue. – arielf Apr 01 '16 at 20:29
  • 3
    Don't believe people when they tell you Linux won't corrupt your drives. It can. On Ubuntu 15, mere file copy followed by reboot consistently gave me errors in chkdsk like this: Stage 2: Examining file name linkage ... Found corrupt basic file structure for "<0x32,0x1e63>" ... queued for offline repair. Found an unneeded link ($FILE_NAME: ???) in index "$I30" of directory "\ <0x5,0x5>" ... queued for offline repair. Found missing Index entry for file "<0x32,0x1e63>" from index "\??\D:\found.000" of directory "$I30" ... queued for offline repair. – user541686 Apr 02 '16 at 06:49
  • 1
    ^...not to mention, this wasn't even on a flash drive, it was on my main SSD. A brand-new SSD. And it happened every single time that I didn't add a ton of extra I/O after the file copy. In other words, Linux's implementation of NTFS is broken, as much as its fans will want to deny it and avoid believing. – user541686 Apr 02 '16 at 06:52
  • 12
    Is this a NTFS filesystem? FAT32? Can you reproduce it reliably? – Braiam Apr 03 '16 at 14:23
  • 2
    What's so bad with mounting drives with shell commands ? ¯\(o_o)/¯ – ulidtko Apr 04 '16 at 12:25
  • 1
    I have the same behavior the other way - I must 'repair' USBs under Linux, because Windows gets them broken. – MatthewRock Apr 04 '16 at 13:24
  • 1
    Are you unmounting the drive, or just pulling it out? If you're properly unmounting it, then all pending writes should be performed and the disk buffers flushed. If you're just pulling the drive out, then I'm not surprised you've got file system corruption. – TMN Apr 05 '16 at 12:58
  • I've noticed that if you wait a few (say, 15) seconds after you eject/unmount the USB & then remove it, you don't have this trouble. It seems that even though it shows immediately after unmount that it's "ejected", it actually is still busy? – Tracy LF Apr 04 '16 at 06:37
  • No no no ! this is a windows scam project started with windows 7 servicepack 2 put in production with windows 8: It works like this.. Anything accessing a forign ( not exclusively Windows Owned drive - may it be a USB or iscsi Drive (HD, stick memory card) that have been accessed by something not OWNED BY Microsoft Will trigger all KINDS of SCARY WARNINGS and ultimately tell you to format the drive ( before reading / Copying of course)!! Next time try it on a Unix, Machintosh or other Linux distro ( same result - No Complaints What so ever!!) Beware of Microsuft Agressive Marketing. !!! :-((( – Ken Mollerup Apr 06 '16 at 12:03
  • @Mehrdad, linux NTFS implementations have very long been experimental when it was about writing. The main trouble with NTFS is its closed spec aspect, meaning Microsoft does not give much information on how to implement NTFS. This is not Linux fault but Microsoft choice. About current NTFS implementations in Linux, there is many different ones. One or many of them are maybe broken about writing, or just obsolete in your current system. Look here for a list under Debian. I guess there is equivalent choices elsewhere for Ubuntu. – Frédéric Apr 06 '16 at 12:23
  • @KenMollerup: Tell us why anyone should believe what you're saying when you have provided zero links or technical details. – user541686 Apr 06 '16 at 18:01
  • @Frédéric: It's Linux fault and Microsoft choice. You can't corrupt user data and then blame it on someone else making their software closed-source. Furthermore, I believe Microsoft does share details of NTFS with its "partners" (those who make partition managers etc.), they just don't do it for free, but for a commercial company like Canonical, it doesn't seem out of the question to try that route. Finally, how do you even know the incompleteness of the current reverse-engineered spec of NTFS is the source of the problem? To me it seems like a completely unrelated bug. – user541686 Apr 06 '16 at 18:06
  • Continued in chat. – Frédéric Apr 06 '16 at 18:27
  • @Mehrdad I Have 2 Usb sticks that after Windows tried to use them for backup, while I was trying to put my Mail back together, show 0 bytes awailable out of 0! Nothing left out of 16GB Kingston DataTraveler, and a NoBrand 8GB. Nothing can make them come back to life! – Ken Mollerup Apr 07 '16 at 06:14
  • related: https://askubuntu.com/questions/955565/does-persistence-kills-usb-sticks – JinSnow Aug 27 '20 at 15:40

8 Answers8

105

No worries Ubuntu did not damage your USB drive. But we do not use poorly documented bit flags of a FAT32, FAT16, or NTFS filesystem. On Windows these flags indicate a possibly corrupted filesystem when we had not properly unmounted the drive or an I/O error had occured.

Those bits are located in a reserved entry of a FAT partition table. According to an internal Microsoft paper of 2004 the purpose of these bits are:

  • ClnShutBitMask:
    If bit is 1, the volume is “clean”. The volume can be mounted for access. If bit is 0, the volume is “dirty” indicating that a FAT file system driver was unable to dismount the volume properly (during a prior mount operation). The volume contents should be scanned for any damage to file system metadata.
  • HrdErrBitMask:
    If this bit is 1, no disk read/write errors were encountered. If this bit is 0, the file system driver implementation encountered a disk I/O error on the volume the last time it was mounted, which is an indicator that some sectors may have gone bad. The volume contents should be scanned with a disk repair utility that does surface analysis on it looking for new bad sectors.

There was some discussion with the kernel file system developers some years ago on how to overcome this but I was unable to follow up the results. Apparently it did not make it into recent kernels.

As only a bit flag is involved but generally our data should be in perfect shape we can ignore the warning Windows issues on those drives we had previously used in Ubuntu.

Takkat
  • 142,284
  • 3
    I've never had these errors in these drives when I actually safely unmount the drives - are you sure support for these bits is missing? – Thomas Ward Apr 01 '16 at 14:47
  • 5
    @ThomasW. These bits are quite obscure but I occasionally have these errors with my Ubuntu-formatted USB drives on my workplace Windows 7. So far I haven't seen any helpful pattern. Only thing I can say is that I always properly unmount/eject the drives. Testing is not easy because at home no Windows, at work no Ubuntu. – Takkat Apr 01 '16 at 15:49
  • The headline is false. – MatthewRock Apr 04 '16 at 13:25
  • @MatthewRock: better? – Takkat Apr 04 '16 at 13:27
  • Yes, it is better. – MatthewRock Apr 04 '16 at 13:49
  • This seems to be the more helpful answer. – xji Apr 05 '16 at 08:10
  • Whenever I had problems I just check and fix the drive with GParted - often it says 'Removing dirty bit' which I suppose refers to the above. These problems I usually had with silly windows machines refusing to unmount, or newer USB drives where you have to use 'Safely remove drive' instead. – Wilf Apr 07 '16 at 02:52
73

This is mostly an issue with Windows. It thinks it is the only OS in the world and acts out if it detects something it does not understand.

Just because Windows says you must repair the drive does not make it true.

Any of my drives used with Ubuntu get this message from Windows, I just say no and they work fine with Windows.

In short there is nothing wrong with the drive, it is just there is something on there that Windows does not understand and its response is destroy it.

Don't repair the drive, it will format it without telling you and you will lose all the data on the drive.

guntbert
  • 13,134
Mark Kirby
  • 18,529
  • 19
  • 78
  • 114
  • 41
  • Repair does not format, repair saves allocated data to a folder. For me it seems as Ubuntu does not finish write process properly.
  • – jan6352781 Apr 01 '16 at 10:19
  • 10
  • Most USB drives are FAT32 formatted, which was developed by Microsoft, so why should Windows be the only system to "not understand" somethin??
  • – jan6352781 Apr 01 '16 at 10:22
  • 6
  • The last years I skipped the repair almost every day ending up with damaged files and USB drives.
  • – jan6352781 Apr 01 '16 at 10:26