강좌
클라우드/리눅스에 관한 강좌입니다.
리눅스 분류

부팅과정에서 살펴본 init프로세스의 역할

작성자 정보

  • 관리자 작성
  • 작성일

컨텐츠 정보

본문

부팅과정에서 살펴본 init프로세스의 역할




 

 

 

필자는 이번에 설명하고 있는 init설명을 통하여 실행중인 프로세스의 관계와 부팅과정에서의 init 대해 이해할 있기를 바란다.

 

 

 

 init프로세스를 제대로 활용하려면 무엇보다도 정확한 이해가 필요하다.

 

 

 

 따라서 init프로세스에 대해서 자세히 설명하도록 하겠다.

 

 

 

 

 

부팅시에 swapper 의해 실행된 init 프로세스는 /etc/inittab 파일을 읽어들이게 된다.

 

 

 

  /etc/inittab 파일은 init프로세스의 설정파일이라고 있다.

 

 

 

 /etc/inittab파일의  예를보면 다음과 같다.

 

 

 

 

 

[root@sulinux ~]#cat /etc/inittab

#

# inittab       This file describes how the INIT process should set up

#               the system in a certain run-level.

#

# Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>

#               Modified for RHS Linux by Marc Ewing and Donnie Barnes

#

 

# Default runlevel. The runlevels used by RHS are:

#   0 - halt (Do NOT set initdefault to this)

#   1 - Single user mode

#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)

#   3 - Full multiuser mode

#   4 - unused

#   5 - X11

#   6 - reboot (Do NOT set initdefault to this)

#

id:5:initdefault:

 

# System initialization.

si::sysinit:/etc/rc.d/rc.sysinit

 

l0:0:wait:/etc/rc.d/rc 0

l1:1:wait:/etc/rc.d/rc 1

l2:2:wait:/etc/rc.d/rc 2

l3:3:wait:/etc/rc.d/rc 3

l4:4:wait:/etc/rc.d/rc 4

l5:5:wait:/etc/rc.d/rc 5

l6:6:wait:/etc/rc.d/rc 6

 

# Trap CTRL-ALT-DELETE

ca::ctrlaltdel:/sbin/shutdown -t3 -r now

 

# When our UPS tells us power has failed, assume we have a few minutes

# of power left.  Schedule a shutdown for 2 minutes from now.

# This does, of course, assume you have powerd installed and your

# UPS connected and working correctly. 

pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"

 

# If power was restored before the shutdown kicked in, cancel it.

pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"

 

 

# Run gettys in standard runlevels

1:2345:respawn:/sbin/mingetty tty1

2:2345:respawn:/sbin/mingetty tty2

3:2345:respawn:/sbin/mingetty tty3

4:2345:respawn:/sbin/mingetty tty4

5:2345:respawn:/sbin/mingetty tty5

6:2345:respawn:/sbin/mingetty tty6

 

# Run xdm in runlevel 5

x:5:respawn:/etc/X11/prefdm -nodaemon

[root@sulinux ~]#

 

위의 예에서 si::sysinit:/etc/rc.d/rc.sysinit행에 있는 rc.sysinit스크립트는 "시스템초기화"스크립트파일이다.

 

 

 

 즉 시스템이 부팅하면서 init프로세스에 의해 /etc/rc.d/rc.sysinit 스크립트가 실행된다는 것을 의미한다.

 

 

 

 

/etc/rc.d/rc.sysinit 스크립트의 내용은 약 971행 정도 된다.

 

 

 

 시스템관리자라면 한번쯤 /etc/rc.d/rc.sysinit파일의 내용을 모두 확인해 보기 바란다.

 

 

 

 

필자가 여기서 강조하고 싶은것은 init프로세스에 의해 실행되는 내용들이다.

 

 

 

 즉 부팅이 되면서 init프로세스는 /etc/inittab파일의 내용을 한 행씩 실행하게 된다는 것을 의미한다.

 

 

 

 

다음과 같이 정리해보자. init프로세스는 부팅되면서 /etc/inittab파일의 내용을 실행하고 위의 내용에 대한 의미를 설명하면 다음과 같다.

 

 

 

 

 

   부팅레벨이 0번이면 /etc/rc.d/rc 0이 실행되어 결론적으로 /etc/rc.d/rc0.d/디렉토리의 파일들이 순차적으로 실행된다.


 

   부팅레벨이 1번이면 /etc/rc.d/rc 1이 실행되어 결론적으로 /etc/rc.d/rc1.d/ 디렉토리의 파일들이 순차적으로 실행된다.



  부팅레벨이 2번이면 /etc/rc.d/rc 2이 실행되어 결론적으로 /etc/rc.d/rc2.d/ 디렉토리의 파일들이 순차적으로 실행된다.

 

 

부팅레벨이 3번이면 /etc/rc.d/rc 3이 실행되어 결론적으로 /etc/rc.d/rc3.d/ 디렉토리의 파일들이 순차적으로 실행된다.

 

부팅레벨이 4번이면 /etc/rc.d/rc 4이 실행되어 결론적으로 /etc/rc.d/rc4.d/ 디렉토리의 파일들이 순차적으로 실행된다.

 

 

부팅레벨이 5번이면 /etc/rc.d/rc 5이 실행되어 결론적으로 /etc/rc.d/rc5.d/ 디렉토리의 파일들이 순차적으로 실행된다.

 

   부팅레벨이 6번이면 /etc/rc.d/rc 6이 실행되어 결론적으로 /etc/rc.d/rc6.d/ 디렉토리의 파일들이 순차적으로 실행된다.

 

 

 

 

 

참고로 앞서 설명한적이 있듯이 부팅레벨 4번은 예비로 남겨두었기 때문에 현재 시스템에서는 정의되어 있지 않다.

 

 

 

 하지만, 시스템관리자가 설정하여 사용할 수는 있는 부팅레벨이다.

 

 

 

 즉 사용하지 못하는 부팅레벨이 아니라, 시스템관리자가 설정하면 사용할 수 있는 부팅레벨이다.

 

 

 

 

 

/etc/rc.d/rcN.d디렉토리(N:0~6)에는 각 실행레벨에 따라서 실행시킬 프로세스들과 실행시키지 않을 프로세스들이 링크파일로 정의되어 있다.

 

 

 

 , 이제 위의 여러가지 부팅레벨들 가운데 하나를 살펴보도록 하자. 즉 위의 부팅레벨 가운데 기본레벨인 3번레벨의 실행내용들을 간단히 살펴보면 다음과 같다.

 

 

 



[root@sulinux ~]#ls -l /etc/rc.d/rc3.d

합계 296

lrwxrwxrwx 1 root root 24  2  9 18:01 K02NetworkManager -> ../init.d/NetworkManager

lrwxrwxrwx 1 root root 34  2  9 18:01 K02NetworkManagerDispatcher -> ../init.d/NetworkManagerDispatcher

lrwxrwxrwx 1 root root 24  2  9 17:56 K02avahi-dnsconfd -> ../init.d/avahi-dnsconfd

lrwxrwxrwx 1 root root 16  2  9 17:57 K02dhcdbd -> ../init.d/dhcdbd

lrwxrwxrwx 1 root root 17  2  9 18:01 K02oddjobd -> ../init.d/oddjobd

lrwxrwxrwx 1 root root 17  2  9 18:06 K05anacron -> ../init.d/anacron

lrwxrwxrwx 1 root root 13  2  9 18:06 K05atd -> ../init.d/atd

lrwxrwxrwx 1 root root 16  2  9 18:00 K05conman -> ../init.d/conman

lrwxrwxrwx 1 root root 14  2  9 18:00 K05innd -> ../init.d/innd

lrwxrwxrwx 1 root root 19  2  9 17:57 K05saslauthd -> ../init.d/saslauthd

lrwxrwxrwx 1 root root 14  2  9 18:06 K10cups -> ../init.d/cups

lrwxrwxrwx 1 root root 19  2  9 18:00 K10dc_server -> ../init.d/dc_server

lrwxrwxrwx 1 root root 16  2  9 18:00 K10psacct -> ../init.d/psacct

lrwxrwxrwx 1 root root 19  2  9 18:00 K12dc_client -> ../init.d/dc_client

lrwxrwxrwx 1 root root 13  2  9 18:06 K15gpm -> ../init.d/gpm

lrwxrwxrwx 1 root root 13  2  9 17:58 K20nfs -> ../init.d/nfs

lrwxrwxrwx 1 root root 15  2  9 17:54 K20rwhod -> ../init.d/rwhod

lrwxrwxrwx 1 root root 18  2  9 18:06 K30sendmail -> ../init.d/sendmail

lrwxrwxrwx 1 root root 22  2  9 17:59 K30spamassassin -> ../init.d/spamassassin

lrwxrwxrwx 1 root root 19  2  9 17:59 K34yppasswdd -> ../init.d/yppasswdd

