Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto-respond to fsck prompt at boot

I have an ubuntu server (11.10) on a single-board computer that occasionally is subject to being powered down unexpectedly. When it is booted afterward, fsck prompts the user to hit 'f' to check the drive. Because this server does not normally have a monitor and keyboard connected, and the only way to normally access it is through SSH, this is very inconvenient.

Is there a way of guaranteeing that on boot any required fsck check can be done without user input? Basically, I want it to always run 'fsck -y' on boot (when problems are detected), rather than prompting the user for input.

Thanks!

like image 271
Nato Saichek Avatar asked Mar 29 '12 19:03

Nato Saichek


People also ask

What is fsck command?

The fsck command attempts to check the root file system before any other file system regardless of the order specified on the command line or in the /etc/filesystems file. The fsck command checks for the following inconsistencies: Blocks or fragments allocated to multiple files.

Can we run fsck on mounted file system?

To make sure you do not try to run fsck on a mounted filesystem, add the -M option. This flag tells the fsck tool to skip any mounted filesystems. To show you the difference, we will run fsck on sdb while it is mounted, and then when we unmount it. While sdb is mounted, the tool exits without running a check.

Can we run fsck on root partition?

To run fsck in recovery mode: Enter the boot menu and choose Advanced Options. Select the Recovery mode and then “fsck”. When prompted to remount the root file system choose “Yes”.


2 Answers

Senthil answer about RECORFAIL TIMETOUT directive is related to Grub bootloader and occurs after a "failed boot attempt" as stated here. Despite being related to the question, and one point to be observed on forced reboots, it's not the answer to the fsck problem ("always run 'fsck -y'").

I believe Nato Saichek answer is on the right way. This link aproaches the problem of forcing fsck in Ubuntu and RHEL/CentOS. In the case of Ubuntu, the scripts get some options from /etc/default/rcS. So I believe uncommenting and changing the default #FSCKFIX=no to FSCKFIX=yes would be sufficient.

like image 99
Frock81 Avatar answered Sep 20 '22 13:09

Frock81


So I found two related solutions to my problem:

I'm not sure these are valid everywhere, but they work on ubuntu server 11.10.

/etc/default/rcS looks like this:

#
# /etc/default/rcS
#
# Default settings for the scripts in /etc/rcS.d/
#
# For information about these variables see the rcS(5) manual page.
#
# This file belongs to the "initscripts" package.

# delete files in /tmp during boot older than x days.
# '0' means always, -1 or 'infinite' disables the feature
TMPTIME=0

# spawn sulogin during boot, continue normal boot if not used in 30 seconds
SULOGIN=no

# do not allow users to log in until the boot has completed
DELAYLOGIN=no

# assume that the BIOS clock is set to UTC time (recommended)
UTC=yes

# be more verbose during the boot process
VERBOSE=no

# automatically repair filesystems with inconsistencies during boot
FSCKFIX=no

Make sure that that final line instead reads

# automatically repair filesystems with inconsistencies during boot
FSCKFIX=yes

Another barrier I had to the system just booting always without requiring user intervention was the grub bootloader screen waiting for user input after a failed / interrupted boot.

This requires editing the grub setup file in /etc/grub.d/00_header

/etc/grub.d$ grep -r -n -C3 timeout ./
./00_header-229-    fi
./00_header-230-fi
./00_header-231-
./00_header:232:make_timeout ()
./00_header-233-{
./00_header-234-    cat << EOF
./00_header-235-if [ "\${recordfail}" = 1 ]; then
./00_header:236:  set timeout=-1
./00_header-237-else
./00_header:238:  set timeout=${2}
./00_header-239-fi
./00_header-240-EOF
./00_header-241-}

simply change line 236 to

set timeout = 0

and line 238 to

set timeout = 0

This causes the system to never pause while booting. After editing the file, run sudo update-grub to get the changes implemented in the /boot/grub/grub.cfg file.

like image 36
Nato Saichek Avatar answered Sep 18 '22 13:09

Nato Saichek