19

I have a headless Ubuntu 12.04 server in a datacenter 1500 miles away. Twice now on reboot the system decided it had to fsck. Unfortunately Ubuntu ran fsck in interactive mode, so I had to ask someone at my datacenter to go over, plug in a console, and press the Y key. How do I set it up so that fsck runs in non-interactive mode at boot time with the -y or -p (aka -a) flag?

If I understand Ubuntu's boot process correctly, init invokes mountall which in turn invokes fsck. However I don't see any way to configure how fsck is invoked. Is this possible?

(To head off one suggestion; I'm aware I can use tune2fs -i 0 -c 0 to prevent periodic fscks. That may help a little but I need the system to try to come back up even if it had a real reason to fsck, say after a power failure.)

In response to followup questions, here's the pertinent details of my /etc/fstab. I don't believe I've edited this at all from what Ubuntu put there.

UUID=3515461e-d425-4525-a07d-da986d2d7e04 /               ext4    errors=remount-ro 0       1
UUID=90908358-b147-42e2-8235-38c8119f15a6 /boot           ext4    defaults        0       2
UUID=01f67147-9117-4229-9b98-e97fa526bfc0 none            swap    sw              0       0
  • 1
    This question and its answers involving /etc/default/rcS are not really valid in 2019, with Ubuntu 16 and Ubuntu 18 now using systemd. I don't know the full story for systemd but the fsck.repair configuration / kernel command line option seems relevant. The docs currently say its default is preen, which means -p. It can also be set to yes for -y. /etc/default/grub may be the place to set this. I'd be grateful if someone more knowledgeable would provide a modern systemd answer. – Nelson Jan 22 '19 at 0:22
29

The setting I am looking for is in /etc/default/rcS, FSCKFIX=yes. This means "automatically repair filesystems with inconsistencies during boot" and causes fsck to run with the -y flag. It was set to no in both of my Ubuntu systems.

Even when set to no, the boot time fsck is still somewhat noninteractive. mountall runs fsck with -a, a synonym for -p, which means "automatically fix any filesystem problems that can be safely fixed without human intervention". Apparently -p drops to interactive mode if there are unsafe fixes to be made. To run fully automatically, you need -y or FSCKFIX=yes.

Here's the relevant bit of code from mountall.c

if (fsck_fix || mnt->fsck_fix) {
  NIH_MUST (nih_str_array_add (&args, NULL, &args_len, "-y"));
} else {
  NIH_MUST (nih_str_array_add (&args, NULL, &args_len, "-a"));
}
| improve this answer | |
  • For recent OSes with systemd the same can be achieved by adding fsck.repair=yes to param GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub – Maxxer Oct 9 '19 at 16:25
2

For Ubuntu 15,16,17+ the FSCKFIX value setting is located in lib/init/vars.sh

Can use command grep -r FSCKFIX * 2>/dev/null to fin it.

| improve this answer | |
  • 1
    Thanks! I'm not positive but the comments in that file suggest you should still configure the setting in /etc/default/rcS. /lib/init/vars.sh has a default for FSCKFIX but then sources /etc/default/rcS which can override it. OTOH a newly installed Ubuntu 18 system didn't have an rcS file at all. – Nelson Nov 18 '18 at 18:53
1

Make sure you don't have any flags that might cause this in fstab, and check your init scripts. (Try grep'ing your init scrips for 'fsck' to find where it's used) My system runs fsck non-interactive, so here is a copy of my fstab and part of my /etc/init/mountall script for you to compare

$ cat /etc/fstab
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
UUID=acbe3514-33a3-4170-b1be-df7b8460a49a /               ext4    errors=remount-ro 0       1
UUID=d361f696-7abc-11e1-9043-5711de71ade6 /home           ext4    defaults        0       2
UUID=213e032c-fce9-4e1b-9d64-0779f0db4208 none            swap    sw              0       0

Snippet from /etc/init/mountall

script
    . /etc/default/rcS
    [ -f /forcefsck ] && force_fsck="--force-fsck"
    [ "$FSCKFIX" = "yes" ] && fsck_fix="--fsck-fix"

    # set $LANG so that messages appearing in plymouth are translated
    if [ -r /etc/default/locale ]; then
        . /etc/default/locale
        export LANG LANGUAGE LC_MESSAGES LC_ALL
    fi

    exec mountall --daemon $force_fsck $fsck_fix
end script
| improve this answer | |
  • 1
    Thanks for the help. Could you please tell me what grep FSCKFIX /etc/default/rcS says on your system? – Nelson Jun 15 '12 at 1:40

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.