/etc/fsokay, /etc/rc, and a cleaner bootup-procedure on the UNIX PC/3B1
Lenny Tropiano
lenny at icus.islp.ny.us
Sun Jun 4 14:15:57 AEST 1989
After extracting everything read the README file ...
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of shell archive."
# Contents: README Makefile fsokay.c autoreboot inittab.add
# profile.add rc syskill sysreboot umountall
# Wrapped by lenny at icus on Sun Jun 4 00:14:20 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f README -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"README\"
else
echo shar: Extracting \"README\" \(5610 characters\)
sed "s/^X//" >README <<'END_OF_README'
XREAD THIS COMPLETELY AND PROCEED WITH CAUTION!
X
XHere's something I've wanted to do for quite some time. Basically there
Xwas a discussion on the net about fsck trashing your filesystems, multiple
Xreboots (when you don't think it is really necessary), etc, etc, etc...
X
XThis was a combination project ... Gil did most of the work on cleaning up
Xthe "rc" script (with a few modifications to his by myself) and I wrote the
X/etc/fsokay program (and associated other hooks into other system scripts).
X
XYou should feel confident about modifying system scripts, startup
Xprocedures, answering fsck questions, and editting /etc/inittab before
Xeven attempting this. (yes, you can edit /etc/inittab carefully).
X
XThis set of utilities will give you a couple of things, first it will give you
Xmore reliability during boot-up and fsck'ing the filesystems. It will not
Xfsck filesystems unless the system crashed (or was shutdown abnormally). It
Xwill give you the control of answering the fsck questions (not using the -y
Xswitch and possibly blowing away something that shouldn't be ...) You will
Xbe able to see the fsck working, doing something, not just saying:
X
X "Stored files are now being checked ..."
X -and-
X "Some stored files were damaged. The damage will be repaired,
X and the stored files will be checked again."
X -and-
X "Serious hard disk damage detected. Please refer to your Installation
X Guide and install the system from the floppy disk set provided."
X
Xin a window ... The fsck process is done before the window driver is loaded
Xand before any possible writes to the disk. The output to fsck isn't written to
X/etc/.lastfsck (possibly causing more damage), but written to the /dev/console
Xwhere you can see it! A possible disadvantage for some will be that the
X"-y" option removed from fsck requires you to answer any possible disk errors
Xduring fsck, therefore requiring operator intervention, and not able to
Xdo automatic reboot if there are errors. Of course some will argue that
Xfsck -y will fix 99% of the problems without any damage to your files,
Xbut the 1% that it doesn't you'll be happy you had control over it.
X
XI wrote /etc/fsokay after trying to think about a work-around for no
Xstate value within the filesystem structure (like what the /etc/fsstat program
Xon the AT&T 3B2 does). Basically what I devised is that when you perform
Xa shutdown (through the /etc/shutdown script), it does an "init s", the "s"
Xrun-level is caught by the /etc/profile which is run automatically. I then
Xafter the appropriate amount of "sync'ing" I truncate the /etc/mnttab
X(ie. "> /etc/mnttab") On my system I call a script called "/etc/umountall"
Xwhich umount's all the filesystems (other than / "root"). "/" cannot be
Xumount'd, so I just *assume* everything is quiet, and truncate the file.
X
XHere is my /etc/mnttab, and why I have to umount all the other filesystems
Xfirst ...
X
X/archives on /dev/fp013 read/write on Fri Jun 2 02:17:19 1989
X/netnews on /dev/fp012 read/write on Fri Jun 2 02:17:19 1989
X/tmp on /dev/fp011 read/write on Fri Jun 2 02:17:19 1989
X/ on /dev/fp002 read/write on Fri Jun 2 02:17:19 1989
X
XMost of you won't need to worry about multiple partitions ... It's just
Xthere commented out if you need it.
X
XWhen the system is booted, the rc script calls /etc/fsokay which checks
Xthe contents of /etc/mnttab. Anything left in there will be assumed
Xmounted when the system crashed or was shutdown abnormally, and will
Xbe checked. If nothing is found in /etc/mnttab, then everything was OK,
Xno filesystems need to be checked, and the system can boot without doing
XANY fsck'ing.
X
XUsage: /etc/fsokay [-s] [-v]
X
X-s: will salvage the free list on any filesystem OTHER than "/"
X See "-s" option of fsck(1M)
X
X-v: verbose option, will print out the message before calling fsck:
X
X <filesystem> : Last mounted on <device> (<how>) at <time>,
X Needs checking ...
X
X Where <filesystem> is the filesystem name,
X <device> is /dev/fp0XX, and <how> is read/write or read only,
X and <time> is obvious.
X
XAlso included for your *enjoyment* is an addition I made to my inittab
Xfile to allow run-level 6, which is automatic reboot. It calls two scripts,
X/etc/syskill which will kill all the processes, and /etc/sysreboot which
Xwill call /etc/reboot.
X
X/etc/autoreboot can be called from /usr/lib/crontab like:
X
X45 1 * * 1 /bin/su root -c "/etc/autoreboot"
X
XSo you can reboot your machine once a week (or more often) automatically.
X
XNow how do I get this all working???
XWell ... you SHOULD save copies of:
X
Xcd /etc
Xcp inittab inittab.orig
Xcp profile profile.orig
Xcp rc rc.orig
X
XThen you add the lines from profile.add to /etc/profile,
Xinittab.add to /etc/inittab, and copy the rc over the /etc/rc file.
X
Xcp syskill sysreboot autoreboot umountall /etc
Xmake install
X
Xchown root /etc/syskill /etc/sysreboot /etc/autoreboot /etc/umountall
Xchgrp sys /etc/syskill /etc/sysreboot /etc/autoreboot /etc/umountall
Xchmod 750 /etc/syskill /etc/sysreboot /etc/autoreboot /etc/umountall
X
XCross your fingers .. (it's a prerequisite for anything to work) ...
X
XNow shut down your system and see if to comes up!! If it doesn't for
Xany reason you should boot your Floppy UNIX and repair the damage by putting
Xthe *.orig files back.
X
XIF YOU DON'T KNOW HOW TO DO THIS, YOU PROBABLY SHOULDN'T BE MESSING WITH
XTHIS AT ALL!!!
X
XDISCLAIMER: I TAKE NO RESPONSIBILITY FOR ANY CONSEQUENCES THESE PROCEDURES
X MIGHT CAUSE. YOU SHOULD HAVE A GOOD KNOWLEDGE OF HOW THINGS
X OPERATE ON THE UNIX PC BEFORE STARTING, AS WELL AS ENOUGH
X KNOWLEDGE TO REPAIR THINGS IF SOMETHING GOES WRONG!
X
X
END_OF_README
if test 5610 -ne `wc -c <README`; then
echo shar: \"README\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f Makefile -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(608 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
X#
X# Makefile to compile fsokay.c (Determine if filesystem is in OKAY state)
X# By Lenny Tropiano
X# (c)1989 ICUS Software Systems UUCP: ...icus!lenny (lenny at icus.islp.ny.us)
X# All rights reserved
X#
XCFLAGS=-v -O
XLDFLAGS=-s
XLIBS=/lib/crt0s.o /lib/shlib.ifile
XDEST=/etc/
X#
Xfsokay: fsokay.o
X @echo "Loading ..."
X $(LD) $(LDFLAGS) -o fsokay fsokay.o $(LIBS)
X#
Xfsokay.o:
X $(CC) $(CFLAGS) -c fsokay.c
X#
X# You need to be super-user to do this.
X#
X$(DEST):
X mkdir $(DEST)
X chmod 755 $(DEST)
X#
Xinstall: fsokay $(DEST)
X cp fsokay $(DEST)
X chown bin $(DEST)/fsokay
X chgrp bin $(DEST)/fsokay
X chmod 750 $(DEST)/fsokay
END_OF_Makefile
if test 608 -ne `wc -c <Makefile`; then
echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f fsokay.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"fsokay.c\"
else
echo shar: Extracting \"fsokay.c\" \(4844 characters\)
sed "s/^X//" >fsokay.c <<'END_OF_fsokay.c'
X/************************************************************************\
X** **
X** Program name: fsokay.c (Determine if filesystem is in OKAY state) **
X** Programmer: Lenny Tropiano UUCP: ...icus!lenny **
X** Organization: ICUS Software Systems (c)1989 All rights reserved **
X** Date: June 3, 1989 **
X** **
X**************************************************************************
X** **
X** Program use: Program is run as information apon login called from **
X** the /etc/rc on bootup. This program should replace **
X** the calls to /etc/fsck, because /etc/fsokay will check **
X** to see if the system was "properly" shutdown the last **
X** time. Since the mount[] structure doesn't have the **
X** idea of the s_state, of being FsOKAY or not, we'll **
X** assume if there is any filesystems left in /etc/mnttab **
X** that the system crashed. Therefore the last thing you **
X** should do in /etc/shutdown is to "truncate" **
X** /etc/mnttab (by "> /etc/mnttab") **
X** **
X**************************************************************************
X** **
X** Credits: Thanks to Gil Kloepfer, Jr. (gil at limbic) for adding to **
X** my ideas in making this with his own ideas. Also thanks to those **
X** on the "net" who started the whole "fsck" discussion (by now which **
X** I'm very tired of reading). And to David Klann's (heurikon!dklann) **
X** net article in comp.sys.att (Message-ID: <331 at heurikon.UUCP>) **
X** because he was thinking about this too ... **
X** **
X**************************************************************************
X** Permission granted to redistribute without profit in the public **
X** domain only. This header must remain in-tact as is. This program **
X** carries no warranties, express or implied, and all consequences **
X** resulting from the use of this program are the sole responsibility **
X** of the user. **
X\************************************************************************/
X
X#include <stdio.h>
X#include <fcntl.h>
X#include <errno.h>
X#include <sys/types.h>
X#include <mnttab.h>
X#include <time.h>
X
X#define MNTTAB "/etc/mnttab"
X#define FSCK_PATH "/etc/fsck"
X
Xchar *progname; /* program name */
Xchar salvage_flg[3];
Xint verbose = 0;
X
X/************************************************************************/
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X int c;
X extern int optind;
X extern char *optarg;
X
X progname = *argv;
X
X salvage_flg[0] = '\0';
X
X while ((c = getopt(argc, argv, "?vs")) != EOF) {
X switch (c) {
X case 'v':
X verbose = 1;
X break;
X case 's':
X strcpy(salvage_flg,"-s");
X break;
X case '?':
X fprintf(stderr,
X "Usage: %s [-v] [-s]\n", progname);
X exit(1);
X break;
X }
X } /* end while */
X
X exit(filestatus()); /* let's see if our filesystems are *sane* */
X
X}
X
Xfilestatus()
X{
X int mntfd, all_errors;
X struct mnttab mtable;
X char *ctime();
X char fsck_cmd[30];
X
X if ((mntfd = open(MNTTAB, O_RDONLY)) == -1) {
X fprintf(stderr,"%s: cannot open %s for read\n",
X progname, MNTTAB);
X return 1;
X }
X
X /* move to EOF, and read mnttab backwards ... */
X
X if (lseek(mntfd, sizeof(struct mnttab) * -1, 2) == -1)
X return 0; /* nothing in file, therefore everything is OKAY */
X
X all_errors = 0;
X do {
X
X if (read(mntfd, &mtable, sizeof(struct mnttab)) <
X sizeof(struct mnttab))
X break; /* no more filesystems here ... */
X
X if (mtable.mt_dev[0] == '\0')
X continue; /* filesystem was umount'd correctly */
X
X if (verbose) {
X printf("\n%-10.10s: Last mounted on %s (%s) at %s",
X mtable.mt_filsys, mtable.mt_dev,
X ((mtable.mt_ro_flg) ? "read only " : "read/write"),
X ctime(&mtable.mt_time));
X printf(" Needs checking ...\n");
X }
X
X if (strcmp(mtable.mt_filsys,"/") != 0)
X sprintf(fsck_cmd,"%s %s /dev/r%s", FSCK_PATH, salvage_flg,
X mtable.mt_dev);
X else
X sprintf(fsck_cmd,"%s /dev/%s", FSCK_PATH, mtable.mt_dev);
X
X all_errors += system(fsck_cmd);
X /* keep taking checking all errors */
X
X } while (lseek(mntfd, sizeof(struct mnttab) * -2, 1) != -1);
X
X close(mntfd);
X
X return all_errors;
X
X}
END_OF_fsokay.c
if test 4844 -ne `wc -c <fsokay.c`; then
echo shar: \"fsokay.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f autoreboot -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"autoreboot\"
else
echo shar: Extracting \"autoreboot\" \(684 characters\)
sed "s/^X//" >autoreboot <<'END_OF_autoreboot'
XTTY=`tty`
Xif [ \( "`expr $TTY : '/dev/w' `" = "0" -a \
X "`expr $TTY : '/dev/sys' `" = "0" -a \
X "`expr $TTY : '/dev/con' `" = "0" \) ]
Xthen
X echo "Reboot must be run from the console"
X exit 1
Xfi
X
Xprocs=`ps -e | grep 'uusched
Xuucico
Xuuxqt
Xrnews
Xexpire' | wc -l`
X
Xusers=`/bin/who | wc -l`
X
Xwhile [ $procs -ne 0 -a $users -le 1 ]
Xdo
X echo "Auto-Reboot suspended at `date`: jobs still running." >> /usr/adm/autoboot.log
X sleep 45
X procs=`ps -e | grep '
Xuusched
Xuucico
Xuuxqt
Xrnews
Xexpire' | wc -l`
X
X users=`/bin/who | wc -l`
Xdone
X
Xecho "\n\n\nSystem is running auto-reboot procedure." > /dev/console &
Xecho "Auto-Reboot started at `date`." >> /usr/adm/autoboot.log
X#/etc/init 6
END_OF_autoreboot
if test 684 -ne `wc -c <autoreboot`; then
echo shar: \"autoreboot\" unpacked with wrong size!
fi
chmod +x autoreboot
# end of overwriting check
fi
if test -f inittab.add -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"inittab.add\"
else
echo shar: Extracting \"inittab.add\" \(115 characters\)
sed "s/^X//" >inittab.add <<'END_OF_inittab.add'
Xsk:6:wait:/etc/syskill >/dev/console 2>&1 < /dev/console
Xrb:6:wait:/etc/sysreboot >/dev/console 2>&1 </dev/console
END_OF_inittab.add
if test 115 -ne `wc -c <inittab.add`; then
echo shar: \"inittab.add\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f profile.add -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"profile.add\"
else
echo shar: Extracting \"profile.add\" \(631 characters\)
sed "s/^X//" >profile.add <<'END_OF_profile.add'
X#sccs "@(#)fndetc:profile 1.7"
X
X#
X# FILE: /etc/profile
X# Initialization script for all logins.
X#
X
Xtrap '' 1 2 3
X
Xset `who -r`
Xif [ "$3" = "S" ]
Xthen
X
X ## Any shutdown procedures (such as slancard reset) can be
X ## put in /etc/shutdaemon, and will be executed without
X ## changing /etc/profile.
X
X if [ -d /etc/shutdaemon ]
X then
X for i in /etc/shutdaemon/*
X do
X if [ -x $i ] ; then $i ; fi
X done
X fi
X
X sync;sync;sync
X /etc/killall
X
X sync;sync;sync # add this line
X /etc/umountall # add this line
X
X sync;sync;sync
X echo "\n\nReady to power off or reset the machine.\nPress RETURN to reboot."
X read inputline
X reboot
Xfi
END_OF_profile.add
if test 631 -ne `wc -c <profile.add`; then
echo shar: \"profile.add\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f rc -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"rc\"
else
echo shar: Extracting \"rc\" \(3421 characters\)
sed "s/^X//" >rc <<'END_OF_rc'
X#
X# System startup script (rc) for site icus - Last modified 4/30/89
X# Developed by Gil Kloepfer, Jr. (gil at limbic)
X# Modified by Lenny Tropiano (lenny at icus.islp.ny.us)
X#
X
Xtrap "" 2
X
X# If this is the first time the system is started, start phase I
X
Xif [ -z "$1" ]
Xthen
X date -
X exec /bin/sh /etc/rc PHASE1 </dev/console >/dev/console 2>&1
Xfi
X
X# Phase I -- File system check and window driver installation
X
Xif [ "$1" = "PHASE1" ]
Xthen
X echo "\nBooting UNIX system ..."
X
X /etc/fsokay -v -s ||
X ( echo "The file system check failed."
X echo "Please check the filesystem using standalone UNIX"
X echo "Press RETURN key to reboot"
X read junk
X /etc/reboot )
X
X sync;sync
X
X # Uncomment these lines and change for appropriate multiple filesystems
X # if you have them
X
X## echo "\nMounting filesystems ..."
X
X## echo "/etc/mount /dev/fp011 /tmp"
X## /etc/mount /dev/fp011 /tmp
X
X## echo "/etc/mount /dev/fp012 /netnews"
X## /etc/mount /dev/fp012 /netnews
X
X## echo "/etc/mount /dev/fp013 /archives"
X## /etc/mount /dev/fp013 /archives
X
X## sync;sync
X
X## echo "\nRebuilding mount table ..."
X
X # Set up mount table
X## /etc/devnm /archives /netnews /tmp / | /etc/setmnt
X
X## sync;sync
X
X# Fix the links on syscon and systty in case they broke
X
X rm -f /dev/syscon /dev/systty
X ln /dev/window /dev/syscon
X ln /dev/window /dev/systty
X
X# Install the window driver
X
X echo "\nLoading the window driver ..."
X cd /etc/lddrv
X ./mkifile /unix unix.syma
X cmp -s unix.sym unix.syma 2>/dev/null
X if [ $? != 0 ]
X then
X mv unix.syma unix.sym 2>/dev/null
X rm -f wind 2>/dev/null
X fi
X sync
X > /etc/drvtab
X sync
X if [ ! "`grep wdinit unix.sym`" ]
X then
X ./lddrv -av wind >/dev/null 2>&1 || (
X echo "Window driver load failed -- going to shell"
X exec /bin/sh < /dev/console > /dev/console 2>&1 )
X fi
X rm -f /tmp/.winload
X exec /bin/sh /etc/rc WINDOWED < /dev/window > /dev/w1 2>&1
Xfi
X
X## The window driver is installed and all filesystems have been checked ##
X
X# Load the system font
X
X/etc/.fontload 2>/dev/null
X
X# Setup environment
X
XTZ=`cat /etc/TZ`;export TZ
XDATE=`date '+%a %h %d, 19%y %r' `
XPATH=:/bin:/usr/bin:/etc
XUA=/usr/lib/ua
XTERM=s4
Xexport UA PATH TERM
X
X# Load other system drivers
X
Xmessage -i "\n Loading drivers\n\n Please stand by...\n" &
Xmpid=$!
X
Xrm -f /usr/adm/drv.log
Xif [ -x /etc/.drvload ]
Xthen
X /etc/.drvload
Xfi
X
X# Set node name and OS version
X
Xif [ -s /etc/namesys ]
Xthen
X /etc/namesys
Xfi
X
Xif [ -s /etc/.version ]
Xthen
X setuname -v `cat /etc/.version`
Xfi
X
X# Kill off last forked off window
X
Xkill $mpid > /dev/null 2>&1
X
Xmessage -i "\n The screen will now be set up.\n\n Please stand by...\n" &
Xmpid=$!
X
X# The following statements execute files in /etc which start daemons
X# and initialize system activities
X
Xfor i in .cleanup .lpstartsched .phinit .modeminit wmgr smgr
Xdo
X /etc/$i 2>/dev/null
Xdone
X
X# any additional daemons (such as slan initialization)
X# can be put in /etc/daemons, and will be executed without
X# changing /etc/rc. Each should be run in the background.
X
Xif [ -d /etc/daemons ]
Xthen
X DAEMONS=`ls /etc/daemons/*`
X if [ $? != 0 ] ; then DAEMONS=""; fi
X for i in $DAEMONS
X do
X if [ -x $i ]
X then nohup $i > /dev/null 2>&1 &
X fi
X done
Xfi
X
X# If a screen time out has been selected, then set it.
X
Xif [ -s /usr/lib/ua/.blanktime ]
Xthen
X scrset `cat /usr/lib/ua/.blanktime`
Xfi
X
X# Kill last window
Xkill $mpid > /dev/null 2>&1
X
X## END SYSTEM STARTUP - /etc/rc ##
END_OF_rc
if test 3421 -ne `wc -c <rc`; then
echo shar: \"rc\" unpacked with wrong size!
fi
chmod +x rc
# end of overwriting check
fi
if test -f syskill -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"syskill\"
else
echo shar: Extracting \"syskill\" \(283 characters\)
sed "s/^X//" >syskill <<'END_OF_syskill'
Xecho "System services are now being stopped."
Xcd /
Xif [ -d /etc/shutdaemon ]
Xthen
X for i in /etc/shutdaemon/*
X do
X if [ -x $i ] ; then $i ; fi
X done
Xfi
X/usr/lib/lpshut > /dev/null 2> /dev/null
Xsync;sync;sync
X/etc/killall
Xsync;sync;sync
X/etc/umountall
Xsync;sync;sync
Xsleep 2
Xexit 0
END_OF_syskill
if test 283 -ne `wc -c <syskill`; then
echo shar: \"syskill\" unpacked with wrong size!
fi
chmod +x syskill
# end of overwriting check
fi
if test -f sysreboot -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"sysreboot\"
else
echo shar: Extracting \"sysreboot\" \(76 characters\)
sed "s/^X//" >sysreboot <<'END_OF_sysreboot'
Xecho "\nThe system is being restarted."
Xsync;sync;sync
Xsleep 3
X/etc/reboot
END_OF_sysreboot
if test 76 -ne `wc -c <sysreboot`; then
echo shar: \"sysreboot\" unpacked with wrong size!
fi
chmod +x sysreboot
# end of overwriting check
fi
if test -f umountall -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"umountall\"
else
echo shar: Extracting \"umountall\" \(252 characters\)
sed "s/^X//" >umountall <<'END_OF_umountall'
Xcd /
X## /etc/umount /dev/fp011
X## tmp_umount=$?
X## /etc/umount /dev/fp012
X## netnews_umount=$?
X## /etc/umount /dev/fp013
X## archives_umount=$?
X## if [ $tmp_umount -eq 0 -a $netnews_umount -eq 0 -a $archives_umount -eq 0 ]
X## then
X > /etc/mnttab
X## fi
END_OF_umountall
if test 252 -ne `wc -c <umountall`; then
echo shar: \"umountall\" unpacked with wrong size!
fi
chmod +x umountall
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
--
Lenny Tropiano ICUS Software Systems [w] +1 (516) 589-7930
lenny at icus.islp.ny.us Telex; 154232428 ICUS [h] +1 (516) 968-8576
{ames,talcott,decuac,hombre,pacbell,sbcs}!icus!lenny attmail!icus!lenny
ICUS Software Systems -- PO Box 1; Islip Terrace, NY 11752
More information about the Unix-pc.sources
mailing list