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

부팅7단계 : /etc/rc.d/rcN.d/ 디렉토리의 스크립트실행(부팅레벨에 따른실행)

작성자 정보

  • 관리자 작성
  • 작성일

컨텐츠 정보

본문

부팅7단계 : /etc/rc.d/rcN.d/ 디렉토리의 스크립트실행(부팅레벨에 따른실행)

 

 

 

 

 

여기서 N 0부터 6까지의 자연수를 의미한다.

 

 

 

 앞 단계에서 실행되었던 /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

 

 

 

 

위의 내용은 다음과 같이 해석하면 된다.

 

 

 

 /etc/rc.d/rc라는 스크립트가 있는데 각각의 부팅레벨에 따라서 rc라는 스크립트에 해당 인자가 주어진다.

 

 

 

 예를들어 부팅레벨 3번이면 rc스크립트에 3이라는 인자가 주어져서 “/etc/rc.d/rc 3”이 실행된다.

 

 

 

 이것의 의미는 /etc/rc.d/rc3.d/디렉토리를 실행하라는 의미로 해석된다.

 

 

 

 다른 부팅레벨도 마찬가지이다.

 

 

 

 결론적으로 0번부터 6번까지 각각의 부팅레벨에 따라서 다음 디렉토리들에 존재하는 스크립트들이 실행된다.

 

 

 

 

 

. 부팅레벨이 0번이면 /etc/rc.d/rc0.d/디렉토리의 스크립트파일들이 순차적으로 실행된다.

 

 

 

 

. 부팅레벨이 1번이면 /etc/rc.d/rc1.d/디렉토리의 스크립트파일들이 순차적으로 실행된다.

 

 

 

 

. 부팅레벨이 2번이면 /etc/rc.d/rc2.d/디렉토리의 스크립트파일들이 순차적으로 실행된다.

 

 

 

 

. 부팅레벨이 3번이면 /etc/rc.d/rc3.d/디렉토리의 스크립트파일들이 순차적으로 실행된다.

 

 

 

 

. 부팅레벨이 4번이면 /etc/rc.d/rc4.d/디렉토리의 스크립트파일들이 순차적으로 실행된다.

 

 

 

 

. 부팅레벨이 5번이면 /etc/rc.d/rc5.d/디렉토리의 스크립트파일들이 순차적으로 실행된다.

 

 

 

 

. 부팅레벨이 6번이면 /etc/rc.d/rc6.d/디렉토리의 스크립트파일들이 순차적으로 실행된다.

 

 

 

 

 

즉 각각의 부팅레벨마다 실행되는 디렉토리가 다르고 각각의 디렉토리내에 존재하는 스크립트파일들이 다르기 때문에 부팅레벨에 따라 실행되는 내용이 다른것이다.

 

 

 

 이미 앞의 5단계에서 시스템부팅레벨이 3번으로 결정되었기 때문에 우리는 3번 부팅레벨일 경우에 실행되는 /etc/rc.d/rc3.d/디렉토리의 내용을 살펴보고자 한다.

 

 

 

 

 

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

total 296

lrwxrwxrwx 1 root root 24 Feb  9  2009 K02NetworkManager -> ../init.d/NetworkManager

lrwxrwxrwx 1 root root 34 Feb  9  2009 K02NetworkManagerDispatcher -> ../init.d/NetworkManagerDispatcher

lrwxrwxrwx 1 root root 24 Feb  9  2009 K02avahi-dnsconfd -> ../init.d/avahi-dnsconfd

lrwxrwxrwx 1 root root 16 Feb  9  2009 K02dhcdbd -> ../init.d/dhcdbd

lrwxrwxrwx 1 root root 17 Feb  9  2009 K02oddjobd -> ../init.d/oddjobd

lrwxrwxrwx 1 root root 17 Feb  9  2009 K05anacron -> ../init.d/anacron

lrwxrwxrwx 1 root root 13 Feb  9  2009 K05atd -> ../init.d/atd

lrwxrwxrwx 1 root root 16 Feb  9  2009 K05conman -> ../init.d/conman

lrwxrwxrwx 1 root root 14 Feb  9  2009 K05innd -> ../init.d/innd

lrwxrwxrwx 1 root root 19 Feb  9  2009 K05saslauthd -> ../init.d/saslauthd

