๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Linux

System V init vs Systemd (๋Ÿฐ๋ ˆ๋ฒจvsํƒ€๊ฒŸ)

๋ฐ˜์‘ํ˜•

System V init์€ init ํ”„๋กœ์„ธ์Šค์™€ /etc/inittab ํŒŒ์ผ, ์ผ๋ จ์˜ ์…ธ ์Šคํฌ๋ฆฝํŠธ๋กœ ๊ตฌ์„ฑ๋œ๋‹ค. init ํ”„๋กœ์„ธ์Šค๋Š” ์ปค๋„์ด ์‹คํ–‰๋œ ์งํ›„ ์ฒ˜์Œ์œผ๋กœ ์‹คํ–‰๋˜๋Š” ํ”„๋กœ์„ธ์Šค์ด๊ณ , /etc/inittab์€ ๋ชจ๋“  ์‹œ์ž‘ ํ™œ๋™์„ ๊ฐ๋…ํ•˜๋Š” ํŒŒ์ผ์ด๋ฉฐ, ๊ฐ์ข… ์…ธ ์Šคํฌ๋ฆฝํŠธ๋Š” ๊ฐ๊ฐ ํ•ด๋‹น ์„œ๋น„์Šค๋ฅผ ์‹œ์ž‘ํ•œ๋‹ค. 

System V init์€ ์›๋ž˜ 1980๋…„๋Œ€ ์ค‘๋ฐ˜ AT&T์—์„œ ์œ ๋‹‰์Šค ์‹œ์Šคํ…œ V์šฉ์œผ๋กœ ๊ฐœ๋ฐœ๋˜์—ˆ๋‹ค. ๋‹น์‹œ ์œ ๋‹‰์Šค ์‹œ์Šคํ…œ์€ ๋„คํŠธ์›Œํฌ ์ธํ„ฐํŽ˜์ด์Šค์˜ ์‹œ์ž‘๊ณผ ์—ฌ๊ธฐ์— ์—ฐ๊ฒฐ๋˜๋Š” ์„œ๋น„์Šค๋“ค์„ ์ฒ˜์Œ์œผ๋กœ ํ†ตํ•ฉํ–ˆ๋‹ค. 

System V init์—์„œ๋Š” ์ผ๋ จ์˜ ์„œ๋น„์Šค๊ฐ€ ์ด๋ฅธ๋ฐ” ๋Ÿฐ๋ ˆ๋ฒจ(runlevel)์— ์ง€์ •๋œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋ฉ€ํ‹ฐ ์œ ์ € ๋ชจ๋“œ์šฉ ๋Ÿฐ๋ ˆ๋ฒจ์€ ๊ธฐ๋ณธ์  ์‹œ์Šคํ…œ ์„œ๋น„์Šค, ๋„คํŠธ์›Œํฌ ์ธํ„ฐํŽ˜์ด์Šค, ๋„คํŠธ์›Œํฌ ์„œ๋น„์Šค๋ฅผ ์‹œ์ž‘ํ•œ๋‹ค. ์‹ฑ๊ธ€ ์œ ์ € ๋ชจ๋“œ์—์„œ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ๋„คํŠธ์›Œํฌ ์ธํ„ฐํŽ˜์ด์Šค๋‚˜ ์„œ๋น„์Šค๊ฐ€ ์‹œ์ž‘๋˜์ง€ ์•Š์€ ์ฑ„ ์‹œ์Šคํ…œ ์ฝ˜์†”์—์„œ ๋กœ๊ทธ์ธํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ธฐ๋ณธ ๋ฆฌ๋ˆ…์Šค ์‹œ์Šคํ…œ์ด ์‹œ์ž‘๋œ๋‹ค.

System V init ์‹œ์Šคํ…œ์ด ๋ฉ”๋ชจ๋ฆฌ์— ์˜ฌ๋ผ๊ฐ€ ์‹คํ–‰๋œ ๋’ค์—๋Š” reboot, shutdown, init ๋“ฑ์˜ ๋ช…๋ น์„ ์‚ฌ์šฉํ•˜์—ฌ ๋Ÿฐ๋ ˆ๋ฒจ์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค. 

System V init ์Šคํฌ๋ฆฝํŠธ๋Š” ํŠน์ • ์ˆœ์„œ๋Œ€๋กœ ์‹คํ–‰๋˜๋„๋ก ์„ค์ •๋˜์–ด ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ ํ•œ ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ๋งˆ๋ฌด๋ฆฌ๋˜์–ด์•ผ๋งŒ ๋‹ค๋ฅธ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋งŒ์•ฝ ํ•œ ์„œ๋น„์Šค๊ฐ€ ์‹คํŒจํ•˜๋ฉด ์ด ์„œ๋น„์Šค๊ฐ€ ์ž๋™์œผ๋กœ ์žฌ์‹œ์ž‘ํ•˜๋Š” ๊ทœ์น™ ๊ฐ™์€ ๊ฒƒ์€ ์ง€์›ํ•˜์ง€ ์•Š๋Š”๋‹ค.

์ตœ์‹  ๋ฆฌ๋ˆ…์Šค ๋ฐฐํฌํŒ์€ init ์‹œ์Šคํ…œ์˜ ๋Œ€์•ˆ ์ค‘ systemd์„ ์‚ฌ์šฉํ•œ๋‹ค. 
CentOS7 ๋ฒ„์ „ ์ดํ›„์—๋Š” runlevel์˜ ๊ฐœ๋…์ด Systemd target์œผ๋กœ ๋Œ€์ฒด๋˜์—ˆ๋‹ค.

์ด์ „ ๋ฒ„์ „์˜ ๋ฆฌ๋ˆ…์Šค ๋ฐฐํฌํŒ๋“ค์€ SysV Init ๋˜๋Š” Upstart๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ, ์ด๋Ÿฌํ•œ Init ์‹œ์Šคํ…œ๋“ค์ด ํ…์ŠคํŠธ๋ชจ๋“œ, ๋ฉ€ํ‹ฐ์œ ์ €๋ชจ๋“œ, GUI ์‹œ์Šคํ…œ์˜ Runlevel ์„ธํŠธ๋ฅผ ์ œ๊ณตํ•˜๋Š” ๋ฐ˜๋ฉด, Systemd๋Š” Target ์œ ๋‹›์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ถ€ํŒ…, ์„œ๋น„์Šค ๊ด€๋ฆฌ, ๋™๊ธฐํ™” ํ”„๋กœ์„ธ์Šค๋ฅผ ์ง„ํ–‰ํ•œ๋‹ค. ๋””ํดํŠธ ๋ถ€ํŠธ ํƒ€๊ฒŸ์€ /etc/systemd/system/default.target ์— ์ง€์ •๋œ๋‹ค. 

ํƒ€๊นƒ์€ ๋Ÿฐ๋ ˆ๋ฒจ์ด ์ต์ˆ™ํ•œ ์‚ฌ๋žŒ๋“ค์„ ์œ„ํ•ด System V init ๋Ÿฐ๋ ˆ๋ฒจ๊ณผ์˜ ํ˜ธํ™˜์„ฑ์„ ์œ ์ง€ํ•˜๊ณ  ์žˆ๋‹ค. ๊ฐ€๋ น, graphical.target์€ runlevel5๋กœ ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ๋‹ค. ํ•˜์ง€๋งŒ ํƒ€๊นƒ์ด ๋Ÿฐ๋ ˆ๋ฒจ๋ณด๋‹ค ์ข…๋ฅ˜๊ฐ€ ๋” ๋งŽ๊ณ , ๋”์šฑ ๋‹ค์–‘ํ•œ ์œ ๋‹›์„ ํ•œ์ธต ๋” ์„ธ๋ถ€์ ์œผ๋กœ ๊ด€๋ฆฌํ•œ๋‹ค. 

systemd๋Š” ์‹œ์Šคํ…œ์ด ์‹œ์ž‘๋˜๋ฉด ์ข…์† ์š”์†Œ๊ฐ€ ๋งŒ์กฑ๋˜๋Š” ๊ธฐ๋ณธ ํƒ€๊นƒ(๋ฐ์Šคํฌํ†ฑ์€ graphical.target, ์„œ๋ฒ„๋“ค ๋Œ€๋ถ€๋ถ„์€ multi-user.target)์˜ ๋ชจ๋“  ์„œ๋น„์Šค ๋˜ํ•œ ์‹œ์ž‘ํ•œ๋‹ค. ์ด ๊ธฐ๋Šฅ์œผ๋กœ ์ธํ•ด ๋ถ€ํŠธ ํ”„๋กœ์„ธ์Šค์˜ ์†๋„๊ฐ€ ๋†’์•„์ง„๋‹ค. ์–ด๋–ค ํ•œ ์„œ๋น„์Šค๊ฐ€ ๋ฒ„๋ฒ…๋Œ€๋”๋ผ๋„ ๋‹ค๋ฅธ ์„œ๋น„์Šค๋“ค์€ ๊ทธ ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. 

systemd์—์„œ๋Š” cgroup์„ ์‚ฌ์šฉํ•˜๋ฉด ์„œ๋น„์Šค๊ฐ€ ์‹œ์Šคํ…œ ๋ฆฌ์†Œ์Šค๋ฅผ ์–ผ๋งŒํผ ์†Œ๋น„ํ•˜๋Š”์ง€ ์กฐ์ ˆํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋ฉ”๋ชจ๋ฆฌ๋‚˜ CPU๋“ฑ์˜ ๋ฆฌ์†Œ์Šค๋ฅผ ํ•˜๋‚˜์˜ ์„œ๋น„์Šค๊ฐ€ ์–ผ๋งˆ๋‚˜ ์ ์œ ํ• ์ง€ ์ œํ•œํ•  ์ˆ˜ ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋งˆ๊ตฌ์žก์ด๋กœ ์ž์‹ ํ”„๋กœ์„ธ์Šค๋ฅผ ๋งŒ๋“ค์–ด๋‚ด๋Š” ๋Ÿฐ์–ด์›จ์ด(runaway) ํ”„๋กœ์„ธ์Šค๋‚˜ ์„œ๋น„์Šค๋Š” ํ—ˆ์šฉ๋œ ๊ฒƒ ์ด์ƒ์„ ์†Œ๋น„ํ•  ์ˆ˜ ์—†๋‹ค.

