What's new

fsck in pre-mount w/mixed file system types (EXT2 & FAT32)

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

latenitetech

Regular Contributor
I'm thinking this should be a trivial problem, but I've not stumbled on the solution yet. I'm wanting to add an auto-fsck for my flash drives in the pre-mount script (AsusWRT-Merlin 380.64, RT-AC68U). It's easy when all the volumes use the same file system type, but I have a mix of EXT2 and FAT32, so I need to be able to determine either the partition label or the file system type from the /dev/sdx# that's passed in as the first argument, so I call the proper fsck program. The mount order is pretty random, so I can't go by just the device name as it's always different.

I think all I need is a simple utility (or command sequence) that given the device string, returns either the file system type or the partition label. I can take it from there.

Any ideas?

Thx
-Mark
 
I believe I've solved this. There may well be a better way, but this is what I came up with:
Code:
#!/bin/sh
# pre-mount script (to be installed in /jffs/scripts)
# auto-check filesystems during boot
# first argument is the filesystem to be mounted (e.g. /dev/sda1)

CHKLOG=/var/fsck.log

# determine the type of filesystem being mounted
FSTYPE=`fdisk -l ${1:0:8} | grep $1 | cut -c55-65`

# determine the appropriate checker for the filesystem
case "$FSTYPE" in
    Linux )
        CHKCMD="e2fsck -p" ;;
    Win95* | FAT* )
        CHKCMD="fatfsck -a" ;;
    HPFS/NTFS )
        CHKCMD="ntfsck -a" ;;
    * )
        logger "$0:" "Unknown filesystem type $FSTYPE on $1 - no filesystem check run."
        exit 1 ;;
esac

logger "$0:" "Running '$CHKCMD $1' - see output at $CHKLOG"
echo -e "\nStarting '$CHKCMD $1' at `date`" >> $CHKLOG
$CHKCMD $1 >> $CHKLOG 2>&1
Seems to work. I'm personally only using EXT2 and FAT32 on my router, but I went ahead and added the cases for FAT and NTFS. I'm not an Apple guy, so I couldn't add the case for HFS (I don't know what string to look for from the fdisk call).

Still open to ideas for a better mousetrap ...

-Mark
 
Doing the check on every boot seems a bit extreme.....any reason you didn't use the Disk Utility to schedule a periodic check?
 
Doing the check on every boot seems a bit extreme.....any reason you didn't use the Disk Utility to schedule a periodic check?
Honestly, I'm not familiar with the Disk Utility (Linux newbie). I got to looking at a boot-time check from the Wiki that describes the pre-mount script. As for extreme, I'm specifically using the 'auto' option of fsck, which only takes action if the volume is marked dirty. In a normal case, it only adds a second or two per volume to the boot. If a volume truly is dirty, I'd rather it take the time to fix it.

Perhaps I'm doing something wrong, but it's a bit of a pita to dismount and run fsck on a running system, at least my system. I have several apps that depend on entware, so to check the entware volume I need to shut down all those apps, turn off swap, etc., before I can umount. Similarly, I'm running Samba, minidlna and pyTivo, that all must be stopped before I can umount my media volumes. It's just much easier to do the disk check during the boot.

Finally, once I get things running to my liking, I don't intend to be rebooting very often. I'm extremely impressed with the stability of this firmware, one of the main things that brought me to Merlin from the DD-WRT environment I'd been using for years on previous routers. While I loved the extra functionality DD-WRT brought me, stability was not one of its strong points. ;)
 
Honestly, I'm not familiar with the Disk Utility (Linux newbie).
Sorry I wasn't clearer....the disk check utility is built into the firmware. From the main Networkmap page, click on the icon for the drive you wan to check, then the Disk Utility tab. From there you can set up a check schedule (it will automatically handle all the partitions on the selected drive).

EDIT: I'm not sure it will handle all your entware apps (but it will take care of starting/stopping the apps built into the firmware).
 
Sorry I wasn't clearer....the disk check utility is built into the firmware. From the main Networkmap page, click on the icon for the drive you wan to check, then the Disk Utility tab. From there you can set up a check schedule (it will automatically handle all the partitions on the selected drive).

EDIT: I'm not sure it will handle all your entware apps (but it will take care of starting/stopping the apps built into the firmware).