lrwxrwxrwx 1 root root 14 Feb  9  2009 K10cups -> ../init.d/cups

lrwxrwxrwx 1 root root 19 Feb  9  2009 K10dc_server -> ../init.d/dc_server

lrwxrwxrwx 1 root root 16 Feb  9  2009 K10psacct -> ../init.d/psacct

lrwxrwxrwx 1 root root 19 Feb  9  2009 K12dc_client -> ../init.d/dc_client

lrwxrwxrwx 1 root root 13 Feb  9  2009 K15gpm -> ../init.d/gpm

lrwxrwxrwx 1 root root 13 Feb  9  2009 K20nfs -> ../init.d/nfs

lrwxrwxrwx 1 root root 15 Feb  9  2009 K20rwhod -> ../init.d/rwhod

lrwxrwxrwx 1 root root 18 Feb  9  2009 K30sendmail -> ../init.d/sendmail

lrwxrwxrwx 1 root root 22 Feb  9  2009 K30spamassassin -> ../init.d/spamassassin

lrwxrwxrwx 1 root root 19 Feb  9  2009 K34yppasswdd -> ../init.d/yppasswdd

lrwxrwxrwx 1 root root 15 Feb  9  2009 K35dhcpd -> ../init.d/dhcpd

lrwxrwxrwx 1 root root 18 Feb  9  2009 K35dhcrelay -> ../init.d/dhcrelay

lrwxrwxrwx 1 root root 13 Feb  9  2009 K35smb -> ../init.d/smb

lrwxrwxrwx 1 root root 19 Feb  9  2009 K35vncserver -> ../init.d/vncserver

lrwxrwxrwx 1 root root 17 Feb  9  2009 K35winbind -> ../init.d/winbind

lrwxrwxrwx 1 root root 20 Feb  9  2009 K50netconsole -> ../init.d/netconsole

lrwxrwxrwx 1 root root 16 Feb  9  2009 K50vsftpd -> ../init.d/vsftpd

lrwxrwxrwx 1 root root 20 Feb  9  2009 K69rpcsvcgssd -> ../init.d/rpcsvcgssd

lrwxrwxrwx 1 root root 16 Feb  9  2009 K73ypbind -> ../init.d/ypbind

lrwxrwxrwx 1 root root 14 Feb  9  2009 K74gfs2 -> ../init.d/gfs2

lrwxrwxrwx 1 root root 14 Feb  9  2009 K74nscd -> ../init.d/nscd

lrwxrwxrwx 1 root root 16 Feb  9  2009 K74ypserv -> ../init.d/ypserv

lrwxrwxrwx 1 root root 16 Feb  9  2009 K74ypxfrd -> ../init.d/ypxfrd

lrwxrwxrwx 1 root root 15 Feb  9  2009 K75netfs -> ../init.d/netfs

lrwxrwxrwx 1 root root 19 Feb  9  2009 K85mdmonitor -> ../init.d/mdmonitor

lrwxrwxrwx 1 root root 15 Feb  9  2009 K85mdmpd -> ../init.d/mdmpd

lrwxrwxrwx 1 root root 17 Feb  9  2009 K85rpcgssd -> ../init.d/rpcgssd

lrwxrwxrwx 1 root root 19 Feb  9  2009 K85rpcidmapd -> ../init.d/rpcidmapd

lrwxrwxrwx 1 root root 17 Feb  9  2009 K86nfslock -> ../init.d/nfslock

lrwxrwxrwx 1 root root 18 Feb  9  2009 K87mcstrans -> ../init.d/mcstrans

lrwxrwxrwx 1 root root 20 Feb  9  2009 K87multipathd -> ../init.d/multipathd

lrwxrwxrwx 1 root root 15 Feb  9  2009 K87named -> ../init.d/named

lrwxrwxrwx 1 root root 17 Feb  9  2009 K87portmap -> ../init.d/portmap

lrwxrwxrwx 1 root root 21 Feb  9  2009 K87restorecond -> ../init.d/restorecond

lrwxrwxrwx 1 root root 15 Feb  9  2009 K88pcscd -> ../init.d/pcscd

lrwxrwxrwx 1 root root 24 Feb  9  2009 K88wpa_supplicant -> ../init.d/wpa_supplicant

