Next Previous Contents

8. Creating system boot scripts

These bootscripts are started at system boot time. The scripts are responsible for mounting the root file system in read-write mode, activating swap, setting up some system settings and starting the various daemons that our system needs.

8.1 Preparing the directories and master files

You need the Sysvinit package again for this section.

   cd /etc
   mkdir rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d init.d rcS.d

   #!/bin/sh
   # Begin /etc/init.d/rcS
   
   runlevel=S
   prevlevel=N
   umask 022
   export runlevel prevlevel
 
   trap ":" INT QUIT TSTP
   
   for i in /etc/rcS.d/S??*
   do
      [ ! -f  "$i" ] && continue;
      $i start       
   done
 
   # End /etc/init.d/rcS

8.2 Creating the reboot script

   #!/bin/sh
   # Begin /etc/init.d/reboot
  
   echo -n "System reboot in progress..."
   
   /sbin/reboot -d -f -i
 
   # End /etc/init.d/reboot

8.3 Creating the halt script

   #!/bin/sh
   # Begin /etc/init.d/halt
 
   /sbin/halt -d -f -i -p
 
   # End /etc/init.d/halt

8.4 Creating the mountfs script

#!/bin/sh
# Begin /etc/init.d/mountfs
 
check_status()
{
  if [ $? = 0 ]
  then
    echo "OK"
  else
    echo "FAILED"
  fi
}
 
echo -n "Remounting root file system in read-write mode..."
/bin/mount -n -o remount,rw /
check_status
 
> /etc/mtab
/bin/mount -f -o remount,rw /
 
echo -n "Mounting proc file system..."
/bin/mount proc
check_status
 
# End /etc/init.d/mountfs

8.5 Creating the umountfs script

#!/bin/sh
# Begin /etc/init.d/umountfs
 
check_status()
{
  if [ $? = 0 ]
  then
    echo "OK"
  else
    echo "FAILED"
  fi
}
  
echo "Deactivating swap..."
/bin/swapoff -av
check_status
 
echo -n "Unmounting file systems..."
/bin/umount -a -r 
check_status
 
# End /etc/init.d/umountfs

8.6 Creating the sendsignals script

#!/bin/sh
# Begin /etc/init.d/sendsignals
 
check_status()
{
  if [ $? = 0 ]
  then
    echo "OK"
  else
    echo "FAILED"
  fi
}
echo -n "Sending all processes the TERM signal..."
/sbin/killall5 -15
check_status
 
echo -n "Sending all processes the KILL signal..."
/sbin/killall5 -9
check_status

8.7 Creating the checkroot bootscript

#!/bin/sh
# Begin /etc/init.d/checkroot
 
echo "Activating swap..."
/sbin/swapon -av
 
if [ -f /fastboot ]
then
  echo "Fast boot, no file system check"
else
  /bin/mount -n -o remount,ro /
  if [ $? = 0 ]
  then
    if [ -f /forcecheck ]
    then
      force="-f"
    else
      force=""
    fi
 
    echo "Checking root file system..."
    /sbin/fsck $force -a /
     
    if [ $? -gt 1 ]
    then
      echo
      echo "fsck failed. Please repair your file system manually by"
      echo "running fsck without the -a option"
      
      echo "Please note that the file system is currently mounted in"
      echo "read-only mode."
      echo
      echo "I will start sulogin now. CTRL+D will reboot your system."
      /sbin/sulogin
      /reboot -f
    fi
  else
    echo "Cannot check root file system because it is not mounted in"
    echo "read-only mode."
  fi
fi
 
# End /etc/init.d/checkroot

8.8 Creating the Sysklogd bootscript

#!/bin/sh
# Begin /etc/init.d/sysklogd
 
check_status()
{
  if [ $? = 0 ]
  then
    echo "OK"
  else
    echo "FAILED"
  fi
}
 
case "$1" in
  start)
    echo -n "Starting system log daemon..."
    start-stop-daemon -S -q -o -x /usr/sbin/syslogd -- -m 0
    check_status
 
    echo -n "Starting kernel log daemon..."
    start-stop-daemon -S -q -o -x /usr/sbin/klogd
    check_status
    ;;
 
  stop)
    echo -n "Stopping kernel log daemon..."
    start-stop-daemon -K -q -o -p  /var/run/klogd.pid
    check_status
 
    echo -n "Stopping system log daemon..."
    start-stop-daemon -K -q -o -p /var/run/syslogd.pid
    check_status
    ;;
 
  reload)
    echo -n "Reloading system load daemon configuration file..."
    start-stop-daemon -K -q -o -s 1 -p /var/run/syslogd.pid
    check_status
    ;;
 
  restart)
    echo -n "Stopping kernel log daemon..."
    start-stop-daemon -K -q -o -p /var/run/klogd.pid
    check_status
 
    echo -n "Stopping system log daemon..."
    start-stop-daemon -K -q -o -p /var/run/syslogd.pid
    check_status
 
    sleep 1
 
    echo -n "Starting system log daemon..."
    start-stop-daemon -S -q -o -x /usr/sbin/syslogd -- -m 0
    check_status
 
    echo -n "Starting kernel log daemon..."
    start-stop-daemon -S -q -o -x /usr/sbin/klogd
    check_status
    ;;
 
  *)
    echo "Usage: $0 {start|stop|reload|restart}"
    exit 1
    ;;
esac
 
# End /etc/init.d/sysklogd

8.9 Setting up symlinks and permissions

chmod 755 rcS reboot halt mountfs umountfs sendsignals checkroot sysklogd
cd ../rc0.d
ln -s ../init.d/sysklogd K90sysklogd
ln -s ../init.d/sendsignals S80sendsignals
ln -s ../init.d/umountfs S90umountfs
ln -s ../init.d/halt S99halt
cd ../rc6.d
ln -s ../init.d/sysklogd K90sysklogd
ln -s ../init.d/sendsignals S80sendsignals
ln -s ../init.d/umountfs S90umountfs
ln -s ../init.d/reboot S99reboot
cd ../rcS.d
ln -s ../init.d/checkroot S05checkroot
ln -s ../init.d/mountfs S10mountfs
cd /etc/rc2.d
ln -s ../init.d/sysklogd S03sysklogd

8.10 Creating the /etc/fstab file

   /dev/<LFS-partition designation> / ext2 defaults 0 1
   /dev/<swap-partition designation> none swap sw 0 0
   proc /proc proc defaults 0 0

Next Previous Contents