LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Force filesystem check after improper shutdown? (https://www.linuxquestions.org/questions/linux-general-1/force-filesystem-check-after-improper-shutdown-181164/)

Phaethar 05-13-2004 03:13 PM

Force filesystem check after improper shutdown?
 
Hey all,

I'm curious to know if there is a way to get Linux (Fedora for the most part) to check the filesystem by default after an improper shutdown. Normally, it will prompt the user to hit Y within 5 seconds of asking to do it. If Y isn't hit, it continues on booting normally. We have a lot of systems running unattended, and I'd like to find out if there is a way to force it to run that check if for whatever reason one of those systems goes down. Is there a way or an option I can enable to make this work?

Thanks.

TheOther1 05-13-2004 03:26 PM

I'm guessing you could add this to /etc/rc.d/rc file

Code:

touch /forcefsck
and on next boot it will be forced. Adding ot to /etc/rc.d/rc will create /forcefsck every time system boots but I'm not sure if you will still need to hit Y.

Phaethar 05-14-2004 10:45 AM

Thought I'd throw this out there as well... I think I've found the part of the rc.sysinit script that checks the FS on bootup and determines if the check needs to be run. Not being a programmer though, I don't know what I would need to change. I'm hoping someone can look at this and tell me how to get it to check by default.. it looks like the option is even in there. I just don't know how to get it. Here's the code I found:

Quote:

if [ -f /fsckoptions ]; then
fsckoptions=`cat /fsckoptions`
fi


if [ -f /forcefsck ] || strstr "$cmdline" forcefsck ; then
fsckoptions="-f $fsckoptions"
elif [ -f /.autofsck ]; then
if [ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --ping ; then
chvt 1
fi
echo $"Your system appears to have shut down uncleanly"
AUTOFSCK_TIMEOUT=5
[ -f /etc/sysconfig/autofsck ] && . /etc/sysconfig/autofsck
if [ "$AUTOFSCK_DEF_CHECK" = "yes" ]; then
AUTOFSCK_OPT=-f
fi

if [ "$PROMPT" != "no" ]; then
if [ "$AUTOFSCK_DEF_CHECK" = "yes" ]; then
if /sbin/getkey -c $AUTOFSCK_TIMEOUT -m $"Press N within %d seconds to not force file system integrity check..." n ; then
AUTOFSCK_OPT=
fi
else
if /sbin/getkey -c $AUTOFSCK_TIMEOUT -m $"Press Y within %d seconds to force file system integrity check..." y ; then

AUTOFSCK_OPT=-f
fi
fi
echo
else
# PROMPT not allowed
if [ "$AUTOFSCK_DEF_CHECK" = "yes" ]; then
echo $"Forcing file system integrity check due to default setting"
else
echo $"Not forcing file system integrity check due to default setting"
fi
fi
fsckoptions="$AUTOFSCK_OPT $fsckoptions"
fi

if [ "$BOOTUP" = "color" ]; then
fsckoptions="-C $fsckoptions"
else
fsckoptions="-V $fsckoptions"
fi
Hopefully someone can make some sense of that...

I apologize.. the formatting wasn't saved when I posted it.

gimbeault 07-21-2004 09:54 AM

Hi Phaethar,

this is what we did here in order to force the integrity scan.
We added the following line,(don't add the stars or arrows).

if [ -f /forcefsck ] || strstr "$cmdline" forcefsck ; then
fsckoptions="-f $fsckoptions"
elif [ -f /.autofsck ]; then
if [ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --ping ; then
chvt 1
fi
echo $"Your system appears to have shut down uncleanly"
AUTOFSCK_TIMEOUT=5
[ -f /etc/sysconfig/autofsck ] && . /etc/sysconfig/autofsck

AUTOFSCK_DEF_CHECK="yes" *****************<<<<<<

if [ "$AUTOFSCK_DEF_CHECK" = "yes" ]; then
AUTOFSCK_OPT=-f
fi

In a nutshell this pretty much tells the script that the input was yes.
We did this on Trustix 2.1 Horizon and it works flawlessly.

We tried the following which also seemed to work fine,but I'm not a fan of leaving things blank and not knowing for sure why it worked

Instead of adding the new line, I removed the yes from in between the quote marks. Just leave it blank.

if [ "$AUTOFSCK_DEF_CHECK" = " " ]; then ******<<<<<<<<

Hope these help.

Phaethar 07-21-2004 10:17 AM

Hi gimbeault,

Thanks a bunch for the tip, that's a nice and easy way to get it working, and it seems to be working great for Fedora as well now.

Thanks! :D

TheOther1 07-22-2004 10:03 AM

Here's a cleaner way to do it w/o modifying the rc.sysinit script:

Code:

echo "AUTOFSCK_TIMEOUT=5" > /etc/sysconfig/autofsck
echo "AUTOFSCK_DEF_CHECK=yes" >> /etc/sysconfig/autofsck

This will do the same but you aren't messing with system files... Also it's easy to incorporate into a kickstart script or distribute the autofsck file to many servers through a simple script.

HTH!

JWilliamCupp 04-23-2011 08:12 PM

Quote:

Originally Posted by TheOther1 (Post 931660)
I'm guessing you could add this to /etc/rc.d/rc file

Code:

touch /forcefsck
and on next boot it will be forced. Adding ot to /etc/rc.d/rc will create /forcefsck every time system boots but I'm not sure if you will still need to hit Y.

Thanks for this tip! It worked ...

Actually, I just entered
touch /forcefsck
from a console after I su'ed in as root, then rebooted.

It did a filesystem check on reboot, which I needed to do to clear an earlier problem.


All times are GMT -5. The time now is 03:58 PM.