4 Replies Latest reply on Jan 13, 2016 2:41 PM by vjou

    Edison: how to clear dirty bit on USB drive from Yocto linux

    vjou

      When I mount USB drive (/dev/disk/by-partlabel/update) to loop device, the following message starts to show up in journalctl time to time. Once it starts, it continues to show up every time I mount the USB drive.

       

      Edison kernel: FAT-fs (loop0): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.

       

      It goes away when I do scan and fix from Windows. Editing dirty bit by Windows software also fixes the problem.

      But, I need to fix this problem from Edison by itself. I tried fsck.vfat with some combination of options, such as

       

      fsck.vfat -aw /dev/mmcblk0p9

      fsck.vfat -rw /dev/mmcblk0p9

      fsck.vfat -arw /dev/mmcblk0p9

       

      but I could not make it. Whichever I try, it just returns the following message, and the same FAT-fs message continues showing up in journalctl when I mount the USB drive.

       

      dosfsck 2.11, 12 Mar 2005, FAT32, LFN

      Logical sector size is zero.

       

      Please tell me what I am wrong about.

       

      Thank you

        • 1. Re: Edison: how to clear dirty bit on USB drive from Yocto linux
          vjou

          I found this page(https://www.raymond.cc/blog/manually-reset-or-clear-dirty-bit-in-windows-without-chkdsk/2/).

          And, I think I located the dirty bit, so far. I'm not sure if I can write the edited data back to the volume...

          root@Edison:~# dd if=/dev/mmcblk0p9 count=17 2>/dev/null | hexdump -C

          00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

          *

          000001b0  00 00 00 00 00 00 00 00  7b 42 36 fc 00 00 00 01  |........{B6.....|

          000001c0  01 00 0b 03 d0 ff 10 00  00 00 f0 ff 17 00 00 00  |................|

          000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

          *

          000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|

          00000200  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

          *

          <<< 0x2000 = 8192, byte that includes ‘dirty bit’ is highlighted green >>>

          00002000  eb 58 90 6d 6b 64 6f 73  66 73 00 00 02 08 20 00  |.X.mkdosfs.... .|

          00002010  02 00 00 00 00 f8 00 00  20 00 40 00 00 00 00 00  |........ .@.....|

          00002020  f0 ff 17 00 fd 05 00 00  00 00 00 00 02 00 00 00  |................|

          00002030  01 00 06 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

          00002040  80 01 29 ac a9 83 55 45  64 69 73 6f 6e 20 20 20  |..)...UEdison   |

          00002050  20 20 46 41 54 33 32 20  20 20 0e 1f be 77 7c ac  | FAT32   ...w|.|

          00002060  22 c0 74 0b 56 b4 0e bb  07 00 cd 10 5e eb f0 32  |".t.V.......^..2|

          00002070  e4 cd 16 cd 19 eb fe 54  68 69 73 20 69 73 20 6e  |.......This is n|

          00002080  6f 74 20 61 20 62 6f 6f  74 61 62 6c 65 20 64 69  |ot a bootable di|

          00002090  73 6b 2e 20 20 50 6c 65  61 73 65 20 69 6e 73 65  |sk. Please inse|

          000020a0  72 74 20 61 20 62 6f 6f  74 61 62 6c 65 20 66 6c  |rt a bootable fl|

          000020b0  6f 70 70 79 20 61 6e 64  0d 0a 70 72 65 73 73 20  |oppy and..press |

          000020c0  61 6e 79 20 6b 65 79 20  74 6f 20 74 72 79 20 61  |any key to try a|

          000020d0  67 61 69 6e 20 2e 2e 2e  20 0d 0a 00 00 00 00 00  |gain ... .......|

          000020e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

          *

          000021f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|

          00002200

          • 2. Re: Edison: how to clear dirty bit on USB drive from Yocto linux
            Intel_Peter

            Hello vjou,

             

            The package udisks should do the trick. I found out about this package in Ubuntu Forums and it work exactly as wish (but on my Ubuntu PC). I'm currently installing some dependencies on my Edison. You could try it too, so far I have had to install the following:

             

            libxml2 - Downloads

            libxslt - Downloads

             

            But I'm pretty sure I need some more and probably the dependencies have other dependencies, so it'll take a while. Meanwhile you could try it as well. You can find the source of udisks in:

             

            udisks

             

            Peter.

            • 3. Re: Edison: how to clear dirty bit on USB drive from Yocto linux
              vjou

              Hi Peter,

               

              Thank you for the information.

              I was trying to use dd to write the edited data back to the volume and it looks working. The FAT-fs message is gone now.

               

              Here is what I did:

              1. Copy 17th block from /dev/mmcblk0p9 to a file (mmcblk0p9_block17.img),

                  root@Edison:~# dd if=/dev/mmcblk0p9 skip=16 count=1 of=mmcblk0p9_block17.img

               

              2. Created another file (mmcblk0p9_edit01.img) by copying the block data other than the dirty-bit byte from the file,

                  root@Edison:~# dd bs=1c skip=0 count=65 if=mmcblk0p9_block17.img of=mmcblk0p9_edit01.img

                  root@Edison:~# printf '\x00' | dd bs=1c skip=0 count=1 seek=65 of=mmcblk0p9_edit01.img

                  root@Edison:~# dd bs=1c skip=66 seek=66 if=mmcblk0p9_block17.img of=mmcblk0p9_edit01.img

               

              3. Then copied the edited data (mmcblk0p9_edit01.img) back to the /dev/mmcblk0p9.

                  root@Edison:~# dd if=mmcblk0p9_edit01.img seek=16 count=1 of=/dev/mmcblk0p9


              Details are attached below. I hope this does not have unexpected side effects that I do not see so far.


              1. Copy one block from /dev/mmcblk0p9 to a file (mmcblk0p9_block17.img),

              root@Edison:~# dd if=/dev/mmcblk0p9 skip=16 count=1 of=mmcblk0p9_block17.img

              1+0 records in

              1+0 records out

               

              root@Edison:~# hexdump -C mmcblk0p9_block17.img

              00000000  eb 58 90 6d 6b 64 6f 73  66 73 00 00 02 08 20 00  |.X.mkdosfs.... .|

              00000010  02 00 00 00 00 f8 00 00  20 00 40 00 00 00 00 00  |........ .@.....|

              00000020  f0 ff 17 00 fd 05 00 00  00 00 00 00 02 00 00 00  |................|

              00000030  01 00 06 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

              00000040  80 01 29 ac a9 83 55 45  64 69 73 6f 6e 20 20 20  |..)...UEdison  |

              00000050  20 20 46 41 54 33 32 20  20 20 0e 1f be 77 7c ac  | FAT32  ...w|.|

              00000060  22 c0 74 0b 56 b4 0e bb  07 00 cd 10 5e eb f0 32  |".t.V.......^..2|

              00000070  e4 cd 16 cd 19 eb fe 54  68 69 73 20 69 73 20 6e  |.......This is n|

              00000080  6f 74 20 61 20 62 6f 6f  74 61 62 6c 65 20 64 69  |ot a bootable di|

              00000090  73 6b 2e 20 20 50 6c 65  61 73 65 20 69 6e 73 65  |sk. Please inse|

              000000a0  72 74 20 61 20 62 6f 6f  74 61 62 6c 65 20 66 6c  |rt a bootable fl|

              000000b0  6f 70 70 79 20 61 6e 64  0d 0a 70 72 65 73 73 20  |oppy and..press |

              000000c0  61 6e 79 20 6b 65 79 20  74 6f 20 74 72 79 20 61  |any key to try a|

              000000d0  67 61 69 6e 20 2e 2e 2e  20 0d 0a 00 00 00 00 00  |gain ... .......|

              000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

              *

              000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|

              00000200

               

              2. Created another file (mmcblk0p9_edit01.img) by copying the block data other than the dirty-bit byte from the file,

              root@Edison:~# dd bs=1c skip=0 count=65 if=mmcblk0p9_block17.img of=mmcblk0p9_edit01.img

              65+0 records in

              65+0 records out

               

              root@Edison:~# printf '\x00' | dd bs=1c skip=0 count=1 seek=65 of=mmcblk0p9_edit01.img

              1+0 records in

              1+0 records out

               

              root@Edison:~# dd bs=1c skip=66 seek=66 if=mmcblk0p9_block17.img of=mmcblk0p9_edit01.img

              446+0 records in

              446+0 records out

               

              root@Edison:~# hexdump -C mmcblk0p9_edit01.img

              00000000  eb 58 90 6d 6b 64 6f 73  66 73 00 00 02 08 20 00  |.X.mkdosfs.... .|

              00000010  02 00 00 00 00 f8 00 00  20 00 40 00 00 00 00 00  |........ .@.....|

              00000020  f0 ff 17 00 fd 05 00 00  00 00 00 00 02 00 00 00  |................|

              00000030  01 00 06 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

              00000040  80 00 29 ac a9 83 55 45  64 69 73 6f 6e 20 20 20  |..)...UEdison  |

              00000050  20 20 46 41 54 33 32 20  20 20 0e 1f be 77 7c ac  | FAT32  ...w|.|

              00000060  22 c0 74 0b 56 b4 0e bb  07 00 cd 10 5e eb f0 32  |".t.V.......^..2|

              00000070  e4 cd 16 cd 19 eb fe 54  68 69 73 20 69 73 20 6e  |.......This is n|

              00000080  6f 74 20 61 20 62 6f 6f  74 61 62 6c 65 20 64 69  |ot a bootable di|

              00000090  73 6b 2e 20 20 50 6c 65  61 73 65 20 69 6e 73 65  |sk. Please inse|

              000000a0  72 74 20 61 20 62 6f 6f  74 61 62 6c 65 20 66 6c  |rt a bootable fl|

              000000b0  6f 70 70 79 20 61 6e 64  0d 0a 70 72 65 73 73 20  |oppy and..press |

              000000c0  61 6e 79 20 6b 65 79 20  74 6f 20 74 72 79 20 61  |any key to try a|

              000000d0  67 61 69 6e 20 2e 2e 2e  20 0d 0a 00 00 00 00 00  |gain ... .......|

              000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

              *

              000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|

              00000200

               

              3. Then copied the edited data (mmcblk0p9_edit01.img) back to the /dev/mmcblk0p9.

              root@Edison:~# dd if=mmcblk0p9_edit01.img seek=16 count=1 of=/dev/mmcblk0p9

              1+0 records in

              1+0 records out

               

              root@Edison:~# dd if=/dev/mmcblk0p9 skip=16 count=1 | hexdump -C

              1+0 records in

              1+0 records out

              00000000  eb 58 90 6d 6b 64 6f 73  66 73 00 00 02 08 20 00  |.X.mkdosfs.... .|

              00000010  02 00 00 00 00 f8 00 00  20 00 40 00 00 00 00 00  |........ .@.....|

              00000020  f0 ff 17 00 fd 05 00 00  00 00 00 00 02 00 00 00  |................|

              00000030  01 00 06 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

              00000040  80 00 29 ac a9 83 55 45  64 69 73 6f 6e 20 20 20  |..)...UEdison  |

              00000050  20 20 46 41 54 33 32 20  20 20 0e 1f be 77 7c ac  | FAT32  ...w|.|

              00000060  22 c0 74 0b 56 b4 0e bb  07 00 cd 10 5e eb f0 32  |".t.V.......^..2|

              00000070  e4 cd 16 cd 19 eb fe 54  68 69 73 20 69 73 20 6e  |.......This is n|

              00000080  6f 74 20 61 20 62 6f 6f  74 61 62 6c 65 20 64 69  |ot a bootable di|

              00000090  73 6b 2e 20 20 50 6c 65  61 73 65 20 69 6e 73 65  |sk. Please inse|

              000000a0  72 74 20 61 20 62 6f 6f  74 61 62 6c 65 20 66 6c  |rt a bootable fl|

              000000b0  6f 70 70 79 20 61 6e 64  0d 0a 70 72 65 73 73 20  |oppy and..press |

              000000c0  61 6e 79 20 6b 65 79 20  74 6f 20 74 72 79 20 61  |any key to try a|

              000000d0  67 61 69 6e 20 2e 2e 2e  20 0d 0a 00 00 00 00 00  |gain ... .......|

              000000e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

              *

              000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|

              00000200
              • 4. Re: Edison: how to clear dirty bit on USB drive from Yocto linux
                vjou

                Just FYI,

                Above was able to be done by directly writing a byte into the USB drive volume like below.

                8257 is valid only for FAT32. If you look for other format, this page(https://www.raymond.cc/blog/manually-reset-or-clear-dirty-bit-in-windows-without-chkdsk/2/) may help you.


                root@Edison:~# printf '\x00' | dd bs=1c seek=8257 count=1 of=/dev/mmcblk0p9

                 

                This is a scary operation to me. I still feel a little safer with the way described in my previous reply.

                 

                --- EDIT START 1/13/2016 ---

                I'm sorry, but I was a little wrong about the value 8257. Now, I'm only sure that the value 8257 is valid for Edison's USB Mass Storage and NOT for all of FAT32 formats, because I recognized that the offset value to mount the FAT32 volume sometimes differs from 8192.

                So, please do not try this without confirming the location of dirty bit.

                --- EDIT END ---

                1 of 1 people found this helpful