How to run fsck during a shutdown sequence, or how to run one-time init scripts?
DebianThis forum is for the discussion of Debian Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.