lrwxrwxrwx 1 root root 18 Feb  9  2009 K89netplugd -> ../init.d/netplugd

lrwxrwxrwx 1 root root 15 Feb  9  2009 K89rdisc -> ../init.d/rdisc

lrwxrwxrwx 1 root root 19 Feb  9  2009 K92ip6tables -> ../init.d/ip6tables

lrwxrwxrwx 1 root root 17 Feb  9  2009 K92ipvsadm -> ../init.d/ipvsadm

lrwxrwxrwx 1 root root 18 Feb  9  2009 K99cpuspeed -> ../init.d/cpuspeed

lrwxrwxrwx 1 root root 22 Feb  9  2009 K99lvm2-monitor -> ../init.d/lvm2-monitor

lrwxrwxrwx 1 root root 25 Feb  9  2009 K99readahead_later -> ../init.d/readahead_later

lrwxrwxrwx 1 root root 23 Feb  9  2009 S00microcode_ctl -> ../init.d/microcode_ctl

lrwxrwxrwx 1 root root 17 Feb  9  2009 S03sysstat -> ../init.d/sysstat

lrwxrwxrwx 1 root root 25 Feb  9  2009 S04readahead_early -> ../init.d/readahead_early

lrwxrwxrwx 1 root root 15 Feb  9  2009 S05kudzu -> ../init.d/kudzu

lrwxrwxrwx 1 root root 18 Feb  9  2009 S08iptables -> ../init.d/iptables

lrwxrwxrwx 1 root root 17 Feb  9  2009 S10network -> ../init.d/network

lrwxrwxrwx 1 root root 16 Feb  9  2009 S11auditd -> ../init.d/auditd

lrwxrwxrwx 1 root root 16 Feb  9  2009 S12syslog -> ../init.d/syslog

lrwxrwxrwx 1 root root 20 Feb  9  2009 S13irqbalance -> ../init.d/irqbalance

lrwxrwxrwx 1 root root 20 Feb  9  2009 S22messagebus -> ../init.d/messagebus

lrwxrwxrwx 1 root root 16 Feb  9  2009 S28autofs -> ../init.d/autofs

lrwxrwxrwx 1 root root 15 Feb  9  2009 S44acpid -> ../init.d/acpid

lrwxrwxrwx 1 root root 14 Feb  9  2009 S55sshd -> ../init.d/sshd

lrwxrwxrwx 1 root root 16 Feb  9  2009 S56xinetd -> ../init.d/xinetd

lrwxrwxrwx 1 root root 14 Feb  9  2009 S58ntpd -> ../init.d/ntpd

lrwxrwxrwx 1 root root 15 Feb  9  2009 S90crond -> ../init.d/crond

lrwxrwxrwx 1 root root 13 Feb  9  2009 S90xfs -> ../init.d/xfs

lrwxrwxrwx 1 root root 22 Feb  9  2009 S97yum-updatesd -> ../init.d/yum-updatesd

lrwxrwxrwx 1 root root 22 Feb  9  2009 S98avahi-daemon -> ../init.d/avahi-daemon

lrwxrwxrwx 1 root root 19 Feb  9  2009 S98haldaemon -> ../init.d/haldaemon

lrwxrwxrwx 1 root root 19 Feb  9  2009 S99firstboot -> ../init.d/firstboot

lrwxrwxrwx 1 root root 11 Feb  9  2009 S99local -> ../rc.local

[root@sulinux ~]#

 

 

 

 

이 디렉토리내에 존재하는 파일은 모두 링크파일들이다.

 

 

 

 그리고 이 파일들은 거의 대부분 /etc/rc.d/init.d/디렉토리에 있는 파일로 링크되어 있는 링크파일들이다.

 

 

 

 즉 실제 실행될 링크파일은 /etc/rc.d/init.d/디렉토리에 존재한다는 의미이다.

 

 

 

 이것은 위의 디렉토리뿐아니라 /etc/rc.d/rcN.d/의 모든 디렉토리에 동일하게 적용되는 것이다.

 

 

 

 , 이제 우리는 /etc/rc.d/rcN.d/디렉토리들에 존재하는 위와 같은 파일들을 읽을 수 있어야 한다.

 

 

 

 이 디렉토리에 존재하는 파일들은 다음과 같은 특징을 가지고 있다.

 

 

 

 부팅과정의 완벽한 이해를 위하여 다음 5가지를 이해해야 한다.

 

 

 

 

 

