1

I have a flash drive formatted with a FAT32 partition. When I pull it out before unmounting it naturally has the dirty bit set and when I use the flash in a Windows machine, Windows complains that the drive should be repaired.

The Linux machine is an embedded device and has no "unmount" in its GUI. But I have SSH access to this machine and I tried to use the command below to clear the dirty bit:

root@system:~# fsck.fat -aw /dev/sda1
fsck.fat 4.1 (2017-01-24)
0x41: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.
 Automatically removing dirty bit.
Performing changes.
/dev/sda1: 4 files, 4/261376 clusters

Then I remove the drive (still no unmount) and when I plug it back in a Windows system it still shows the drive should repaired message.

So the question is, why fsck does not actually clear the dirty bit?

Is there any way to prevent or clear the drty bit so plugging out the drive without a proper unmount doesnt trigger the dirty bit?

The reason: I want to have a script or service to perform fsck to clear dirty bit as soon as a drive is mounted. I mean I want the device not to set the dirty bit at all or clear it as soon as a drive is inserted. Because the user has no way of asking the system to perform the unmount

3
  • Dunno about dirty bit but if you have SSH you can umount /dev/sda1
    – golimar
    Feb 2 at 13:07
  • @golimar Yes but the user of the system has no SSH. I updated my question to refelect the reasoning behind my question
    – DEKKER
    Feb 2 at 13:15
  • If you do not have umount, you could try mount -o remount,ro /dev/sda1 to remount it read-only. This might make the kernel write a clean flag, and you can then safely remove the drive.
    – meuh
    Feb 2 at 15:10

1 Answer 1

1

There was a commit to dosfstools to fix the dirty bit correctly in jan 2021. This became release 4.2, and it seems you have 4.1.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .