6

I have a backup script that mounts and unmounts a USB drive.
I just noticed that its warning me:

EXT3-fs warning: maximal mount count reached, running e2fsck is recommended

My question: How can I get it to run e2fsck automatically when the mount command is run?
This is how it looks in /etc/fsck

UUID=c870ccb3-e472-4a3e-8e82-65f4fdb73b38   /media/backup_disk_1  auto  defaults,rw,noauto  0 3

So <pass> is 3, so I was expecting fsck to be run when required.

EDIT

This is how I ended up doing it, based on the given answer:

(In a Bash script)

function fsck_disk {
  UUID=$1
  echo "Checking if we need to fsck $UUID"
  MCOUNT=`tune2fs -l "UUID=$UUID" 2> /dev/null | sed -n '/Mount count:\s\+/s///p'`
  if [ "$MCOUNT" -eq "$MCOUNT" ] 2> /dev/null
  then
    echo "Mount count = $MCOUNT"
    if (( $MCOUNT > 30 ))
    then
      echo "Time to fsck"
      fsck -a UUID=$UUID \
           1>> output.log \
           2>> error.log
    else
      echo "Not yet time to fsck"
    fi
  fi
}

fsck_disk a60b1234-c123-123e-b4d1-a4a111ab2222
2
  • 2
    You would want to run fsck before you mount the volume. You can do this in your backup script before mounting the volume.
    – Raza
    Oct 27, 2014 at 3:53
  • If you'd like I'l be substitute grep "Mount count" | cut -f2 -d':' | tr -d ' ' by sed -n '/Mount count:\s\+/s///p' to be short a little
    – Costas
    Oct 31, 2014 at 14:43

2 Answers 2

1

According to man fstab:

The sixth field (fs_passno). This field is used by the fsck(8) program to determine the order in which filesystem checks are done at reboot time. The root filesystem should be specified with a fs_passno of 1, and other filesystems should have a fs_passno of 2. Filesystems within a drive will be checked sequentially, but filesystems on different drives will be checked at the same time to utilize parallelism available in the hardware. If the sixth field is not present or zero, a value of zero is returned and fsck will assume that the filesystem does not need to be checked.

So 3 is void. Moreover the fstab influences just on boot time check not every time a device is mounted. So to check during the boot, change 6th field to 2. If your wants to make check every mount you can do it by simple script or even make alias (for example

alias bk_mount='fsck -a UUID=c870ccb3-e472-4a3e-8e82-65f4fdb73b38 && \
                mount /media/backup_disk_1'
5
  • Won't "fsck -a" always run a check? The goal is to only run a check when its past the max-count threshold. Or if there is some sort of issue.
    – user92979
    Oct 27, 2014 at 12:29
  • You can use the information from tune2fs -l to check the parameter you are want to use as signal to start fsck: Mount count or time from Last checked
    – Costas
    Oct 27, 2014 at 13:07
  • You must be running Ubuntu. They edited the man page to say that since they use Upstart rather than fsck -a at boot time. Historically the number was simply the order that fsck -a should fsck them in, so 3 was quite valid. Really the Ubuntu man page is misleading; upstart simply treats all values above 0 the same: it means it should be fscked, but there is no ordering.
    – psusi
    Oct 31, 2014 at 15:43
  • @psusi Thanks for remark. Whould you like to get some link to research the matter?
    – Costas
    Oct 31, 2014 at 15:50
  • Link? No... just the source code from Ubuntu's repositories.
    – psusi
    Oct 31, 2014 at 16:00
1

This warning is rather pointless so you can simply ignore it, or alternatively, you can get rid of it by using tune2fs -c 0 /dev/sdb. There is really no reason to fsck the filesystem after X mounts, especially with ext3/4. This is a holdover from when ext2 was new in the 90's and it was thought that it would just be "a good idea", "just in case".

3
  • Whatever the wisdom might be about the necessity or non-necessity of an fsck every N mounts, that's not what the question is about.
    – Celada
    Oct 31, 2014 at 15:53
  • 1
    @Celada, questions don't always ask exactly what the questioner needs to know; sometimes they need guided to the right answer that they didn't consider in their question because they didn't know it was a possibility.
    – psusi
    Oct 31, 2014 at 15:58
  • Your point is valid, and I appreciate it, however in this case: * I have seen FSCK required on ext3/4 in extreme corruption cases, and * This is for a external backup disk, so mount speed is not important, and I want to catch any corruption as early as possible (ie not when I'm trying to restore!)
    – user92979
    Nov 1, 2014 at 23:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .