LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (http://www.linuxquestions.org/questions/debian-26/)
-   -   How to run fsck during a shutdown sequence, or how to run one-time init scripts? (http://www.linuxquestions.org/questions/debian-26/how-to-run-fsck-during-a-shutdown-sequence-or-how-to-run-one-time-init-scripts-846926/)

bgoodr 11-27-2010 02:38 PM

How to run fsck during a shutdown sequence, or how to run one-time init scripts?
 
I want to be able to run fsck at, or near, shutdown at the end of the day, and not have to wait for it when booting (important now that I have 1TB drives!). As far as I can tell, the only way to arrange to run fsck on the root partition is if it is unmounted and I believe that only occurs at reboot time.

So, I thought of using the /forcefsck file that, when exists, will force file system check upon the next boot. So I envision having a script that touches that file, or issues the right shutdown command, then lets the system reboot and thus forcing a fsck of the root partition. However, I then want the system to turn right around and then shutdown, so that when I cold boot the system in the morning, I won't see the fsck run at that time, ever.

So I think this boils down to being able to run a one-time init script or something like that. Is there an established way or idiom for running an init script only one time? I know I can create a non-standard init-script that looks for a special file like is done for /forcefsck, and only shutdown if that file is seen, but surely someone else has already come up with a canned solution/init-script to what I want to do. ;)

bg

ilikejam 11-27-2010 05:57 PM

You could create an init script that moves itself then runs shutdown.

The question I suppose needs to be asked, though, is: why are you running fsck at all?

Dave

bgoodr 11-27-2010 07:36 PM

Quote:

Originally Posted by ilikejam (Post 4173023)
You could create an init script that moves itself then runs shutdown.

What I actually will probably do is just have a permanently executed script under init.d that executes at the right run level, and only really and truly shuts down if a special file exists, a file I would touch during this funky backup+reboot+fsck+shutdown sequence I am concocting.

I wonder if there is some more direct way to just fsck the root partition at shutdown, and then just directly shutdown, instead of the funky script approach above.

Quote:

Originally Posted by ilikejam (Post 4173023)
The question I suppose needs to be asked, though, is: why are you running fsck at all?

Actually, I haven't been running fsck manually at all. It is the system that periodically runs it for me, and during the boot sequence. I have always assumed it knew what it was doing, but now I know it will want to fsck all of these big fat data drives too, so I'm hoping to just have fsck run as a part of the shutdown process at the end of a workday, instead of having to wait for it in the mornings every X time the system is cold booted. E.g., Just run my script, and walk away from the computer (I also will be running an rsync backup to a spare drive in the system as a part of that process, so fsck'ing is not the only use here).

Are you implying that running fsck is wrong in this context?

Note that my root partition and data drives are all either ext3 or ext4 partitions.

bg

syg00 11-27-2010 08:05 PM

ext4 fsck should be quicker by nature (after the first one). Very full big drives would still be an issue.

ilikejam 11-27-2010 08:16 PM

If I were you, I'd probably just switch it off (despite the dire warnings in the tune2fs man page).

Set the 6th (last) field in /etc/fstab to 0 and the problem goes away.

Dave

bgoodr 11-28-2010 04:08 PM

Quote:

Originally Posted by ilikejam (Post 4173107)
If I were you, I'd probably just switch it off (despite the dire warnings in the tune2fs man page).

No disrespect, but I'd really rather not. Folks much smarter than myself put the fsck mechanism in place for a reason, and I don't want to go second-guessing them. :)

bg


All times are GMT -5. The time now is 04:02 AM.