lrwxrwxrwx 1 root root 15  2  9 18:00 K35dhcpd -> ../init.d/dhcpd

lrwxrwxrwx 1 root root 18  2  9 18:00 K35dhcrelay -> ../init.d/dhcrelay

lrwxrwxrwx 1 root root 13  2  9 17:57 K35smb -> ../init.d/smb

lrwxrwxrwx 1 root root 19  2  9 18:01 K35vncserver -> ../init.d/vncserver

lrwxrwxrwx 1 root root 17  2  9 18:05 K35winbind -> ../init.d/winbind

lrwxrwxrwx 1 root root 20  2  9 17:56 K50netconsole -> ../init.d/netconsole

lrwxrwxrwx 1 root root 16  2  9 17:59 K50vsftpd -> ../init.d/vsftpd

lrwxrwxrwx 1 root root 20  2  9 17:58 K69rpcsvcgssd -> ../init.d/rpcsvcgssd

lrwxrwxrwx 1 root root 16  2  9 18:05 K73ypbind -> ../init.d/ypbind

lrwxrwxrwx 1 root root 14  2  9 17:54 K74gfs2 -> ../init.d/gfs2

lrwxrwxrwx 1 root root 14  2  9 17:57 K74nscd -> ../init.d/nscd

lrwxrwxrwx 1 root root 16  2  9 17:59 K74ypserv -> ../init.d/ypserv

lrwxrwxrwx 1 root root 16  2  9 17:59 K74ypxfrd -> ../init.d/ypxfrd

lrwxrwxrwx 1 root root 15  2  9 18:06 K75netfs -> ../init.d/netfs

lrwxrwxrwx 1 root root 19  2  9 18:06 K85mdmonitor -> ../init.d/mdmonitor

lrwxrwxrwx 1 root root 15  2  9 17:59 K85mdmpd -> ../init.d/mdmpd

lrwxrwxrwx 1 root root 17  2  9 18:06 K85rpcgssd -> ../init.d/rpcgssd

lrwxrwxrwx 1 root root 19  2  9 18:06 K85rpcidmapd -> ../init.d/rpcidmapd

lrwxrwxrwx 1 root root 17  2  9 18:06 K86nfslock -> ../init.d/nfslock

lrwxrwxrwx 1 root root 18  2  9 18:06 K87mcstrans -> ../init.d/mcstrans

lrwxrwxrwx 1 root root 20  2  9 17:56 K87multipathd -> ../init.d/multipathd

lrwxrwxrwx 1 root root 15  2  9 17:59 K87named -> ../init.d/named

lrwxrwxrwx 1 root root 17  2  9 18:06 K87portmap -> ../init.d/portmap

lrwxrwxrwx 1 root root 21  2  9 18:06 K87restorecond -> ../init.d/restorecond

lrwxrwxrwx 1 root root 15  2  9 18:06 K88pcscd -> ../init.d/pcscd

lrwxrwxrwx 1 root root 24  2  9 17:57 K88wpa_supplicant -> ../init.d/wpa_supplicant

lrwxrwxrwx 1 root root 18  2  9 17:55 K89netplugd -> ../init.d/netplugd

lrwxrwxrwx 1 root root 15  2  9 17:54 K89rdisc -> ../init.d/rdisc

lrwxrwxrwx 1 root root 19  2  9 18:06 K92ip6tables -> ../init.d/ip6tables

lrwxrwxrwx 1 root root 17  2  9 17:54 K92ipvsadm -> ../init.d/ipvsadm

lrwxrwxrwx 1 root root 18  2  9 18:06 K99cpuspeed -> ../init.d/cpuspeed

lrwxrwxrwx 1 root root 22  2  9 18:06 K99lvm2-monitor -> ../init.d/lvm2-monitor

lrwxrwxrwx 1 root root 25  2  9 18:00 K99readahead_later -> ../init.d/readahead_later

lrwxrwxrwx 1 root root 23  2  9 17:59 S00microcode_ctl -> ../init.d/microcode_ctl

lrwxrwxrwx 1 root root 17  2  9 17:59 S03sysstat -> ../init.d/sysstat

lrwxrwxrwx 1 root root 25  2  9 18:00 S04readahead_early -> ../init.d/readahead_early

lrwxrwxrwx 1 root root 15  2  9 18:00 S05kudzu -> ../init.d/kudzu

lrwxrwxrwx 1 root root 18  2  9 17:54 S08iptables -> ../init.d/iptables

lrwxrwxrwx 1 root root 17  2  9 17:56 S10network -> ../init.d/network

