6.3. Construction

6.3.1. Install sysvinit utilities

bash# cd /usr/src/sysvinit-2.84/src
bash# make CC="gcc -mcpu=i386"
bash# cp halt init shutdown ~/staging/sbin
bash# ln -s halt ~/staging/sbin/reboot
bash# ln -s init ~/staging/sbin/telinit
bash# mknod ~/staging/dev/initctl p

6.3.2. Create /etc/inittab file

Use a text editor to create the following file and save it as ~/staging/etc/inittab

# /etc/inittab - init daemon configuration file
#
# Default runlevel
id:1:initdefault:
#
# System initialization
si:S:sysinit:/etc/init.d/rc S
#
# Runlevel scripts
r0:0:wait:/etc/init.d/rc 0
r1:1:respawn:/bin/sh
r2:2:wait:/etc/init.d/rc 2
r3:3:wait:/etc/init.d/rc 3
r4:4:wait:/etc/init.d/rc 4
r5:5:wait:/etc/init.d/rc 5
r6:6:wait:/etc/init.d/rc 6
#
# end of /etc/inittab

6.3.3. Create /etc/init.d/rc script

Use a text editor to create the following file and save it as ~/staging/etc/init.d/rc

#!/bin/sh
#
# /etc/init.d/rc - runlevel change script
#
PATH=/sbin:/bin
SCRIPT_DIR="/etc/rc$1.d"
#
# Check that the rcN.d directory really exists.
if [ -d $SCRIPT_DIR ]; then
#
# Execute the kill scripts first.
  for SCRIPT in $SCRIPT_DIR/K*; do
    if [ -x "$SCRIPT" ]; then
      $SCRIPT stop;
    fi;
  done;
#
# Do the Start scripts last.
  for SCRIPT in $SCRIPT_DIR/S*; do
    if [ -x $SCRIPT ]; then
      $SCRIPT start;
    fi;
  done;
fi

Make the file executable.

bash# chmod +x /etc/init.d/rc

6.3.4. Modify /etc/init.d/local_fs script

A case statement is added to allow the script to either mount or dismount local filesystems depending on the command-line argument given. The original script is contained inside the "start" portion of the case statement. The stop portion is new.

#!/bin/sh
#
# local_fs - check and mount local filesystems
#
PATH=/sbin:/bin ; export PATH

case $1 in

start)
  echo "Checking local filesystem integrity."
  fsck -ATCp
  if [ $(($?)) -gt $((1)) ]; then
    echo "Filesystem errors still exist!  Manual intervention required."
    /bin/sh
  else
    echo "Remounting / as read-write."
    mount -o remount,rw /
    echo "Mounting local filesystems."
    mount -a
  fi
;;

stop)
  echo "Dismounting local filesystems."
  umount -a
  echo "Remounting / as read-only."
  mount -o remount,rw /
  echo "Flushing disk cache."
  sync
;;

default)
  echo "usage: $0 start|stop";
;;

esac
#
# end of local_fs

6.3.5. Create a hostname script

Use a text editor to create the following script and save it as ~/staging/etc/init.d/hostname

#!/bin/sh
#
# hostname - set the system name to the name stored in /etc/hostname
#
PATH=/sbin:/bin ; export PATH

echo "Setting hostname."
if [ -f /etc/hostname ]; then
  hostname $(cat /etc/hostname)
else
  hostname gnu-linux
fi
#
# end of hostname

6.3.6. Create halt & reboot scripts

Use a text editor to create ~/staging/etc/init.d/halt as shown below.

#!/bin/sh
#
# halt - halt the system
#
PATH=/sbin:/bin ; export PATH

echo "Initiating system halt."
halt
#
# end of /etc/init.d/halt

Create the following script and save it as ~/staging/etc/init.d/reboot

#!/bin/sh
#
# reboot - reboot the system
#
PATH=/sbin:/bin ; export PATH

echo "Initiating system reboot."
reboot
#
# end of /etc/init.d/reboot

Flag script files as executable.

bash# chmod +x /etc/init.d/*

6.3.7. Create rcN.d directories and links

bash# cd ~/staging/etc
bash# mkdir rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d rcS.d
bash# cd rcS.d
bash# ln -s ../init.d/proc_fs S10proc_fs
bash# ln -s ../init.d/local_fs S20local_fs
bash# ln -s ../init.d/hostname S30hostname
bash# cd rc0.d
bash# ln -s ../init.d/local_fs K10local_fs
bash# ln -s ../init.d/halt K90halt
bash# cd rc6.d
bash# ln -s ../init.d/local_fs K10local_fs
bash# ln -s ../init.d/reboot K90reboot

6.3.8. Create the root disk image

bash# cd /
bash# dd if=/dev/zero of=/dev/ram7 bs=1k count=4096
bash# mke2fs -m0 /dev/ram7
bash# mount /dev/ram7 /mnt
bash# cp -dpR ~/staging/* /mnt
bash# umount /dev/ram7
bash# dd if=/dev/ram7 of=~/phase5-image bs=1k
bash# gzip -9 ~/phase5-image

6.3.9. Copy the image to diskette

Insert the diskette labled "root disk" into drive fd0.

bash# dd if=~/phase5-image.gz of=/dev/fd0 bs=1k