init프로세스의 의미와 부팅과정에서의 init프로세스의 역할
작성자 정보
- 관리자 작성
- 작성일
컨텐츠 정보
- 3,506 조회
- 0 추천
- 목록
본문
init프로세스의 의미와 부팅과정에서의 init프로세스의 역할
리눅스에서 실행되는 모든 프로세스들은 PID를 가지고 있습니다.
이중 PID가 0번인 프로세스가 swapper입니다.
부팅과정에서 이 swapper프로세스(swapper는 커널의 일부분임, 즉, kernel)에 의해 실행되는 프로세스가 init프로세스입니다.
init프로세스의 PID는 1번이며 리눅스에서 실행되는 모든 프로세스들은 init프로세스로부터 시작합니다.
즉, 리눅스시스템에서 실행되어있는 모든 프로세스들은 init프로세스에 의해 실행된(fork) 프로세스들입니다.
따라서 init프로세스를 모든 프로세스들의 부모프로세스라고 합니다.
그리고 init프로세스는 0번부터 6번까지(0,1,2,3,4,5,6)의 실행모드를 가지고 있습니다.
즉, 리눅스 실행모드를 변경할 수 있는 명령어역할도 한다는 것을 기억해 두시기 바랍니다.
명령어위치 : /sbin/init
필자는 이번 장에서 설명하고 있는 init설명을 통하여 실행중인 프로세스의 관계와 부팅과정에서의 init에 대해 이해를 하실 수 있기를 간절히 바랍니다.
init프로세스를 제대로 활용하려면 무엇보다도 정확한 이해가 필요합니다.
따라서 init프로세스에 대해서 좀 자세히 설명 드리도록 하겠습니다.
부팅시에 swapper에 의해 실행된 init 프로세스는 /etc/inittab 파일을 읽어 들이게 됩니다.
/etc/inittab 파일의 예를 보면 다음과 같습니다.
[root@su250 ~]# cat /etc/inittab # inittab is only used by upstart for the default runlevel. # ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # System initialization is started by /etc/event.d/rcS # Individual runlevels are started by /etc/event.d/rc[0-6] # Ctrl-Alt-Delete is handled by /etc/event.d/control-alt-delete # Terminal gettys (tty[1-6]) are handled by /etc/event.d/tty[1-6] and # /etc/event.d/serial # For information on how to write upstart event handlers, or how # upstart works, see init(8), initctl(8), and events(5). # Default runlevel. The runlevels used 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: [root@su250 ~]# |
위의 주석문(#)에서 확인할 수 있듯이 init프로세스에 의해서 부팅시에 실행되는 내용들은 모두 /etc/event.d 디렉토리에 스크립트파일로 존재하고 있습니다.
이 디렉토리에 존재하는 파일들은 모두 시스템부팅시에 시스템초기화를 위해 실행되는 파일들이며 이 중 rcS라는 파일의 내용을 보시면 다음과 같습니다.
[root@su250 event.d]# cat /etc/event.d/rcS # rcS - runlevel compatibility # # This task runs the old sysv-rc startup scripts.
start on startup
stop on runlevel
# Note: there can be no previous runlevel here, if we have one it's bad # information (we enter rc1 not rcS for maintenance). Run /etc/rc.d/rc # without information so that it defaults to previous=N runlevel=S. console output script runlevel --set S >/dev/null || true
/etc/rc.d/rc.sysinit
runlevel --reboot || true end script post-stop script if [ "$UPSTART_EVENT" == "startup" ]; then runlevel=$(/bin/awk -F ':' '$3 == "initdefault" { print $2 }' /etc/inittab) [ -z "$runlevel" ] && runlevel="3" for t in $(cat /proc/cmdline); do case $t in -s|single|S|s) runlevel="S" ;; [1-9]) runlevel="$t" ;; esac done exec telinit $runlevel fi end script [root@su250 event.d]# |
위의 rc.sysinit스크립트는"시스템초기화"스크립트입니다.
즉, init프로세스에 의해 /etc/rc.d/rc.sysinit 스크립트가 실행이 된다는 것입니다.
/etc/rc.d/rc.sysinit 스크립트의 내용은 약 850행 정도 됩니다.
여러분들께서는 한번쯤 /etc/rc.d/rc.sysinit파일의 내용을 모두 확인해 보시기 바랍니다.
필자가 여기서 강조하고 싶은 내용은 init프로세스에 의해 실행되는 내용들 입니다.
다음은 /etc/event.d 디렉토리에 존재하는 rcN스크립트파일들입니다.
[root@su250 event.d]# ls -l /etc/event.d/rc* -rw-r--r-- 1 root root 545 2008-11-12 01:51 /etc/event.d/rc0 -rw-r--r-- 1 root root 639 2008-11-12 01:51 /etc/event.d/rc1 -rw-r--r-- 1 root root 396 2008-11-12 01:51 /etc/event.d/rc2 -rw-r--r-- 1 root root 396 2008-11-12 01:51 /etc/event.d/rc3 -rw-r--r-- 1 root root 396 2008-11-12 01:51 /etc/event.d/rc4 -rw-r--r-- 1 root root 396 2008-11-12 01:51 /etc/event.d/rc5 -rw-r--r-- 1 root root 415 2008-11-12 01:51 /etc/event.d/rc6 -rw-r--r-- 1 root root 803 2008-11-12 01:51 /etc/event.d/rcS -rw-r--r-- 1 root root 505 2008-11-12 01:51 /etc/event.d/rcS-sulogin [root@su250 event.d]# |
위의 내용에 대한 의미를 설명하면 다음과 같습니다.
- 부팅레벨이 0번이면 /etc/event.d/rc0스크립트가 실행되며 “/etc/rc.d/rc 0”이 실행되어 결론적으로 /etc/rc.d/rc0.d 디렉토리의 내용들이 순차적으로 실행됩니다.
-
-
-
-
- 부팅레벨이 1번이면 /etc/event.d/rc1스크립트가 실행되며 “/etc/rc.d/rc 1”이 실행되어 결론적으로 /etc/rc.d/rc1.d 디렉토리의 내용들이 순차적으로 실행됩니다.
-
-
-
-
- 부팅레벨이 2번이면 /etc/event.d/rc2스크립트가 실행되며 “/etc/rc.d/rc 2”이 실행되어 결론적으로 /etc/rc.d/rc2.d 디렉토리의 내용들이 순차적으로 실행됩니다.
-
-
-
-
- 부팅레벨이 3번이면 /etc/event.d/rc3스크립트가 실행되며 “/etc/rc.d/rc 3”이 실행되어 결론적으로 /etc/rc.d/rc3.d 디렉토리의 내용들이 순차적으로 실행됩니다.
-
-
-
-
- 부팅레벨이 4번이면 /etc/event.d/rc4스크립트가 실행되며 “/etc/rc.d/rc 4”이 실행되어 결론적으로 /etc/rc.d/rc4.d 디렉토리의 내용들이 순차적으로 실행됩니다.
-
-
-
-
- 부팅레벨이 5번이면 /etc/event.d/rc5스크립트가 실행되며 “/etc/rc.d/rc 5”이 실행되어 결론적으로 /etc/rc.d/rc5.d 디렉토리의 내용들이 순차적으로 실행됩니다.
-
-
-
-
- 부팅레벨이 6번이면 /etc/event.d/rc6스크립트가 실행되며 “/etc/rc.d/rc 6”이 실행되어 결론적으로 /etc/rc.d/rc6.d 디렉토리의 내용들이 순차적으로 실행됩니다.
-
-
-
-
참고로 부팅레벨 4번은 예비로 남겨두었기 때문에 현재 시스템에서는 정의되어 있지 않습니다.
하지만, 시스템관리자가 설정을 하여 사용할 수는 있는 부팅레벨입니다.
즉, 사용하지 못하는 부팅레벨이 아니라, 시스템관리자가 설정하면 사용할 수 있는 부팅레벨입니다.
/etc/rc.d/rcN.d디렉토리(N:0~6)에는 각 실행레벨에 따라서 실행시킬 프로세스들과 실행시키지 않을 프로세스들이 링크파일로 정의되어 있습니다.
위의 부팅레벨 가운데 기본레벨인 3번레벨의 실행내용들을 간단히 살펴보면 다음과 같습니다
[root@su250 rc.d]# ls -l /etc/rc.d/rc3.d/ 합계0 lrwxrwxrwx 1 root root 17 2008-12-01 21:59 K01dnsmasq -> ../init.d/dnsmasq lrwxrwxrwx 1 root root 16 2008-12-01 22:00 K01smartd -> ../init.d/smartd lrwxrwxrwx 1 root root 15 2008-12-01 21:58 K01smolt -> ../init.d/smolt lrwxrwxrwx 1 root root 17 2008-12-01 22:00 K05anacron -> ../init.d/anacron lrwxrwxrwx 1 root root 19 2008-12-01 21:59 K05saslauthd -> ../init.d/saslauthd lrwxrwxrwx 1 root root 19 2008-12-01 21:56 K10dc_server -> ../init.d/dc_server lrwxrwxrwx 1 root root 16 2008-12-01 21:56 K10psacct -> ../init.d/psacct lrwxrwxrwx 1 root root 19 2008-12-01 21:56 K12dc_client -> ../init.d/dc_client lrwxrwxrwx 1 root root 15 2008-12-01 21:58 K15httpd -> ../init.d/httpd lrwxrwxrwx 1 root root 13 2008-12-01 21:56 K20nfs -> ../init.d/nfs lrwxrwxrwx 1 root root 14 2008-12-01 21:56 K24irda -> ../init.d/irda lrwxrwxrwx 1 root root 15 2008-12-01 22:05 K25squid -> ../init.d/squid lrwxrwxrwx 1 root root 20 2008-12-01 21:58 K50netconsole -> ../init.d/netconsole lrwxrwxrwx 1 root root 15 2008-12-01 22:04 K50snmpd -> ../init.d/snmpd lrwxrwxrwx 1 root root 19 2008-12-01 22:04 K50snmptrapd -> ../init.d/snmptrapd lrwxrwxrwx 1 root root 20 2008-12-01 21:56 K69rpcsvcgssd -> ../init.d/rpcsvcgssd lrwxrwxrwx 1 root root 17 2008-12-01 22:16 K73winbind -> ../init.d/winbind lrwxrwxrwx 1 root root 16 2008-12-01 22:16 K73ypbind -> ../init.d/ypbind lrwxrwxrwx 1 root root 20 2008-12-01 22:03 K74lm_sensors -> ../init.d/lm_sensors lrwxrwxrwx 1 root root 14 2008-12-01 21:56 K74nscd -> ../init.d/nscd lrwxrwxrwx 1 root root 14 2008-12-01 22:24 K74ntpd -> ../init.d/ntpd lrwxrwxrwx 1 root root 14 2008-12-01 22:00 K75fuse -> ../init.d/fuse lrwxrwxrwx 1 root root 17 2008-12-01 22:24 K75ntpdate -> ../init.d/ntpdate lrwxrwxrwx 1 root root 16 2008-12-01 22:01 K84btseed -> ../init.d/btseed lrwxrwxrwx 1 root root 17 2008-12-01 22:01 K84bttrack -> ../init.d/bttrack lrwxrwxrwx 1 root root 24 2008-12-01 22:24 K84wpa_supplicant -> ../init.d/wpa_supplicant lrwxrwxrwx 1 root root 20 2008-12-01 21:52 K87multipathd -> ../init.d/multipathd lrwxrwxrwx 1 root root 21 2008-12-01 21:59 K87restorecond -> ../init.d/restorecond lrwxrwxrwx 1 root root 18 2008-12-01 21:51 K89netplugd -> ../init.d/netplugd lrwxrwxrwx 1 root root 15 2008-12-01 21:51 K89rdisc -> ../init.d/rdisc lrwxrwxrwx 1 root root 17 2008-12-01 21:58 K90network -> ../init.d/network lrwxrwxrwx 1 root root 14 2008-12-01 22:05 K91capi -> ../init.d/capi lrwxrwxrwx 1 root root 19 2008-12-01 22:24 K95firstboot -> ../init.d/firstboot lrwxrwxrwx 1 root root 23 2008-12-01 22:00 S00microcode_ctl -> ../init.d/microcode_ctl lrwxrwxrwx 1 root root 18 2008-12-01 21:52 S06cpuspeed -> ../init.d/cpuspeed lrwxrwxrwx 1 root root 19 2008-12-01 21:51 S08ip6tables -> ../init.d/ip6tables lrwxrwxrwx 1 root root 18 2008-12-01 21:51 S08iptables -> ../init.d/iptables lrwxrwxrwx 1 root root 14 2008-12-01 22:05 S09isdn -> ../init.d/isdn lrwxrwxrwx 1 root root 16 2008-12-01 21:56 S11auditd -> ../init.d/auditd lrwxrwxrwx 1 root root 17 2008-12-01 21:55 S12rsyslog -> ../init.d/rsyslog lrwxrwxrwx 1 root root 20 2008-12-01 22:00 S13irqbalance -> ../init.d/irqbalance lrwxrwxrwx 1 root root 17 2008-12-01 21:56 S13rpcbind -> ../init.d/rpcbind lrwxrwxrwx 1 root root 17 2008-12-01 21:56 S14nfslock -> ../init.d/nfslock lrwxrwxrwx 1 root root 19 2008-12-01 21:59 S15mdmonitor -> ../init.d/mdmonitor lrwxrwxrwx 1 root root 19 2008-12-01 21:56 S18rpcidmapd -> ../init.d/rpcidmapd lrwxrwxrwx 1 root root 17 2008-12-01 21:56 S19rpcgssd -> ../init.d/rpcgssd lrwxrwxrwx 1 root root 20 2008-12-01 21:54 S22messagebus -> ../init.d/messagebus lrwxrwxrwx 1 root root 15 2008-12-01 21:58 S25netfs -> ../init.d/netfs lrwxrwxrwx 1 root root 15 2008-12-01 21:52 S26acpid -> ../init.d/acpid lrwxrwxrwx 1 root root 19 2008-12-01 22:01 S26haldaemon -> ../init.d/haldaemon lrwxrwxrwx 1 root root 15 2008-12-01 22:24 S26pcscd -> ../init.d/pcscd lrwxrwxrwx 1 root root 19 2008-12-01 21:58 S26udev-post -> ../init.d/udev-post lrwxrwxrwx 1 root root 24 2008-12-01 22:01 S27NetworkManager -> ../init.d/NetworkManager lrwxrwxrwx 1 root root 21 2008-12-01 22:24 S28portreserve -> ../init.d/portreserve lrwxrwxrwx 1 root root 24 2008-12-01 22:24 S28setroubleshoot -> ../init.d/setroubleshoot lrwxrwxrwx 1 root root 19 2008-12-01 21:59 S50bluetooth -> ../init.d/bluetooth lrwxrwxrwx 1 root root 14 2008-12-01 22:00 S55sshd -> ../init.d/sshd lrwxrwxrwx 1 root root 18 2008-12-01 21:59 S80sendmail -> ../init.d/sendmail lrwxrwxrwx 1 root root 13 2008-12-01 21:51 S85gpm -> ../init.d/gpm lrwxrwxrwx 1 root root 15 2008-12-01 21:59 S90crond -> ../init.d/crond lrwxrwxrwx 1 root root 20 2008-12-01 22:24 S90kerneloops -> ../init.d/kerneloops lrwxrwxrwx 1 root root 13 2008-12-01 21:56 S95atd -> ../init.d/atd lrwxrwxrwx 1 root root 22 2008-12-01 21:58 S96avahi-daemon -> ../init.d/avahi-daemon lrwxrwxrwx 1 root root 14 2008-12-01 22:02 S98cups -> ../init.d/cups lrwxrwxrwx 1 root root 11 2008-12-01 21:58 S99local -> ../rc.local [root@su250 rc.d]# |
위의 예는 보시는 바와 같이 각 실행레벨마다 실행될 스크립트들은 모두 링크파일 형태로 존재하여 실제 실행 스크립트 파일들은 모두 /etc/rc.d/init.d/ 디렉토리에 존재하고 있습니다.
이 링크에 의해 각 실행 단계별로 필요한 프로세스들을 실행하기도 하며 실행하지 않을 수도 있습니다.
이 디렉토리에 있는 모든 파일들은 K로 시작하거나 S시작합니다.
K로 시작하는 스크립트 파일들은 해당 부팅레벨(여기서는 현재 3번 부팅레벨)에서는 실행되지 않은 프로세스들이며 S로 시작하는 스크립트파일들은 해당 부팅레벨에서 부팅시에 실행하는 프로세스들입니다.
그리고 K나 S뒤의 숫자들은 실행될 순서를 나타낸 것입니다.
그리고 여기서 주의 깊게 보셔야 하는 것은 맨 마지막 스크립트가 S99local 이라는 것입니다.
이 스크립트에 의해 /etc/rc.d/rc.local 스크립트가 수행됩니다.
즉, /etc/rc.d/rc.local 파일에 설정해 둔 내용들이 부팅시마다 매번 자동 실행되는 이유는 여기에 있는 것입니다.
관련자료
-
이전
-
다음