tohox
Posts: 11
Joined: Tue Dec 29, 2015 12:04 am

Unmount/Mount systematically sets dirty bit

Wed Jan 25, 2017 3:20 pm

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,


tohox
Posts: 11
Joined: Tue Dec 29, 2015 12:04 am

Re: Unmount/Mount systematically sets dirty bit

Wed Jan 25, 2017 8:57 pm

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!

tohox
Posts: 11
Joined: Tue Dec 29, 2015 12:04 am

Re: Unmount/Mount systematically sets dirty bit

Thu May 18, 2017 2:37 am

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,

User avatar
scruss
Posts: 2615
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Unmount/Mount systematically sets dirty bit

Thu May 18, 2017 2:52 am

Use mount -o ro to read the device
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

tohox
Posts: 11
Joined: Tue Dec 29, 2015 12:04 am

Re: Unmount/Mount systematically sets dirty bit

Thu May 18, 2017 3:13 am

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,

User avatar
DougieLawson
Posts: 36518
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Unmount/Mount systematically sets dirty bit

Thu May 18, 2017 3:50 am

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.
Last edited by DougieLawson on Thu May 18, 2017 5:01 am, edited 1 time in total.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

tohox
Posts: 11
Joined: Tue Dec 29, 2015 12:04 am

Re: Unmount/Mount systematically sets dirty bit

Thu May 18, 2017 5:00 am

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
r[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,

User avatar
DougieLawson
Posts: 36518
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Unmount/Mount systematically sets dirty bit

Thu May 18, 2017 5:05 am

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
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

tohox
Posts: 11
Joined: Tue Dec 29, 2015 12:04 am

Re: Unmount/Mount systematically sets dirty bit

Thu May 18, 2017 5:36 am

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?

User avatar
DougieLawson
Posts: 36518
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Unmount/Mount systematically sets dirty bit

Sun May 21, 2017 2:42 pm

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).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

sameenashaikh29
Posts: 7
Joined: Thu Jan 11, 2018 7:15 am

Re: Unmount/Mount systematically sets dirty bit

Thu Mar 08, 2018 12:09 pm

Have you found the solution. I am doing something similar to this

User avatar
scruss
Posts: 2615
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Unmount/Mount systematically sets dirty bit

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.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

n67
Posts: 938
Joined: Mon Oct 30, 2017 4:55 pm

Re: Unmount/Mount systematically sets dirty bit

Thu Mar 08, 2018 1:23 pm

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...
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

tohox
Posts: 11
Joined: Tue Dec 29, 2015 12:04 am

Re: Unmount/Mount systematically sets dirty bit

Thu Mar 08, 2018 2:08 pm

Unfortunately sameenashaikh29, in the end I simply ignored the dirty bit... Been working OK despite this.

User avatar
scruss
Posts: 2615
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Unmount/Mount systematically sets dirty bit

Thu Mar 08, 2018 8:39 pm

Yeah, it was the only PTP and linux site I could find quickly. gphoto does PTP control.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

Return to “Raspbian”