Nelson's log

interactive fsck on Ubuntu

My headless server in Kansas didn’t reboot properly. The nice guys at the datacenter plugged in a console and found fsck waiting for them to press “Y”, which they did, and the system came back. Interactive fsck is pretty much always a terrible idea, particularly for a headless server, why was it waiting?

I can’t find good docs on this for Ubuntu. I’ve asked a question on StackExchange and started digging through code. I think the important setting is FSCKFIX /etc/default/rcS:

When the root and all other file systems are checked, fsck is invoked with the -a option which means “autorepair”. If there are major inconsistencies then the fsck process will bail out. The system will print a message asking the administrator to repair the file system manually and will present a root shell prompt (actually a sulogin prompt) on the console. Setting this option to yes causes the fsck commands to be run with the -y option instead of the -a option. This will tell fsck always to repair the file systems without asking for permission.

So Ubuntu already partially runs fsck in non-interactive mode; the -a flag (aka -p) “This option will cause e2fsck to automatically fix any filesystem problems that can be safely fixed without human intervention.” I guess something was wrong enough with the filesystem on reboot that -p was afraid to fix it. But in my case I don’t care; I have a backup, I need the server up under any circumstance, and I never knew how to answer fsck’s questions anyway.

I found this by reading through code. Ubuntu mounts filesystems via a program called mountall. Init invokes mountall and uses a shell script to set options. Here’s relevant bits of code:


[ "$FSCKFIX" = "yes" ] && fsck_fix="--fsck-fix"


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"));

So there we have it, I think setting FSCKFIX=yes in /etc/default/rcS is my solution. And I’m glad to see even with that not set Ubuntu mostly runs fsck non-interactively.