Thanks @john9527, I did not even realize that option was there! One has to click on the USB icon for the menu to appear in the upper right hand corner. I have been seeing some I/O errors in my logs so I need to take time to e2fsck the little guys.

Code:
kernel: EXT2-fs (sdc1): previous I/O error to superblock detected

I have two mounted to a USB 2.0 hub. One runs entware and the other ab solution-3. All is working good, but I need to take care of this....Seems to always be something.
 
Sorry I wasn't clearer....the disk check utility is built into the firmware. From the main Networkmap page, click on the icon for the drive you wan to check, then the Disk Utility tab. From there you can set up a check schedule (it will automatically handle all the partitions on the selected drive).

EDIT: I'm not sure it will handle all your entware apps (but it will take care of starting/stopping the apps built into the firmware).
I got around to looking at the built-in disk check utility you mentioned, and determined it's fairly easy add some code to the 'unmount' custom script to do an entware services-stop. With that, I was able to get the built-in health scanner to successfully scan the entware volume. I included that technique at the tail end of my first Merlin wiki contribution at: https://github.com/RMerl/asuswrt-me...eck-at-Boot-(and-other-noobie-hints-and-tips)

I'm still not convinced there aren't some further issues in that stock AsusWRT code in the Health Scanner section, as I was seeing some flaky actions happening with regard to stopping and starting the built-in Samba and minidlna services. It's on my list of further things to look at, but pretty far down the list right now.

-Mark
 
as I was seeing some flaky actions happening with regard to stopping and starting the built-in Samba and minidlna services
Yes, the built in checker will stop all and restart the active services that can use the USB being scanned. If you are using a swap partition, it will also take care of unmounting/mounting the swap. Otherwise, if using a swap file, you need to take care of it in unmount/post-mount scripts.

Thanks for the wiki updates.....help is always appreciated!
 
Hello

Im trying to run this on my router but keep getting some errors
Code:
Dec 31 19:00:19 pre-mount: Loading Drive checker
Dec 31 19:00:20 admin: /jffs/scripts/drive_check: Unknown filesystem type  on  - no filesystem check run.

These are my drives:
Code:
admin@RT-AC66U-FF48:/tmp# fdisk /dev/sda -l

Disk /dev/sda: 15.7 GB, 15703474176 bytes
255 heads, 63 sectors/track, 1909 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks  Id System
/dev/sda1               2        1909    15326010   f Win95 Ext'd (LBA)
/dev/sda5               2         102      811251  83 Linux
/dev/sda6             103        1909    14514696   b Win95 FAT32

This is my script
Code:
#!/bin/sh
# pre-mount script (to be installed in /jffs/scripts)
# auto-check filesystems during boot
# first argument is the filesystem to be mounted (e.g. /dev/sda1)

CHKLOG=/var/fsck.log

# determine the type of filesystem being mounted
FSTYPE=`fdisk -l ${1:0:8} | grep $1 | cut -c55-65`

# determine the appropriate checker for the filesystem
case "$FSTYPE" in
        Linux )
                CHKCMD="e2fsck -p" ;;
        Win95* | FAT* )
                CHKCMD="fatfsck -a" ;;
        HPFS/NTFS )
                CHKCMD="ntfsck -a" ;;
        * )
                logger "$0:" "Unknown filesystem type $FSTYPE on $1 - no filesystem check run."
                exit 1 ;;
esac

logger "$0:" "Running '$CHKCMD $1' - see output at $CHKLOG"
echo -e "\nStarting '$CHKCMD $1' at `date`" >> $CHKLOG
$CHKCMD $1 >> $CHKLOG 2>&1

what could i be missing?

thanks!!
 
Hello

Im trying to run this on my router but keep getting some errors
Code:
Dec 31 19:00:19 pre-mount: Loading Drive checker
Dec 31 19:00:20 admin: /jffs/scripts/drive_check: Unknown filesystem type  on  - no filesystem check run.

These are my drives:
Code:
admin@RT-AC66U-FF48:/tmp# fdisk /dev/sda -l

Disk /dev/sda: 15.7 GB, 15703474176 bytes
255 heads, 63 sectors/track, 1909 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks  Id System
/dev/sda1               2        1909    15326010   f Win95 Ext'd (LBA)
/dev/sda5               2         102      811251  83 Linux
/dev/sda6             103        1909    14514696   b Win95 FAT32

