USB corrupted filesystem

Discussion in 'Tomato Firmware' started by rs232, May 17, 2019 at 10:27 AM.

  1. rs232

    rs232 Network Guru Member

    On 3 different routers recently I have found some sort of USB filesystem issue.
    I'm a bit puzzled on this one as all 3 devices are connected to an APC and (as far as I remember at least) they suffered no specific issues although they might have gone through some manual power cycling now and again.

    The process to resolve the issue has been extremely painful and time consuming for what it was.Deselect mount automatically, reboot, fix, reboot, re-enable automounting, mounting.... all this all in between many "device busy", you get the picture, we've all been there I guess.

    I was wondering.... is there a smart way to force a filesystem check/repair prior to the USB mounting? Perhaps to be added in the INIT script? Or perhaps we could use a new "Run before mounting" function?

    In general I'm wondering what tomato could provide to simplify this task.

    Last edited: May 17, 2019 at 2:01 PM
  2. Sean B.

    Sean B. Network Guru Member

    Just unmount it via command line in a shell. Run e2fsck ( depending what filesystem you formatted the drive as ), and remount.
  3. rs232

    rs232 Network Guru Member

    Appreciate that, as mentioned unmount often fails bacause entware, dependencies, etc.

    I was suggesting a "scan and repair at next reboot" or "scan and repair before mounting" function if you get what I mean...
  4. Monk E. Boy

    Monk E. Boy Network Guru Member

    I've seen this periodically although my fix is usually to uncleanly remove the drive and then connect it to a desktop running a full Linux distro and fsck it there. More than a few times the flash drive itself had failed so there was no bringing it back to life.

    In the event of failure with the disk unmounted you can sudo dd if=/dev/zero of=/dev/diskdevicehere then control c a minute or so later to write zeros to the start of the disk, unplug, plug, and voila, you have a "blank" disk. Although when the drive hardware fails it typically would error out after a couple seconds to write. Note that this does destroy the partition map so if you want to save data don't write zeros, although again in the case of the failed drives it refused to read from the disk as well, so this was a hail mary hope it works kind of thing.

    In theory this might work on the router itself but everything runs faster on a desktop so I tend to sidestep routers when I have physical access to the system.
  5. Sean B.

    Sean B. Network Guru Member

    I thought it would be a given, but yes, you must kill any running processes of which are running on ( or have libraries/file locks etc ) the USB drive. Either shut them down gracefully or use kill and their PID#. That is no different a requirement than a regular desktop.

    Ext3/4 will auto-repair the first attempt to mount during boot after a previous unclean dismount. This can be seen in the system log.
  6. rs232

    rs232 Network Guru Member

    that's even longer than the way I described in my OP :rolleyes:

    I do agree that the pendrive needs to be top-notch brand, I would not recommend anybody to save money on them for what they cost and for the amount of headache they give when they fail.

    The angle where I'm coming from is that very often (for me at least) things on routers have to be done remotely. A router can indeed repair a file-system issue all I'm looking for here (for us all really I should say) is a way to repair with minimum effort.

    Scripting this is not an issue really but needs to be executed before the USB mounting function which is something we currently don't have in tomato.
  7. rs232

    rs232 Network Guru Member

    Interesting I will keep an eye, but I'm sure I did repair manually in the past so perhaps it's not always effective. The issue here really is the manual power cycle of the router... you would never power down a linux physical box unplugging the power, that's recipe for disaster. Perhaps we should have "a" button on the router whose task is to run "reboot" or "shutdown" gracefully so unmounting things as they should.
  8. Sean B.

    Sean B. Network Guru Member

    I don't see why you're set on shutting down or rebooting the router to unmount/mount the USB drive. It's simply not required, not in any use case I can think of. You just kill the processes of which are running from/using files on the USB drive, run umount, run e2fsck, run mount, done. All can be done remotely, all without power cycling the router.
  9. rs232

    rs232 Network Guru Member

    Because reboot is 1 click and perhaps an additional one to set "force filesystem check/repair at the next boot" which we don't have.

    What I'm trying to say is: corrupted filesystem on USB storage while connected to tomato is sadly happening rather often. Let's make it easy-peasy to fix. I know how to fix this manually I still think there's a value in providing an automated "1 click" function for all the users.

    BTW even if I know how to fix this, sometime I really don't have the time! I need to remember the commands, sequence, etc. This is another good reason why I decided to post on this topic :)

    It's more a vision than a technical issue this one of mine.
  10. Sean B.

    Sean B. Network Guru Member

    IMHO, the perceived liability for Tomato offering "1 button" to fix your filesystem is astronomical. Even if you just wanted to script a few shell commands together, you'd have to code checks and balances to make sure you're running the right program for the filesystem in use on the drive. And then, if the program ( such as e2fsck ) fails, or worse causes data loss, end users will blame Tomato devs, not the program Tomato simply executed. I don't see it as a viable concept.
  11. rs232

    rs232 Network Guru Member

    I don't disagree with you. But... if we forget about filesystem corruption for a minute, more generically I just would like to narrow down my question to the simplier:

    - how do I run something before USB mounts?
  12. AndreDVJ

    AndreDVJ LI Guru Member

    Does Hotplug script run before partition is actually mounted?
  13. Sean B.

    Sean B. Network Guru Member

    You don't, not with auto mount enabled. At least not anything that would be affected by the drive being mounted, as auto mount would have the drive mounted milliseconds after, if not before.
    Last edited: May 18, 2019 at 11:08 PM
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice