Page 1 of 1

Unmount/Mount systematically sets dirty bit

Posted: Wed Jan 25, 2017 3:20 pm
by tohox
Hi,

I'm using a Python script to automate a timelapse. My script periodically switches the DSLR to mass storage mode in order to offload its SD card onto the Pi. To achieve this the Pi has to mount and unmount the volume frequently. I noted the other day that the dirty bit was set on the camera's SD card so I ran fsck which simply reported that the dirty bit was set and that it was automatically removed. I then proceeded to manually unmount and remount the volume to check if my script was causing this behaviour but the dirty bit was set again. I tried the cycle below a couple times and each time the dirty bit gets set after unmounting/remounting:

Code: Select all

sudo mount /dev/sdb1 /media/GX7
sudo fsck -a /media/GX7
At this point fsck reports the dirty bit was set and automatically removed so I run it once more to confirm.

Code: Select all

sudo fsck -a /media/GX7
This time fsck reports no problems so I unmount and mount to check again...

Code: Select all

sudo umount /media/GX7
sudo mount /dev/sdb1 /media/GX7
sudo fsck -a /media/GX7
Dirty bit is set again...

EDIT: I just tried the same routine as above but through a USB SD card reader instead of the camera and got the same result. Repeated the same test with a different SD card also with the same result. Tried again on a different Pi although with the same OS version (Jessie with Pixel) and again the dirty bit is always set.

There doesn't seem to be any consequences other than the annoying warning but I'm wondering if anyone has experienced a similar problem?

Thanks,

Re: Unmount/Mount systematically sets dirty bit

Posted: Wed Jan 25, 2017 5:53 pm
by AlexJ
Looks like this is not pi specific: http://unix.stackexchange.com/questions ... ounting-it

Re: Unmount/Mount systematically sets dirty bit

Posted: Wed Jan 25, 2017 8:57 pm
by tohox
So in principle unmounting the volume should clear the dirty bit as long as it wasn't set before mounting it in the first place but that doesn't seem to be the case here.

Thanks for the link!

Re: Unmount/Mount systematically sets dirty bit

Posted: Thu May 18, 2017 2:37 am
by tohox
Hi,

Just bumping this post as I still haven't found a valid explanation as to why the dirty bit gets set by simply mounting and immediately unmounting an SD card under Raspbian...

Thanks,

Re: Unmount/Mount systematically sets dirty bit

Posted: Thu May 18, 2017 2:52 am
by scruss
Use mount -o ro to read the device

Re: Unmount/Mount systematically sets dirty bit

Posted: Thu May 18, 2017 3:13 am
by tohox
Scruss,

Indeed but what if I need to erase some files on the SD card before unmounting it? I assume I should be able to do this without setting the dirty bit if done correctly...

Thanks,

Re: Unmount/Mount systematically sets dirty bit

Posted: Thu May 18, 2017 3:50 am
by DougieLawson
Have you checked whether that SDCard is worn out? When they reach the end of their usable life the SDCard goes into read only mode and if the dirty bit was set at that time it would stay set for ever.

Are you able to create a new file on it that doesn't disappear after a umount/mount sequence of commands?

Also try
sudo -i
for i in /dev/sda1 /dev/sda2; do umount $i; fsck -f -y $i; done
exit


Because the GUI includes an automounter and that may have mounted the SDCard on /media/pi/xxxxxx directories. If you pull the card while those things are still mounted then you will set the dirty bit.

EDIT: brain dead moron error. Left the testing echos in the command.

Re: Unmount/Mount systematically sets dirty bit

Posted: Thu May 18, 2017 5:00 am
by tohox
Hi Dougie,

SD card is not worn out (yet) as it is currently getting written to a couple thousand times a day by the camera and files are still there after unmounting/mounting. Also as mentioned above I've verified this same behaviour with both a different card and a different Pi.

I'm running with X disabled and can confirm that nothing gets automatically mounted under /media/pi. I have however configured fstab so that it mounts the SD card automatically based on its UUID like so:

Code: Select all

UUID=5FC6-EB2A  /media/GX7      vfat    defaults,nofail 0       0
Is something wrong with this method? Could this perhpas be a vfat specific issue?

