View previous topic :: View next topic |
Author |
Message |
MalleRIM Guru
Joined: 23 Jul 2007 Posts: 563 Location: China
|
Posted: Tue Nov 13, 2007 6:37 pm Post subject: Check filesystems _after_ finishing boot (mount ro before)? |
|
|
Hi,
I have 750 GB of diskspace with partitions up to 200GB. I already set the number of mounts before a check to 50. But partitions of 100GB or more take ages to be checked. So I thought of a way to get this working differently, I'd like to have your advice to a good solution.
This is what I thought: Partitions which are to be checked are mounted ro on boot (except from any partition with system files like e.g. /, /home, /boot, /usr). After booting (or while booting) these partitions are checked and re-mounted when the check is successfully finished. A notify after logon which provides information about current checks would be useful but this will be the easiest part.
This would be my newbie solution to this problem: turn off the check of any partition which should not be checked on boot and mount it ro. A script looks for the number of mounts after last check, mounts the filesystems which don't have to be checked rw, then checks the filesystems that have been mounted x times and then mounts them rw.
I don't consider this a very professional solution. Is there a better way?
Malle |
|
Back to top |
|
|
neiljw Apprentice
Joined: 12 Nov 2007 Posts: 166 Location: Telford, UK
|
Posted: Tue Nov 13, 2007 8:06 pm Post subject: Re: Check filesystems _after_ finishing boot (mount ro befor |
|
|
MalleRIM wrote: | I don't consider this a very professional solution. Is there a better way?
Malle |
Yeh, don't keep re-booting. Why are you doing it? Given the frequency with which fsck needs to run, I don't see a couple of minutes as a big issue. _________________ Be lucky,
Neil |
|
Back to top |
|
|
Paapaa l33t
Joined: 14 Aug 2005 Posts: 955 Location: Finland
|
Posted: Tue Nov 13, 2007 8:14 pm Post subject: |
|
|
I also wonder why the FS check can't be interrupted/postponed during boot. It really annoys me when I have to have my box online quickly.
I got no answers at all:
https://forums.gentoo.org/viewtopic-t-579097.html _________________ Paludis, the way packages are meant to be managed. |
|
Back to top |
|
|
timeBandit Bodhisattva
Joined: 31 Dec 2004 Posts: 2719 Location: here, there or in transit
|
Posted: Tue Nov 13, 2007 8:59 pm Post subject: Re: Check filesystems _after_ finishing boot (mount ro befor |
|
|
MalleRIM wrote: | I don't consider this a very professional solution. Is there a better way? |
Which filesystem(s) did you use for the big partitions? This is the primary reason to use a journaled filesystem like JFS, XFS or ext3. Periodic checks of a relatively clean filesystem take seconds, not minutes.
If you used ext2, you can easily convert to ext3 by simply adding the journal, e.g., tune2fs -j /dev/sda3. _________________ Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others. |
|
Back to top |
|
|
MalleRIM Guru
Joined: 23 Jul 2007 Posts: 563 Location: China
|
Posted: Wed Nov 14, 2007 3:57 pm Post subject: Re: Check filesystems _after_ finishing boot (mount ro befor |
|
|
neiljw wrote: | Yeh, don't keep re-booting. Why are you doing it? Given the frequency with which fsck needs to run, I don't see a couple of minutes as a big issue. |
normally I boot my system once a day because it normally only runs 1-3 hours. For the answer to the second part im referring to Paapaa's post. Why wait if there is a better way?
@timeBandit: I am using ext3 for all of my partitions |
|
Back to top |
|
|
Section_8 l33t
Joined: 22 May 2004 Posts: 627
|
Posted: Wed Nov 14, 2007 4:42 pm Post subject: |
|
|
I have a home PC that boots (more or less) daily and have ext3 on most partitions. The partitions set up so they never do the forced fsck at bootup.
About once a month, I boot a liveCD and do a full system backup. From that backup script, I do the forced fsck of all my partitions. |
|
Back to top |
|
|
MalleRIM Guru
Joined: 23 Jul 2007 Posts: 563 Location: China
|
Posted: Tue Nov 20, 2007 9:04 pm Post subject: |
|
|
I think this is what I am going to do, but I need a little help because I'm not best at scripting.
I'm going to set the partitions I want to be checked after boot to not being checked. A script checks the number of mounts, and remounts the partitions to be checked ro, checks them and again, remounts them rw. This should be the best solution.
How can I check the number of mounts/time passed since last checking of a filesystem?
How can I remount a filesystem? |
|
Back to top |
|
|
Habbit Apprentice
Joined: 01 Sep 2007 Posts: 237 Location: 3.7137 W, 40.3873 N
|
Posted: Tue Nov 20, 2007 10:26 pm Post subject: |
|
|
MalleRIM wrote: | I think this is what I am going to do, but I need a little help because I'm not best at scripting.
I'm going to set the partitions I want to be checked after boot to not being checked. A script checks the number of mounts, and remounts the partitions to be checked ro, checks them and again, remounts them rw. This should be the best solution.
How can I check the number of mounts/time passed since last checking of a filesystem?
How can I remount a filesystem? |
Checking the number of mounts can be done by "tune2fs -l /dev/sdb7". I don't know of a similar tool for reiser/xfs/jfs/whatever.
Remounting: "mount /dev/sdb7 -o ro,remount" will remount the partition ro. Same goes for rw.
However, it would be best for you to set them as "ro" in your fstab and let the script remount them rw when it has checked them. It's quite a risk to mount an unclean FS rw. _________________
Code: | ~ $ objdump -d ./habbit_mind
90 xchg %rax, %rax
EB FD jmp $-3 |
|
|
Back to top |
|
|
MalleRIM Guru
Joined: 23 Jul 2007 Posts: 563 Location: China
|
Posted: Wed Nov 21, 2007 6:01 pm Post subject: |
|
|
Quote: | It's quite a risk to mount an unclean FS rw |
My script is just to get rid of the routine check during boot. I think I'll leave the check in the fstab and set the script to check the partitions five mounts/days before they have to be checked (in case the fs was remounted manually/not switched on for more than one day) after reaching number of mounts/days to be checked.
reiserfs/xfs/jfs won't be a problem - I'm only using ext3.
I'm not actually familiar with sed. I want to use grep to extract the line wich shows the mounts/days and then use sed to just have the number in a variable. Furthermore I need to know how to write "if $MOUNT_COUNT higher than '45'". I only know == and !=.
edit: I finally figured out, how to cut with sed. Is there a better way than using:
tune2fs -l /dev/sda5 | grep "Mount count" | sed s/"Mount count: "//
there are many spaces which is kind of bugging me... (spaces can't be displayed in the post)
it would also be nice to have a config file in which you can put all the filesystems you want to be checked this way including the number of mounts after which they should be checked. But I have actually no idea how to include a config file in a script. |
|
Back to top |
|
|
MalleRIM Guru
Joined: 23 Jul 2007 Posts: 563 Location: China
|
Posted: Thu Nov 22, 2007 11:00 pm Post subject: |
|
|
No suggestions? |
|
Back to top |
|
|
MalleRIM Guru
Joined: 23 Jul 2007 Posts: 563 Location: China
|
Posted: Mon Nov 26, 2007 8:36 pm Post subject: |
|
|
No idea at all? |
|
Back to top |
|
|
Habbit Apprentice
Joined: 01 Sep 2007 Posts: 237 Location: 3.7137 W, 40.3873 N
|
Posted: Mon Nov 26, 2007 10:33 pm Post subject: |
|
|
Yep, there is another, cleaner way: use awk. I don't remember the syntax from the last time I used it, but in your case it should be something along the lines of Code: | MOUNTS=$(tune2fs /dev/sdb5 -l | grep 'Mount count:' | awk -F: '{ print $3 }') # For the second ':' separated field
if [ "$MOUNTS" - gt 45 ]
then DO_WHATEVER
else DO_SOMETHING_ELSE
fi |
_________________
Code: | ~ $ objdump -d ./habbit_mind
90 xchg %rax, %rax
EB FD jmp $-3 |
|
|
Back to top |
|
|
neuron Advocate
Joined: 28 May 2002 Posts: 2371
|
Posted: Tue Nov 27, 2007 6:42 am Post subject: |
|
|
you might wanna look into suspend2 and hibernation instead of rebooting |
|
Back to top |
|
|
MalleRIM Guru
Joined: 23 Jul 2007 Posts: 563 Location: China
|
Posted: Tue Nov 27, 2007 9:40 pm Post subject: |
|
|
The spaces are not even saved in the variable - they are just displayed in the normal output. awk didn't work so I used sed again. |
|
Back to top |
|
|
Habbit Apprentice
Joined: 01 Sep 2007 Posts: 237 Location: 3.7137 W, 40.3873 N
|
Posted: Tue Nov 27, 2007 11:21 pm Post subject: |
|
|
Oops, sorry. Two errors in such a short snippet of code.
First: awk needs "print $2" instead of "print $3" because you want the part after ":", that is, the second colon-separated field. The spaces are ignored, you'll just get the right number (I've checked this time). The $3 was there because I was using space-separated fields before and then I thought about the colons.
Second: the "if" line must have "-gt", not "- gt". That space has no place there.
That should work, or at least it does in my system. _________________
Code: | ~ $ objdump -d ./habbit_mind
90 xchg %rax, %rax
EB FD jmp $-3 |
|
|
Back to top |
|
|
MalleRIM Guru
Joined: 23 Jul 2007 Posts: 563 Location: China
|
Posted: Wed Nov 28, 2007 4:13 pm Post subject: |
|
|
This is my first try:
Code: | FILESYSTEM=$@
COUNT=10
MOUNTS=`tune2fs -l ${FILESYSTEM} | grep "Mount count" | sed s/"Mount count: "//`
if [ "$MOUNTS" -gt ${COUNT} ]
then
echo "${FILESYSTEM} has been mounted more than ${COUNT} times, check forced"
mount -o ro,remount ${FILESYSTEM}
if [ "$?" != "0" ]
then
echo "${FILESYSTEM} can't be mounted ro. Terminate all processes writing ${FILESYSTEM} and try again"
exit
fi
fsck -fyc ${FILESYSTEM}
mount -o rw,remount ${FILESYSTEM}
echo "${FILESYSTEM} has been checked"
else
echo "${FILESYSTEM} does not have to be checked"
fi
exit 0 |
It still warns me about a mounted filesystem. can this be ignored? |
|
Back to top |
|
|
MalleRIM Guru
Joined: 23 Jul 2007 Posts: 563 Location: China
|
Posted: Mon Dec 03, 2007 7:25 pm Post subject: |
|
|
Does anyone know something about this? |
|
Back to top |
|
|
eccerr0r Watchman
Joined: 01 Jul 2004 Posts: 9824 Location: almost Mile High in the USA
|
Posted: Mon Dec 03, 2007 8:03 pm Post subject: |
|
|
my suggestion is that you don't bother mounting the partition till after you finish booting, then deal with fsck in local.start.
The reason why fsck is done at boot is that there's a potential for corruption specifically for the root partition, which is mitigated by rebooting the machine. If you fsck it a read-only mounted disk, the disk potentially could end up with changes from the write portion of fsck to clean up inconsistencies. Now the disk may be clean of inconsistencies but now your RAM cache could be inconsistent with the disk, and you could be hosed remounting that partition read-write.
Leave it unmounted, or unmount it totally before checking. _________________ Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching? |
|
Back to top |
|
|
MalleRIM Guru
Joined: 23 Jul 2007 Posts: 563 Location: China
|
Posted: Tue Dec 04, 2007 9:37 pm Post subject: |
|
|
ok, thanks for the answer
I'll try that when I got time. |
|
Back to top |
|
|
|