다음 이전 차례

8. 시스템 부트 스크립트의 생성

이 부트 스크립트들은 시스템이 부팅될 때 시작된다. 이 스크립트들은 루트 파일 시스템을 읽고 쓰기 모드로 마운트하고, 스왑을 활성화하며 몇몇 시스템 설정을 하고 우리 시스템이 필요한 다양한 데몬들을 시작하는 역할을 한다.

8.1 디렉토리와 마스터 파일의 준비

이 장에서 여러분은 다시 Sysvinit 패키지가 필요하다.

   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 reboot 스크립트 만들기

   #!/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 halt 스크립트 생성

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

8.4 mountfs 스크립트의 생성

#!/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 umountfs 스크립트의 생성

#!/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 sendsignals 스크립트의 생성

#!/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 checkroot 부트 스크립트의 생성

#!/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 Sysklogd 부트 스크립트의 생성

#!/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 심볼릭 링크와 권한 설정

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 /etc/fstab 파일의 생성

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

다음 이전 차례