Runlevel
A runlevel is a mode of operation in the computer operating systems that implement Unix System V-style initialization. Conventionally, seven runlevels exist, numbered from zero to six; though up to ten, from zero to nine, may be used. S is sometimes used as a synonym for one of the levels. Only one runlevel is executed on startup; run levels are not executed one after another, i.e. either the runlevel 2, 3 or 4 is executed, not more of them sequentially or in any other order.
Levels
- 0 - halt (DO NOT set initdefault to this)
- 시스템 종료를 의미합니다. 즉, 런레벨 0으로 변경하라는 명령을 내리면 시스템을 종료하는 것이죠.
- 1 - Single user mode
- 시스템 복원모드라고도 하며, 기본적으로 관리자 권한 쉘을 얻게 됩니다.
- 주로, 파일시스템을 점검하거나 관리자 암호를 변경할 때 사용합니다.
- 2 - Multiuser mode, without NFS (The same as 3, if you do ot have networking)
- NFS(Network File System)을 지원하지 않는 다중 사용자 모드입니다.
- 네트워크를 사용하지 않는 텍스트 유저모드라고 할 수 있죠.
- 3 - Full muliuser mode
- 일반적인 쉘 기반의 인터페이스를 가진 다중 사용자 모드입니다.
- 쉽게 말하면 그래픽 유저 모드가 아닌 '텍스트 유저 모드'입니다.
- 4 - unused
- 4번은 쓰이지 않습니다. 기본적으로는 사용되지 않지만, 임의로 정의해서 사용할 수 있는 레벨입니다.
- 5 - X11
- 기본적으로는 level 3과 같습니다. 다른 점은 '그래픽 유저 모드' 라는것!!!
- 6 - reboot (DO NOT set initdefault to this)
- 시스템 재부팅을 의미합니다. 런레벨 6으로 변경하라는 명령을 내리면 시스템을 재부팅 하죠.
Run-Level | 설명 | init Run-Level | systemd Run-Level |
0 | Halt (종료 모드) | runlevel0.target | poweroff.target |
1 | Single-user (단일 사용자 모드) | runlevel1.target | rescue.target |
2 | Multi-user (다중 사용자 모드) | runlevel2.target | multi-user.target |
3 | Full Multi-user | runlevel3.target | |
4 | unused | runlevel4.target | |
5 | Graphic-user (그래픽 사용자 모드) | runlevel5.target | graphical.target |
6 | Reboot (재구동) | runlevel6.target | reboot.target |
Run Command
Init 프로세스가 런 레벨을 결정하면, 각각의 런 레벨에 맞는 서비스들을 실행해야 한다. 이때 각각 런 레벨 별 실행해야하는 서비스들의 디렉토리 경로는 다음과 같다.
- 레벨 S - /etc/rcS.d
- 레벨 0 - /etc/rc0.d
- 레벨 1 - /etc/rc1.d
- 레벨 2 - /etc/rc2.d
- 레벨 3 - /etc/rc3.d
- 레벨 4 - /etc/rc4.d
- 레벨 5 - /etc/rc5.d
- 레벨 6 - /etc/rc6.d
여기서 rc는 Run Command의 약자라고 한다.
Check run level in script
Unix System V-style implement conventionally 7 runlevels. This runlevel implementation vary across many Linux distribution. Usually runlevel 0, 1 and 6 are the same.
- 0 - halt
- 1 - single mode
- 6 - reboot
Debian distribution has it runlevel 2-5 dedicated to full multi-user with graphical managers and console login whereas Redhat/Fedora has two separate runlevels for each mode. To check the runlevel of you system you can use runlevel command with no arguments:
another way to check your runlevel is to use:
Bash script:
if [[ $(runlevel | awk '{print $2}') != 1 ]]; then
echo 'The runlevel must be 1'
echo ' sudo init 1'
exit 1
fi