This is my script
Code:
#!/bin/sh
# pre-mount script (to be installed in /jffs/scripts)
# auto-check filesystems during boot
# first argument is the filesystem to be mounted (e.g. /dev/sda1)

CHKLOG=/var/fsck.log

# determine the type of filesystem being mounted
FSTYPE=`fdisk -l ${1:0:8} | grep $1 | cut -c55-65`

# determine the appropriate checker for the filesystem
case "$FSTYPE" in
        Linux )
                CHKCMD="e2fsck -p" ;;
        Win95* | FAT* )
                CHKCMD="fatfsck -a" ;;
        HPFS/NTFS )
                CHKCMD="ntfsck -a" ;;
        * )
                logger "$0:" "Unknown filesystem type $FSTYPE on $1 - no filesystem check run."
                exit 1 ;;
esac

logger "$0:" "Running '$CHKCMD $1' - see output at $CHKLOG"
echo -e "\nStarting '$CHKCMD $1' at `date`" >> $CHKLOG
$CHKCMD $1 >> $CHKLOG 2>&1

what could i be missing?

thanks!!
I think you simply forgot to pass on $1 to your script (the device to be mounted, which is the first argument passed to the pre-mount script). So in pre-mount, call your script with:
Code:
/jffs/scripts/drive_check $1

Any reason why you put it in a separate script rather than just put the code directly in pre-mount? The original design intent was the script listed is the actual 'pre-mount' script, rather than have it call yet another script. But what you have should be fine so long as you pass along $1 to your script.
 
Thanks. Im trying this now and will get back to you!

I did it that way just to keep stuff organized my way

pre-mount ----- ill add the "$1"
Code:
#!/bin/sh
me=`basename "$0"`

logger -t $me "Loading Drive checker"
/jffs/scripts/drive_check
 
hello again

i made some progress. the $1 was indeed missing.
Im now getting a not found error when trying to run fatfsck

Code:
Starting 'e2fsck -p /dev/sda5' at Fri Jul 31 19:00:31 GMT 2015
/dev/sda5: clean, 53/101472 files, 4242/202812 blocks

Starting 'fatfsck -a /dev/sda6' at Thu Apr  6 19:58:53 GMT 2017
/jffs/scripts/drive_check: line 28: fatfsck: not found

why could this happen?

thanks!
 
hello again

i made some progress. the $1 was indeed missing.
Im now getting a not found error when trying to run fatfsck

Code:
Starting 'e2fsck -p /dev/sda5' at Fri Jul 31 19:00:31 GMT 2015
/dev/sda5: clean, 53/101472 files, 4242/202812 blocks

Starting 'fatfsck -a /dev/sda6' at Thu Apr  6 19:58:53 GMT 2017
/jffs/scripts/drive_check: line 28: fatfsck: not found

why could this happen?

thanks!
That's certainly a strange one. fatfask comes built-in with the firmware load, so hard to believe it's not there. But that's the first thing to verify. Is it found if you invoke it from the command line (ssh or telnet)? You could also run 'which fatfsck', and that will report if it's found down the path and the location (should be '/usr/sbin/fatfsck').

I'm going to bet you have a typo or issue in your script, and the error message is misleading. A couple of things to look for:
1) Run 'dos2unix /jffs/scripts/drive_check'
That will remove any possible issues resulting from creating or editing the file on a Windows box. It won't hurt anything if no problem exists, but a common (and hard to see) issue with shell scripts on Linux.
2) Look for any unintended line breaks in the script introduced by your text editor. The easiest way to see those is ensure you have a wide screen window while editing the file (wider than the longest line in the script). Many editors will "auto wrap" long lines that will cause confusion in a shell script.

If none of that helps, I'd suggest post the entire/exact script to see if someone can spot the issue.

Best of luck!
 
That's certainly a strange one. fatfask comes built-in with the firmware load, so hard to believe it's not there. But that's the first thing to verify. Is it found if you invoke it from the command line (ssh or telnet)? You could also run 'which fatfsck', and that will report if it's found down the path and the location (should be '/usr/sbin/fatfsck').

I'm going to bet you have a typo or issue in your script, and the error message is misleading. A couple of things to look for:
1) Run 'dos2unix /jffs/scripts/drive_check'
That will remove any possible issues resulting from creating or editing the file on a Windows box. It won't hurt anything if no problem exists, but a common (and hard to see) issue with shell scripts on Linux.
2) Look for any unintended line breaks in the script introduced by your text editor. The easiest way to see those is ensure you have a wide screen window while editing the file (wider than the longest line in the script). Many editors will "auto wrap" long lines that will cause confusion in a shell script.

