14

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?

  • 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? – unforgettableid Mar 27 '17 at 7:06
  • This question is a near-duplicate of unix.stackexchange.com/questions/180488/… by the same user. – unforgettableid Mar 27 '17 at 7:08
16

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.

  • Will this handle the 'Run fsck manually' condition? – ethrbunny Apr 9 '14 at 17:58
  • Indeed, I read too fast, updated my answer. – finite graygreen Apr 9 '14 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 '14 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. – finite graygreen Apr 9 '14 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 '14 at 18:54
7

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)

  • 2
    Only a command is not enough in most cases, write at least a minimal explanation, too. – peterh Mar 3 '15 at 8:30
7

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.