From: pen@lysator.liu.se (Peter Eriksson) Subject: Re: How to put e2fsck before mounting harddrive in SLS? Date: 21 May 1993 15:31:48 GMT
sct@dcs.ed.ac.uk (Stephen Tweedie) writes:
>On 19 May 93 10:56:22 GMT, gwesp@cosy.sbg.ac.at (Gerhard Wesp) said:
>> This sounds like some chicken and egg problem to me...
>> How is it possible to run e2fsck *BEFORE* the file systems are mounted?
>> e2fsck lives on your root partition, doesn't it? So if the root partition
>> isn't mounted, how to access e2fsck? And if it is mounted, you shouldn't
>> run it! A little bit confusing...
>You get the kernel to mount root readonly, and run fsck before any
>other partitions are mounted. Then, if the fsck had to make any
>changes, you either drop out immediately to single-user mode, or do an
>immediate reboot. (You can't just continue to boot safely, because if
>fsck changed anything then the kernel's inode caches might disagree
>with the corrected filesystem.)
>If all went well, now you can remount root in read-write mode, and
>mount the rest of your partitions.
>The necessary kernel and application support for all of this is
>currently being worked on - it should be ready soon!
I have a modifed "mount" command that allows me to remount a
filesystem from read-only to read-write. It can be FTP'd from
"ftp.lysator.liu.se" in "pub/linux/lysator/lsd-mount/". It is based
on the "mount" sources as distributed with SLS 1.01.
This "mount" command understands a new command line option "-n" that
makes "mount" not try to write an entry in /etc/mtab (which it can't
do if the root filesystem is mounted read-only :-) and the new mount
option "remount".
From my /etc/rc file (this file needs more work but atleast it works
and it let's me check my filesystems in a nice way...):
> echo "Checking root filesystem..."
> /bin/e2fsck -a /dev/hda1
> if [ $? -ne 0 ]; then
> echo "Root filesystem modified. Rebooting..."
> /etc/reboot
> fi
>
> # We use the "-n" (no /etc/mtab) option so that we don't
> # try to write an entry in the read-only mount /etc/mtab...
> echo "Remounting / read-write..."
> /etc/mount -n -o remount,rw /dev/hda1 /
>
> # remove /etc/mtab* so mount creates the /etc/mtab file
> /bin/rm -f /etc/mtab*
>
> # Have to do this again so /etc/mtab gets updated...
> # We use the "-f" (fake) option to create a nice mtab entry.
> /etc/mount -f -o rw /dev/hda1 /
/Peter