LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 11-27-2010, 01:38 PM   #1
bgoodr
Member
 
Registered: Dec 2006
Location: Oregon
Distribution: RHEL[567] x86_64, Ubuntu 17.10 x86_64
Posts: 221

Rep: Reputation: 36
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
 
Old 11-27-2010, 04:57 PM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
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
 
Old 11-27-2010, 06:36 PM   #3
bgoodr
Member
 
Registered: Dec 2006
Location: Oregon
Distribution: RHEL[567] x86_64, Ubuntu 17.10 x86_64
Posts: 221

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by ilikejam View Post
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 View Post
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
 
Old 11-27-2010, 07:05 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,120

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
ext4 fsck should be quicker by nature (after the first one). Very full big drives would still be an issue.
 
Old 11-27-2010, 07:16 PM   #5
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
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
 
Old 11-28-2010, 03:08 PM   #6
bgoodr
Member
 
Registered: Dec 2006
Location: Oregon
Distribution: RHEL[567] x86_64, Ubuntu 17.10 x86_64
Posts: 221

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by ilikejam View Post
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
 
  


Reply

Tags
fsck init shutdown



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting an /etc/init.d script to run at system shutdown forrie Linux - Server 6 05-05-2010 01:19 PM
init script does not run at the shutdown time procfs Linux - Newbie 4 02-16-2010 02:00 AM
Is a script, run at boot time from init.d, run with root authority? tmbrwolf53 Linux - Server 2 03-31-2007 08:15 PM
Want to run a few scripts before KDE shutdown, where can I add them. Brian1 Linux - Software 6 06-16-2004 06:36 PM
How do i make scripts run at bootup and shutdown? BajaNick Linux - General 2 08-11-2003 08:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 05:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration