How to auto-check filesystem at startup?

Using applications, configuring, problems
Post Reply
Message
Author
User avatar
SilverPuppy
Posts: 143
Joined: Fri 29 May 2009, 02:21

How to auto-check filesystem at startup?

#1 Post by SilverPuppy »

Hello,

I use full HD installation to create basic computers for elderly, etc. out of older computers. I have discovered that EXT2 is very fussy, and will really mess itself up if shutdown improperly, but even EXT3 can self-destruct if shutdown improperly enough times with no intervention.

SO.......rather than just booting to a bash shell after an improper shutdown, I need to have it behave like Windows 98 and do an fsck -f -y and then reboot itself. Upon reboot, I believe it will automatically go to the xwin "wait 30 seconds or select ignore" screen, which is fine.

Sooooooo.......I know the commands IIRC:

fsck -f -y /dev/hda1
reboot

..................but where do I put them so they get run after an improper shutdown instead of just dumping to a # prompt?

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#2 Post by mikeb »

at the top of /etc/rc.d/rc.sysinit before the remount r/w

you also need this otherwise you get a full check every boot...
http://www.murga-linux.com/puppy/viewtopic.php?t=45992

And check if this is included
http://www.murga-linux.com/puppy/viewtopic.php?t=36944

then relax :D

mike

User avatar
SilverPuppy
Posts: 143
Joined: Fri 29 May 2009, 02:21

Thanks!

#3 Post by SilverPuppy »

Wow, what a wealth of information. I'm going to have a much more dependable puppy that I send to keep old people company. That's good, because the elderly don't exactly enjoy cleaning up digital crap...... :D

And THIS is the beauty of OSS. Collectively, we can do so much more than M$ ever will. Just you wait, Bill! We're coming after your empire!

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#4 Post by mikeb »

Not as daunting as it sounds...just a few lines of script in the right places :) .

Actually the other reason for posting is that I'm not getting every notification from the forum ..

regards

mike

User avatar
SilverPuppy
Posts: 143
Joined: Fri 29 May 2009, 02:21

Ummm.....yoikes!

#5 Post by SilverPuppy »

Well, I have achieved partial success. I have reengineered the startup and shutdown scripts with the help of the OSS Community so that now it will detect and automatically recover from the most common improper shutdowns (turning power off without selecting power off on the menu.) I will link the files I modified later.

I have NOT however succeeded in getting fsck to run in the startup script. If I put it between loading kernel modules and swap activation, fsck says the partition is mounted. If I add a umount first it gripes that's not possible and then fsck still says it's mounted. If I put it before "making filesystem usable" fsck says that it can't access the device, probably because /dev hasn't been properly populated yet.

While it seems very solid the way I have it, and booting from a CD and fsck-ing the hard drive found no serious errors after about a dozen nasty shutoffs, I would feel better if cleanup was being done along the way after an unclean shutdown. I have heard that ext3 checks itself at mount, but fsck said it had been mounted 24 times without an fsck. I tried the /forcefsck trick, which did nothing.

I read something about Barry disabling automatic fsck to improve boot times. How can I selectively re-enable it without (for example) adding one-time options to grub's menu.lst boot line and then yanking them back out?

User avatar
SilverPuppy
Posts: 143
Joined: Fri 29 May 2009, 02:21

Files and such

#6 Post by SilverPuppy »

Here's the files I created (with help from you, of course....)

I strongly recommend using these or an improved version of these with EXT3 if you are using Puppy as a full install for a non-computer-person (such as an elderly person) as they greatly reduce the amount of fiddling required to clean up after things we wish they wouldn't do.......or power loss, etc.

This was very educational, to say the least. Maybe one day I'll upload an improved Puppy Package Manager that makes uninstall archives with the files which would have otherwise been overwritten and then puts them back upon uninstall. That project needs to be tackled, and it sounds like fun. I have a feeling someone more sage will beat me to it, though.......

[EDIT] One other thing I've learned in screwing around with this Puppy-----when fsck warns that fsck-ing a mounted partition is dangerous, they're NOT KIDDING! I've completely destroyed 2 or 3 installations that way. The first couple of times I thought that they must have been severely damaged anyway, and would have self-destructed sooner or later without my intervention. The third time it dawned on me......I'll bet something happened in the background that caused fsck to royally screw up the FS.....because it could, because it was mounted! So from now on, as much as it pains me to wait for a CD bootup, I'll be doing all future fsck-ing from a liveCD.

On an unrelated quirky note, "fsck-ing" just looks kinda......ummmmm........wrong??? :lol:

[EDIT AGAIN] I thought I should explain what these files do and what they're based on. This script is from the 4.1.2 RETRO kernel, so you might have to just find my insertions and put them in the appropriate places in your files. This version creates a flag file /tmp/RUNNING in the bootup process, then removes it during shutdown. If the file is PRESENT at bootup, then it knows that Puppy was not properly shut down, and performs a little file cleanup and reboots. This allows the services to all start correctly after the automatic reboot and X will also start with just the warning screen, rather than dumping to a bash prompt and waiting for startx. This version does NOT perform fsck on the hard drive; the version below does.
Attachments
rc.files.tar.gz
(18.23 KiB) Downloaded 567 times
Last edited by SilverPuppy on Sat 10 Oct 2009, 18:05, edited 1 time in total.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#7 Post by mikeb »

Oops my description was too vague....in puppy 2

Code: Select all

