19

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
  • 1
    A) Who were your users? B) Could you have added a prominent "Shut Down" button which was always visible onscreen? C) Alternatively, could you have educated your users? D) Why did the machines not have power buttons on the front? Commented Mar 27, 2017 at 7:06
  • This question is a near-duplicate of unix.stackexchange.com/questions/180488/… by the same user. Commented Mar 27, 2017 at 7:08

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? Commented Apr 9, 2014 at 17:58
  • Indeed, I read too fast, updated my answer. Commented 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. Commented 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. Commented 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. Commented Apr 9, 2014 at 18:54
12

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

2
  • ~~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 ... Commented Oct 18, 2022 at 3:37
  • For what it is worth, I have just experienced a situation when there was a corrupted root filesystem. I had both fsck.mode=force and fsck.repair=yes kernel boot options enabled. And yet, the boot process was stopped because of bad fsck result. And the user was dropped into a maintenance shell where fsck had to be run manually. So, either I am missing something or this method does not seem to work reliably in all scenarios. Commented Nov 17, 2024 at 18:51
9

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. Commented 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. Commented Jun 14, 2020 at 22:49
  • Does this also fixes any issues without user input? like with -y ? Commented May 18, 2022 at 8:42

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.