Next Previous Contents

10. Creating initial boot scripts

10.1 Preparing the directories and master files

You need the Sysvinit package again for this section.

Create the necessary directories by issuing these commands:

   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
      if [ ! -f  "$i" ] && continue
      $i start
   done
 
   # End /etc/init.d/rcS
 

10.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
 

10.3 Creating the halt script

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

10.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..."
/sbin/mount -n -o remount,rw /
check_status
 
> /etc/mtab
/sbin/mount -f -o remount,rw /
 
echo -n "Mounting proc file system..."
/sbin/mount proc
check_status
 
# End /etc/init.d/mountfs
 

10.5 Creating the umountfs script

#!/bin/sh
# Begin /etc/init.d/umountfs
 
check_status()
{
  if [ $? = 0 ]
  then
    echo "OK"
  else
    echo "FAILED"
  fi
} 
echo -n "Unmounting file systems..."
/sbin/umount -a -r 
check_status
 
echo -n "Remounting root file system in read-only mode..."
/sbin/mount -o remount,ro /
check_status
 
# End /etc/init.d/umountfs
 

10.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
 

10.7 Set file permissions and create symlinks

   cd ../rc6.d; ln -s ../init.d/umountfs S90umountfs
   ln -s ../init.d/reboot S99reboot
   ln -s ../init.d/sendsignals S80sendsignals
 
   cd ../rc0.d; ln -s ../init.d/umountfs S90umountfs
   ln -s ../init.d/halt S99halt
   ln -s ../init.d/sendsignals S80sendsignals
 
   cd ../rcS.d; ln -s ../init.d/mountfs S10mountfs
 

10.8 Creating the /etc/fstab file

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

10.9 Testing the system

You can test the system by restarting your computer and boot into LFS again. Any errors should be gone now and your root partition should be mounted in read-write mode automatically.

You can now finally restart your computer with a command like shutdown -r now


Next Previous Contents