I've modified your suggested test a bit as my card is actually getting mounted at /dev/sdb1 and not /dev/sda1 or /dev/sda2 (sda1 is already used by another disk). Unfortunately it yields no output besides the commands themselves:

Code: Select all

[email protected]:/media $ sudo -i
[email protected]:~# for i in /dev/sdb1 /dev/sdb2; do echo umount $i; echo fsck -f -y $i; done
umount /dev/sdb1
fsck -f -y /dev/sdb1
umount /dev/sdb2
fsck -f -y /dev/sdb2
[email protected]:~# exit
logout
[email protected]:/media $
However if I run it without the for loop I get:

Code: Select all

[email protected]:/media $ sudo umount /dev/sdb1
[email protected]:/media $ sudo fsck -f -y /dev/sdb1
fsck from util-linux 2.25.2
fsck.fat 3.0.27 (2014-11-12)
/dev/sdb1: 28 files, 846/474368 clusters
But upon remounting the card the dirty bit appears set again...

I've also verified the volume was not used by any process before unmounting it with:

Code: Select all

[email protected]:/media $ sudo fuser -v /media/GX7
                     USER        PID ACCESS COMMAND
/media/GX7:          root     kernel mount /media/GX7
Can anyone try mounting and unmounting a known good vfat SD card on Raspbian Jessie and report if they also get the dirty bit set upon remounting despite having cleared it previously?

Thanks,

Re: Unmount/Mount systematically sets dirty bit

Posted: Thu May 18, 2017 5:05 am
by DougieLawson
Sorry I'm a moron. I left the "echo" commands in (because I didn't want to unmount anything on my RPi that's currently a 10 and a half hour flight away from where I am right now).

sudo -i
for i in /dev/sda1 /dev/sda2; do umount $i; fsck -f -y $i; done
exit

Re: Unmount/Mount systematically sets dirty bit

Posted: Thu May 18, 2017 5:36 am
by tohox

Code: Select all

[email protected]:~/timelapse $ sudo -i
[email protected]:~# for i in /dev/sdb1 /dev/sdb2; do umount $i; fsck -f -y $i; done
fsck from util-linux 2.25.2
fsck.fat 3.0.27 (2014-11-12)
Free cluster summary uninitialized (should be 473522)
  Auto-setting.
Performing changes.
/dev/sdb1: 28 files, 846/474368 clusters
umount: /dev/sdb2: mountpoint not found
fsck from util-linux 2.25.2
e2fsck 1.42.12 (29-Aug-2014)
fsck.ext2: No such file or directory while trying to open /dev/sdb2
Possibly non-existent device?
[email protected]:~#
Same result after remounting, still dirty...

Btw, I couldn't find anything regarding the -f parameter you are using with fsck above. What does it do?

Re: Unmount/Mount systematically sets dirty bit

Posted: Sun May 21, 2017 2:42 pm
by DougieLawson
You've got a NOOBS system

so you'll need to check /dev/sdb1 /dev/sdb5 and /dev/sdb6 (maybe more if you have more than one OS).

Re: Unmount/Mount systematically sets dirty bit

Posted: Thu Mar 08, 2018 12:09 pm
by sameenashaikh29
Have you found the solution. I am doing something similar to this

Re: Unmount/Mount systematically sets dirty bit

Posted: Thu Mar 08, 2018 1:19 pm
by scruss
Can you use PTP mode instead? That way the camera manages its filesystem, so you never have to explicitly mount the SD card under Linux.

Re: Unmount/Mount systematically sets dirty bit

Posted: Thu Mar 08, 2018 1:23 pm
by n67
scruss wrote:
Thu Mar 08, 2018 1:19 pm
Can you use PTP mode instead? That way the camera manages its filesystem, so you never have to explicitly mount the SD card under Linux.
That site could use some editing...

Re: Unmount/Mount systematically sets dirty bit

Posted: Thu Mar 08, 2018 2:08 pm
by tohox
Unfortunately sameenashaikh29, in the end I simply ignored the dirty bit... Been working OK despite this.

Re: Unmount/Mount systematically sets dirty bit

Posted: Thu Mar 08, 2018 8:39 pm
by scruss
Yeah, it was the only PTP and linux site I could find quickly. gphoto does PTP control.