The scripts in this post will automatically find, check and repair as needed your unmounted ext2 and ext3 partitions.
Script: autofsck
Code: Select all
#!/bin/bash
main()
{
variables
partition_types
}
variables()
{
partitions=`fdisk -l | grep "83 Linux" | cut -d " " -f 1 | tr "\n" " "`
}
partition_types()
{
for i in $partitions ; do
guess_fstype $i | grep ext[23]>/dev/null
if [ x$? = x0 ] ; then
</proc/mounts grep $i>/dev/null
if [ x$? != x0 ] ; then
echo -en "\\033[1;36m""Checking $i"
echo -e "\\033[1;36m"
e2fsck -y $i
fi
fi
done
}
main
Code: Select all
## BEGIN AUTO EXT2|3 FSCK
partitions=`fdisk -l | grep "83 Linux" \
| cut -d " " -f 1 | tr "\n" " "`
for i in $partitions ; do
guess_fstype $i | grep ext[23]>/dev/null
if [ x$? = x0 ] ; then
</proc/mounts grep $i>/dev/null
if [ x$? != x0 ] ; then
echo -en "\\033[1;36m""Checking $i">/dev/console
echo -e "\\033[1;36m">/dev/console
e2fsck -y $i >/dev/console
fi
fi
done
## END AUTO EXT2|3 FSCK
- 1) find 83 Linux partitions
2) filter out the ext2 and ext3
3) see if they are unmounted
4) if so do a file system check
5) provide on screen feedback
Some people think it takes too long to check the file systems each boot. Some people think it is unnecessary. Some people never check anything at all.
With ext3 partitions it takes me about 1/2 second to do the filesystem check. Your ext2 and ext3 partitions keep count of days between full checks and number of mounts between full checks.
A full check is typically about every 26 mounts, the full check is time consuming, no doubt.
(If you are like me, you are the system administrator - that's how it is)
Between these two scripts, depending on which script you use, you have the ability to run them as you please, or each boot, or never at all.
If nothing else, please read the two scripts, they are almost identical, except in style. See what style you like the best, try and understand each line.
~
Chapter 63 - auto ext2|3 filesystem check and repair