① 이 디렉토리에는 각각의 부팅레벨에 따라 시스템 부팅시에 자동실행될 서비스(데몬)들에 대한 설정이다.

 

 

 

 

 

② 이 디렉토리에 존재하는 모든 파일들은 /etc/rc.d/init.d/디렉토리에 있는 파일을 원본으로 하는 링크파일들이다.

 

 

 

 

 

③ 이 디렉토리에는 K로 시작하는 파일과 S로 시작하는 파일이 있다.

 

 

 

 K로 시작하는 파일들은 해당 부팅레벨로 부팅시에 자동시작되지 않는 서비스들의 링크파일이다.

 

 

 

 S로 시작하는 파일들은 해당 부팅레벨로 부팅시에 자동시작되는 서비스들의 링크파일이다.

 

 

 

 

 

④ 이 디렉토리에 존재하는 파일명에서 K 또는 S다음의 숫자들은 실행될 순서를 의미한다.

 

 

 

 

 

⑤ 예외적으로 S99local /etc/rc.d/rc.local파일을 원본으로 하는 링크파일로서 2, 3, 4, 5번부팅레벨에서만 실행되도록 되어있다.

 

 

 

 그리고 1번 부팅레벨에서만 실행되는 /etc/rc.d/rc1.d/S99single, 6번 부팅레벨에서만 실행되는 /etc/rc.d/rc6.d/S01reboot이 있다는 것도 함께 알아두면 좋다.

 

 

 

 

 

그리고 이 단계의 마지막에 항상 실행되는 S99local에 의해 /etc/rc.d/rc.local파일은  2,3,4,5번 각 실행레벨에서 맨 마지막 단계에 꼭 한번 실행되는 파일이다.

 

 

 

  /etc/rc.d/rc.local파일은 각 사용자들이 부팅시에 자동으로 실행하고자하는 프로그램들을 설정하거나 스크립트를 설정해두는 파일이다.

 

 

 

 예를들어 APACHE MYSQL등을 소스로 직접 컴파일하여 설치한 후에 부팅시마다 매번 자동실행 설정을 하는 곳이 바로 이 파일이다.

 

 

 

 다음은 /etc/rc.d/rc.local파일의 실제 예이다.

 

 

 

 

 

[root@sulinux ~]#cat /etc/rc.d/rc.local

#!/bin/sh

touch /var/lock/subsys/local

 

/usr/local/apache/bin/apachectl start

/usr/local/mysql/bin/mysql_safe &

/usr/local/proftpd/sbin/proftpd

 

[root@sulinux ~]#

 

 

 

 

위의 설정은 시스템부팅시에 소스로 직접컴파일하여 설치했던 apache, mysql, proftpd 응용프로그램들을 자동실행하기 위한 설정내용이다.

 

 

 

 따라서 만약 시스템관리자들이 리눅스서버에 새로 설치한 툴이나 프로그램을 매번 부팅때마다 자동으로 실행시키고자 한다면 이 파일의 맨 마지막에 원하는 실행명령을 넣어두면 된다.

 

 

 

 

 

이번 단계의 부팅과정 내용들을 정리해 보면 다음과 같다.

 

 

 

 각 부팅레벨에 따라서 /etc/rc.d/rcN.d/디렉토리의 스크립트파일들이 각각 실행된다.

 

 

 

 이 디렉토리에 있는 스크립트파일들은 링크파일로서 실제 원본파일은 /etc/rc.d/init.d/디렉토리에 존재한다.

 

 

 

 이 디렉토리에 존재하는 각각의 파일들은 각각의 서비스(데몬)들을 실행시키기 위한 스크립트파일들이다.

 

 

 

 

 

따라서 웬만한 서비스들은 모두 이 단계에서 실행된다.

 

 

 

 따라서 이 단계 이후부터는 시스템의 모든 서비스들이 대부분 실행되어 있다.

 

관련자료

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

공지사항


뉴스광장


  • 현재 회원수 :  60,080 명
  • 현재 강좌수 :  36,013 개
  • 현재 접속자 :  282 명