Raspberry Pi_Kor_20.3.5 run level 무관 booting 자동 실행

20.3.5 run level 무관 booting 자동 실행

명령이나 script가 특정 run level과 무관하게 항상 실행되도록 하려면 “/etc/rc.local” 파일에 등록하면 된다. 여기에 등록된 script는 통상 시스템이 정상 작동하는 상태인 run level “2” ~”5″ 상태에서만 실행된다.

다음은 “/etc/rc.local” 파일의 내용에 대한 사례이다.

Raspberry Pi_Kor_20.3.4 run level 연동 booting 자동 실행

20.3.4 run level 연동 booting 자동 실행

20.3.4.1 init script 등록 원리

init script를 작성하여 “/etc/init.d”에 저장한 다음에는 해당 script가 run level에 따라 자동 실행되도록 시스템에 등록해야 한다. 시스템에 등록한다는 것을 시스템적으로 자세히 살펴보면 원본 script 파일에 대해서 link를 만드는 것이라는 것을 알수 있다. 즉 link를 실행하면 원본 script 파일이 실행되는 것이다.

시스템에서 run level에 따라 자동 실행하는 script는 “/etc/rc0.d/” ~ “/etc/rc6.d/” directory 밑에 등록되어 있다. 즉 run level에 따라서 실행하고 싶은 script는 link를 만들어서 각각의 directory 밑에 넣어 두면 등록이 된다.

Raspberry Pi_Kor_20.3.3 init script 작성

20.3.3 init script 작성

20.3.3.1 init script의 의미

시스템이 booting하거나 shutdown하는 과정에서 사용되는 script를 “init script”라고 한다. 모든 init script는 기본적으로 “/etc/init.d/” directory 밑에 넣어 두어야 한다.

init script에는 사용하는 용도에 따라 다음과 같이 여러 가지 종류가 있다.

n run level에 따라 특정 작업을 다르게 하기 위한 script

시스템 관리를 위해 필요한 다양한 작업을 할 수 있다.

Raspberry Pi_Kor_20.3.2 booting sequence

20.3.2 booting sequence

시스템이 처음 시작할 때는 일정한 순서에 따라 정해진 작업을 실행하게 되는데, 이런 순서를 “booting sequence”라고 한다. 다음에는 booting sequence에 대한 기본 체계와 이를 이용하여 booting할 때 필요한 작업을 자동으로 실행하는 방법에 대해서 설명하도록 하겠다.

Raspberry Pi_Kor_20.3.1 run level

20.3 init script를 통한 자동 실행

20.3.1 run level

20.3.1.1 run level 정의

Linux에서는 시스템이 처음 시작하거나 종료할 때 사전에 지정된 모든 작업을 처리하거나, 때때로 시스템 복구작업을 할 때 다른 사용자들이 사용하지 못하게 할 필요가 있다. 이렇게 특정 단계에서 시스템을 사용할 수 있는 사용자를 제한하거나, 특정 환경에서 실행할 수 있는 명령이나 프로그램의 종류를 구분하기 위해서 “run level”이라는 도구를 사용한다.

Raspberry Pi_Eng_20.3.5 Automatic Run regardless of Run Level at Booting

20.3.5 Automatic Run regardless of Run Level at Booting

If you want the command or script to always run regardless of run level, you register it in the “/etc/rc.local” file. The script registered here is executed only in run level “2” ~ “5” which is a normal operation status of the system.

Here is an example for the contents of the file “/etc/rc.local”.

Raspberry Pi_Eng_20.3.4 Automatic Execution by Run Level at Booting

20.3.4 Automatic Execution by Run Level at Booting

20.3.4.1 Principles of Registering Init Script

After you have created an init script and saved it in “/etc/init.d”, you need to register it on the system so that it runs automatically according to the run level. If we systematically look into registering on the system, you can see that it is creating a link to the original script file. In other words, running the link will run the original script file.

Raspberry Pi_Eng_20.3.3 Creating Init Script

20.3.3 Creating Init Script

20.3.3.1 Meaning of Init Script

The script that is used when the system boots or shuts down is called “init script”. All init scripts basically should be put under “/etc/init.d/” directory.

There are several types of init scripts as follows according to their usage:

Raspberry Pi_Eng_20.3.2 Booting Sequence

20.3.2 Booting Sequence

When the system first starts up, it executes certain defined tasks in a certain order. This sequence is called “booting sequence”. Next, we will explain the basic framework of booting sequence and how to use it to automatically execute the necessary tasks in booting.

20.3.2.1 Booting Framework

Raspberry Pi_Eng_20.3.1 Run Level

20.3 Automatic Run with Init Script

20.3.1 Run Level

20.3.1.1 Definition of Run Level

On Linux, you need to process all pre-specified tasks when the system first starts or shuts down, or sometimes need to prevent others from using it when performing system recovery tasks. A tool called “run level” is used to limit who can use the system in a certain step or to identify the types of commands or programs that can run in a particular environment.