systemd๊ฐ€ ์ ์šฉ๋œ ๋ฆฌ๋ˆ…์Šค ์‹œ์Šคํ…œ์ด ์‹œ์ž‘๋˜๋ฉด, ์ฒซ ๋ฒˆ์งธ๋กœ ์‹œ์ž‘ํ•˜๋Š” ํ”„๋กœ์„ธ์Šค(PID 1)๋Š” systemd ๋ฐ๋ชฌ์ด ๋œ๋‹ค.(init ๋ฐ๋ชฌ ์•„๋‹˜)
์ดํ›„์˜ systemd ์„œ๋น„์Šค๋ฅผ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ๊ธฐ๋ณธ ๋ช…๋ น์€ systemctl์ด๋‹ค.

 

 


 

Sysv runlevel vs systemd targets

Systemd target Sysv Runlevel Desc Old Command New command
runevel0.target
poweroff.target
0 Power off init 0 systemctl isolate poweroff.targe
runlevel1.target
rescue.target
1 ์ด๋จธ์ „์‹œ ๋ชจ๋“œ ๋ถ€ํŒ…
(Single user mode)
init 1 systemctl isolate rescue.target
runlevel2.target
multi-user.target
2 CLI
๋„คํŠธ์›Œํฌ ์ธํ„ฐํŽ˜์ด์ŠคX
init 2 systemctl isolate runlevel2.target
runlevel3.target
multi-user.target
3 CLI init 3 systemctl isolate runlevel3.target
runlevel4.target
multi-user.target
4 CLI
ํŠน์ˆ˜๋ชฉ์ 
init 4 systemctl isolate runlevel4.target
runlevel5.target
graphical.target
5 GUI init 5 systemctl isolate graphical.target
runlevel6.target
reboot.target
6 Reboot init 6 systemctl isolate reboot .target

* Single User-mode

Single-user mode is a mode in which a multiuser computer operating system boots into a single superuser. It is mainly used for maintenance of multi-user environments such as network servers. Some tasks may require exclusive access to shared resources, for example running fsck on a network share. This mode can also be used for security purposes – network services are not run, eliminating the possibility of outside interference. On some systems a lost superuser password can be changed by switching to single-user mode, but not asking for the password in such circumstances is viewed as a security vulnerability.


An important run level is single user mode (run level 1), in which only the system administrator is using the machine and as few system services, including logins, as possible are running. Single user mode is necessary for a few administrative tasks, such as running fsck on a /usr partition, since this requires that the partition be unmounted, and that can't happen, unless just about all system services are killed.

A running system can be taken to single user mode by using telinit to request run level 1. At bootup, it can be entered by giving the word single or emergency on the kernel command line: the kernel gives the command line to init as well, and init understands from that word that it shouldn't use the default run level. (The kernel command line is entered in a way that depends on how you boot the system.)

Booting into single user mode is sometimes necessary so that one can run fsck by hand, before anything mounts or otherwise touches a broken /usr partition (any activity on a broken filesystem is likely to break it more, so fsck should be run as soon as possible).

The bootup scripts init runs will automatically enter single user mode, if the automatic fsck at bootup fails. This is an attempt to prevent the system from using a filesystem that is so broken that fsck can't fix it automatically. Such breakage is relatively rare, and usually involves a broken hard disk or an experimental kernel release, but it's good to be prepared.

As a security measure, a properly configured system will ask for the root password before starting the shell in single user mode. Otherwise, it would be simple to just enter a suitable line to LILO to get in as root. (This will break if /etc/passwd has been broken by filesystem problems, of course, and in that case you'd better have a boot floppy handy.)


 

๋ชจ๋“  Systemd ํƒ€๊ฒŸ ๋ฆฌ์ŠคํŒ…ํ•˜๊ธฐ

#list all loaded units in any state
systemctl list-units --type target --all



์‚ฌ์šฉ์ค‘์ธ ๋Ÿฐ๋ ˆ๋ฒจ ํ™•์ธ

runlevel

 

๋””ํดํŠธ ๋ถ€ํŠธ ํƒ€๊ฒŸ ๋ณ€๊ฒฝํ•˜๊ธฐ

#Find which target unit is used by default
systemctl get-default

#To change boot target to the text mode
systemctl set-default multi-user.target

#GUI: systemctl set-default graphical.target

#Reboot the system
systemctl reboot

 

๋ฐ˜์‘ํ˜•
Archives
Notice
Link
Visits
Today
Yesterday