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