If none of that helps, I'd suggest post the entire/exact script to see if someone can spot the issue.

Best of luck!

hello...
weird weird...none of what you advise seem to make sense to my router! o_O

trying to run fatfsck
Code:
ASUSWRT-Merlin RT-AC66U 380.65-4 Wed Mar 29 04:40:30 UTC 2017

admin@RT-AC66U-FF48:/jffs/scripts# fatfsck
-sh: fatfsck: not found

admin@RT-AC66U-FF48:/jffs/scripts# which fatfsck
admin@RT-AC66U-FF48:/jffs/scripts#


running dos2unix
Code:
ASUSWRT-Merlin RT-AC66U 380.65-4 Wed Mar 29 04:40:30 UTC 2017

admin@RT-AC66U-FF48:/jffs/scripts# dos2unix /jffs/scripts/drive_check
admin@RT-AC66U-FF48:/jffs/scripts#

my scripts

drive_check
Code:
#!/bin/sh
# pre-mount script (to be installed in /jffs/scripts)
# auto-check filesystems during boot
# first argument is the filesystem to be mounted (e.g. /dev/sda1)

CHKLOG=/var/fsck.log

me=`basename "$0"`

# determine the type of filesystem being mounted
FSTYPE=`fdisk -l ${1:0:8} | grep $1 | cut -c55-65`

# determine the appropriate checker for the filesystem
case "$FSTYPE" in
        Linux )
                CHKCMD="e2fsck -p" ;;
        Win95* | FAT* )
                CHKCMD="fatfsck -a" ;;
        HPFS/NTFS )
                CHKCMD="ntfsck -a" ;;
        * )
                logger "$0:" "Unknown filesystem type $FSTYPE on $1 - no filesystem check run."
                exit 1 ;;
esac

logger "$0:" "Running '$CHKCMD $1' - see output at $CHKLOG"
echo -e "\nStarting '$CHKCMD $1' at `date`" >> $CHKLOG
$CHKCMD $1 >> $CHKLOG 2>&1

logger -t $me "Drive checker has finished"


pre-mount
Code:
#!/bin/sh
me=`basename "$0"`

logger -t $me "Loading Drive checker"
/jffs/scripts/drive_check $1
 
fatfsck doesn't exist in my firmware either. It seems to be tuxera specific.
OK, well my mistake/ignorance about the various router models supported by AsusWRT-Merlin. I have an RT-AC68U, and just assumed all the *fsck's were included on all models. Sorry about that!

Colin, is there some other flavor of fsck included on the 66 that will indeed check a FAT drive? Or does it require importing a disk-check tool (e.g. from Entware)? I figure there must be something there that the built-in USB "Health Scanner" (accessible from the WebGUI) uses, or is that not included on the 66 either?
 
The UI uses app_fsck.sh (script) I believe
Code:
Usage: app_fsck.sh [filesystem type] [device's path]
filesystem can be any of:
vfat
msdos
fuseblk
tfat
ntfs
tntfs
hfs
hfsplus
thfsplus
hfs+j
hfs+jx


EDIT:
Sorry I did not realize @ColinTaylor had already linked to that script in #15
 
Last edited:
Colin, is there some other flavor of fsck included on the 66 that will indeed check a FAT drive?
I have a 68U not a 66 ;), but I'm running John's fork which is based on a different codebase. fatfsck isn't included with that.

@redhat27 is correct about app_fsck.sh. If the filesystem type tfat it uses fatfsck, if it is vfat, msdos or fuseblk it doesn't do anything.
 
I have a 68U not a 66 ;), but I'm running John's fork which is based on a different codebase. fatfsck isn't included with that.

@redhat27 is correct about app_fsck.sh. If the filesystem type tfat it uses fatfsck, if it is vfat, msdos or fuseblk it doesn't do anything.
I'm still confused about this. app_fsck.sh calls 'fatfsck' for FAT filesystems, but that command (fatfsck) doesn't exist on a '66U' router? So you're just SOL if you're using a FAT32-formatted USB stick (the most common formatting you'll ever find on an off-the-shelf USB stick)?
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top