e2fsck -p /dev/hda3
echo -n "Making the filesystem usable..."
this works but for puppy 4 the check needed to be inserted between these two lines...

Code: Select all

busybox mount -t proc none /proc ;STATUS=$((STATUS+$?))
[ ! -d /initrd ] && busybox mount -o remount,rw,noatime /
but...I'm not 100% sure cos I'm not using it on my puppy4 install (ext3) but I did try it...I may also have moved

Code: Select all

rm -f /etc/mtab
ln -s /proc/mounts /etc/mtab
or

Code: Select all

busybox mount /dev/pts ;STATUS=$((STATUS+$?))
mkdir /sys 2>/dev/null
busybox mount -t sysfs none /sys ;STATUS=$((STATUS+$?))
earlier ....basically to make the partition device visable....as long as the check is whilst / is read only..it was a case of trial and error but definately done in rc.sysinit....teach me to keep notes.

The reason puppy does not fsck everytime is that with a frugal install there is no way (as far as I know) to unmount dev_save cos its in the union....so there would be a full check forced every boot. With a clean partition it only takes a fraction of a second.

mike

mike

User avatar
SilverPuppy
Posts: 143
Joined: Fri 29 May 2009, 02:21

Ah, victory!

#8 Post by SilverPuppy »

OK, then! Thanks to Mr. mikeb, I now have it exactly as I want it. I struggled briefly with creating a flag that rc.sysinit could see so early in the boot process, but putting it in / worked. Initially I tried to put it in /tmp to be tidy, as I did with RUNNING (I thought it looks messy in /) but it was not visible in /tmp at that point in the script. That's OK, as messy is not significant, since that flag only exists between the time of first phase cleanup and reboot to fsck and reload properly. The only way someone would ever see the flag file /fsckme would be to boot from a liveCD on the reboot and look at the hard drive. NOT something that most people will be doing. It'll be fine.

So.....here's the updated scripts. I really like these, and I highly recommend them for full HD installs. I see a few of you downloaded my original ones, but trust me, these are BETTER.

On a side note, I found a bug in PupZip........it added the one script to the file listing twice...... :roll:

[EDIT] Need to clarify again what this file is. This is the version that DOES perform fsck on the hard drive after an improper shutdown. Remember, this is from a RETRO kernel, so if you are using a newer one you will have to change the e2fsck line to reflect the correct nomenclature for your hard drive. Also, if your Puppy is not installed on the first partition, likewise, changing the nomenclature will be necessary. I don't see anything risky about what I've added; if you don't fix it right, it just won't work.
Attachments
fsck-rc.sysinit.tar.gz
(29.49 KiB) Downloaded 589 times
Last edited by SilverPuppy on Sat 10 Oct 2009, 18:12, edited 1 time in total.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#9 Post by mikeb »

On a side note, I found a bug in PupZip........it added the one script to the file listing twice......
it tends to do that if you open with more than one file/folder to create a new archive.

your flag could have a . in front of it to keep it hidden.

I assume my description from memory of the location of e2fsck is correct.?
Also just running fsck tries to check all partitions but then sometimes it does not...would be handy if it did

You might like to add a summary of this to the HOW TO section once you are fully happy with it..keeps it from being lost so easily.
mike

User avatar
SilverPuppy
Posts: 143
Joined: Fri 29 May 2009, 02:21

True.....

#10 Post by SilverPuppy »

I forgot about hidden files, so yes, that would be possible, but like I said, that flag file only exists during the reboot to finish the cleanup........so no end user (in my case) would ever see it anyway.

Yes, your memory was good. I added the creation of a flag file /fsckme after removing the temporary files but before the reboot, and added an if trigger that notices /fsckme and runs e2fsck on the hard drive if it exists. There's another if trigger deeper into the boot cycle that removes the /fsckme flag afterward. This if trigger is after the reboot in the initial cleanup if trigger, so it doesn't get removed if it is needed.

I wouldn't know how to add this to the HOWTO section, but maybe I can figure it out. Just this discussion in the forums will help a great deal. If I were looking to do this and someone else had had this discussion first, I'm sure I'd have found this, with tips and theoretically ready-to-implement files. (Although, I did just think of a few disclaimers I should put with my files above......)

Thinking about this now, I should state that it is theoretically possible to do this in one pass without a reboot, but I think with a reboot is best because that cleans up the files, flags for fsck, reboots, fscks, and then boots normally. I could move the RUNNING flag file back out of the /tmp folder and make the fsck if trigger look for that as well, which would eliminate the need for a reboot........but that wouldn't fix the fact that a reboot is still required after an improper shutdown to restore proper USB function, and I think something else as well, so rebooting is best. This automates the whole process of recovering from an improper shutdown, rather than leaving my non-computer-literate end-users wondering why their printer doesn't work anymore............rather than wasting their time and mine figuring out that they need to reboot again to finish the cleanup, it's best to just let Puppy take care of it.

Wow, a Puppy that does his own Poop-scoop Boogie! :lol:

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#11 Post by mikeb »

Nice one.....just post in the HOW TO section...title of what its for ,summerise its function, include files and instructions to implement. Another reason is that a post like this includes the learning bit that can be confusing to a user.

mike

Sylvander
Posts: 4416
Joined: Mon 15 Dec 2008, 11:06
Location: West Lothian, Scotland, UK

#12 Post by Sylvander »

Sorry, posted in error.

Is there a way to delete a post?

Post Reply