17

I'm working with a fanless PC (hundreds of them, in fact) that has debian 6 and 3 partitions( FAT and 2x ext2). The system doesn't have a power button as such so most people tend to yank the plug to 'shut it down' rather than init 0 (or equivalent). As a result the filesystem(s) build up errors pretty rapidly.

I've tried using 'shutdown -rF' to force fsck but this doesn't seem to be working. I'm wondering if there is some way to tell the system to check each mount point / FS before they are mounted.

I've tried setting the fsck param in /etc/fstab. This typically gives me a 'Errors found. Run fsck manually' message.

Are there other options to try?

2

3 Answers 3

17

In /etc/init.d/checkfs.sh is the line if [ -f /forcefsck ] || grep -s -w -i "forcefsck" /proc/cmdline, so providing forcefsck on the kernel command line or generating a /forcefsck file on shutdown should cause an fsck on the next reboot.

To prevent manual fsck runs, ask fsck to try to automatically fix errors with the -y option by uncommenting and changing no to yes in the following /etc/default/rcS entry, after the edit it should look like:

# automatically repair filesystems with inconsistencies during boot
FSCKFIX=yes

One option (forcefsck or FSCKFIX) does not imply the other.

7
  • Will this handle the 'Run fsck manually' condition?
    – ethrbunny
    Apr 9, 2014 at 17:58
  • Indeed, I read too fast, updated my answer. Apr 9, 2014 at 18:11
  • I have set both FSCKFIX=yes and the value in checkfs.sh. In neither case did fsck run when I rebooted (via init 6). I must be missing something here.
    – ethrbunny
    Apr 9, 2014 at 18:34
  • Don't change anything in checkfs.sh, only edit /etc/defaults/rcS and run touch /forcefsck before reboot. The last command needs to be run before every restart or just after you booted but the fsck init script is done. Apr 9, 2014 at 18:42
  • Hmm.. no luck. I still see the 'mounting unchecked filesystem' message followed by lots of 'delete inode referenced' errors. So far changing /etc/fstab has been the only thing has had any effect. Not sure what I'm doing such that your suggestions aren't working.
    – ethrbunny
    Apr 9, 2014 at 18:54
10

Add the fsck.mode=force Kernel parameter on your bootloader. Append this option to the GRUB_CMDLINE_LINUX_DEFAULT= variable inside /etc/default/grub. As root, generate a new grub configuration file:

[root@host]# grub-mkconfig -o /boot/grub/grub.cfg

This parameter have the same effect as creating the forcefsck file inside the root of the mount point.

The solution of using the checkfs.sh script will better fit on Debian, but should not work on other distros

1
  • ~~Instead of changing every entry, there should be a GRUB entry for this like the Advanced/Recover mode entry. ~~ I take back what I say, hack, grub entries are useless in headless mode ...
    – Ben
    Oct 18, 2022 at 3:37
8

I am editing my answer:

The command is:

sudo tune2fs -c 1 /dev/sdX

according to manpages -c argument for tune2fs counts number of instances of mounts for a partition. Hence, 1 forces to check the fs after every mounting instance.

(http://man7.org/linux/man-pages/man8/tune2fs.8.html)

3
  • 2
    Only a command is not enough in most cases, write at least a minimal explanation, too.
    – peterh
    Mar 3, 2015 at 8:30
  • This is what I was looking for, since I have to fix my corrupted fylesystem (Ubuntu 16 LTS) very often. I put a new Kingston SSD one year ago, so I don't know exactly why this issue is so recurrent.
    – Jose4Linux
    Jun 14, 2020 at 22:49
  • Does this also fixes any issues without user input? like with -y ?
    – Freedo
    May 18, 2022 at 8:42

You must log in to answer this question.

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