lrwxrwxrwx 1 root root 16  2  9 17:57 S11auditd -> ../init.d/auditd

lrwxrwxrwx 1 root root 16  2  9 17:57 S12syslog -> ../init.d/syslog

lrwxrwxrwx 1 root root 20  2  9 17:59 S13irqbalance -> ../init.d/irqbalance

lrwxrwxrwx 1 root root 20  2  9 17:55 S22messagebus -> ../init.d/messagebus

lrwxrwxrwx 1 root root 16  2  9 18:00 S28autofs -> ../init.d/autofs

lrwxrwxrwx 1 root root 15  2  9 17:59 S44acpid -> ../init.d/acpid

lrwxrwxrwx 1 root root 14  2  9 17:59 S55sshd -> ../init.d/sshd

lrwxrwxrwx 1 root root 16  2  9 18:00 S56xinetd -> ../init.d/xinetd

lrwxrwxrwx 1 root root 14  2  9 18:25 S58ntpd -> ../init.d/ntpd

lrwxrwxrwx 1 root root 15  2  9 17:57 S90crond -> ../init.d/crond

lrwxrwxrwx 1 root root 13  2  9 18:01 S90xfs -> ../init.d/xfs

lrwxrwxrwx 1 root root 22  2  9 17:59 S97yum-updatesd -> ../init.d/yum-updatesd

lrwxrwxrwx 1 root root 22  2  9 17:56 S98avahi-daemon -> ../init.d/avahi-daemon

lrwxrwxrwx 1 root root 19  2  9 18:00 S98haldaemon -> ../init.d/haldaemon

lrwxrwxrwx 1 root root 19  2  9 18:01 S99firstboot -> ../init.d/firstboot

lrwxrwxrwx 1 root root 11  2  9 17:56 S99local -> ../rc.local

[root@sulinux ~]#

 

위의 내용은 /etc/rc.d/rc3.d/디렉토리에 존재하는 파일들의 목록이다.

 

 

 

 즉 위의 파일들은 시스템이 부팅레벨 3번으로 부팅될 때 모두 실행되는 내용들이다.

 

 

 

 이 디렉토리의 내용에서 여러분과 필자 같은 시스템관리자들이 반드시, , 기필코 알아야하는 내용을 정리해 보겠다.

 

 

 

 잘 보기 바란다.

 

 

 

 매우 중요한 내용이다.

 

 

 

 

디렉토리의 모든 파일들은 모두 링크파일 형태로 존재한다.

 

 

 

 

링크파일들은 모두 /etc/rc.d/init.d/ 디렉토리의 실제파일로 링크되어 있다.

 

 

 

 

즉 이 링크에 의해 각 실행 단계별로 필요한 프로세스들을 실행하기도 하며
실행하지 않을 수도 있다.

 

 

 

 

이 디렉토리에 존재하는 모든 파일들은 K로 시작하거나 S시작한다.

 

 

 

 

K로 시작하는 스크립트 파일들은 해당 부팅레벨 (여기서는 현재 3번 부팅레벨)에서는 실행되지 않는 프로세스들이며 S로 시작하는 스크립트파일들은 해당 부팅레벨에서 부팅시에 실행하는 프로세스들이다.

 

 

 

 

K S뒤의 숫자들은 실행될 순서를 나타낸 것이다.

 

 

 

 

이런 링크를 생성하고 삭제할 수 있는 명령어는 chkconfig이다.

 

 

 

 즉 각
부팅레벨마다 링크파일을 별도로 만들고 삭제하고 K S를 변경할 수 있는 명령어이다.

 

 

 

 

 

그리고 한가지 더 주의깊게 보아야 할 것은 맨 마지막 스크립트가 S99local 이라는 것이다.

 

 

 

 이 스크립트에 의해 /etc/rc.d/rc.local 스크립트가 수행된다.

 

 

 

 /etc/rc.d/rc.local 파일에 설정해 둔 내용들이 부팅시마다 매번 자동 실행되는 이유는 여기에 있다.

 

 

 

 

 

결국 시스템 부팅에 대한 이해를 하기 위해서는 /etc/rc.d/rcN.d/디렉토리의 내용을 모두 파악하고 있어야 한다.

 

 

 

 

 

 

관련자료

댓글 0
등록된 댓글이 없습니다.

공지사항


뉴스광장


  • 현재 회원수 :  60,070 명
  • 현재 강좌수 :  35,986 개
  • 현재 접속자 :  495 명