01 o n dmesg more varlogboot log user










01 리눅스 시스템의 부팅 o 부팅 후 메시지 확인 n 부팅시 출력된 메시지는 dmesg 명령이나 more /var/log/boot. log 명령으로 확인 가능 [user 1@localhost ~]$ dmesg | more [ 0. 000000] Initializing cgroup subsys cpuset [ 0. 000000] Initializing cgroup subsys cpuacct [ 0. 000000] Linux version 3. 11. 2 -201. fc 19. x 86_64 (mockbuild@bkernel 01. phx 2. fe doraproject. org) (gcc version 4. 8. 1 20130603 (Red Hat 4. 8. 1 -1) (GCC) ) #1 SMP Fr i Sep 27 19: 20: 55 UTC 2013 [ 0. 000000] Command line: BOOT_IMAGE=/vmlinuz-3. 11. 2 -201. fc 19. x 86_64 root=/de v/mapper/fedora-root ro rd. lvm. lv=fedora/swap rd. md=0 rd. dm=0 vconsole. keymap=us rd. luks=0 vconsole. font=latarcyrheb-sun 16 rd. lvm. lv=fedora/root rhgb quiet LANG =ko_KR. UTF-8 [ 0. 000000] Disabled fast string operations [ 0. 000000] e 820: BIOS-provided physical RAM map: (생략)


02 systemd 서비스 o 기존 init 프로세스 n n n init 프로세스는 PID가 1번인 프로세스로 모든 프로세스의 조상 역할 init 프로세스는 부팅 과정에서 각종 서비스를 제공하는 셸 스크립트 파일을 실행 init 프로세스 설정 파일은 /etc/inittab [user 1@localhost ~]$ cd /etc [user 1@localhost etc]$ cat inittab # inittab is no longer used when using systemd. # # ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # # Ctrl-Alt-Delete is handled by /etc/systemd/system/ctrl-alt-del. target # # systemd uses 'targets' instead of runlevels. By default, there are two main targets: # # multi-user. target: analogous to runlevel 3 # graphical. target: analogous to runlevel 5 # # To set a default target, run: # # ln -s /lib/systemd/system/<target name>. target /etc/systemd/system/default. target # [user 1@localhost etc]$

02 systemd 서비스 o 기존 init 프로세스 n n n init 프로세스가 실행하는 스크립트 파일은 /etc/rc. d/init. d 디렉터리에 위치 /etc/rc*. d 디렉터리에 있는 파일들은 /etc/rc. d/init. d 파일에 대한 심벌릭 링크 현재는 systemd 서비스에 의해 대부분 대체되고 일부 파일만 유지 [user 1@localhost etc]$ cd /etc/rc. d/init. d [user 1@localhost init. d]$ ls README ebtables functions netcf-transaction [user 1@localhost init. d]$ n netconsole network /etc/rc. d/init. d 디렉터리의 README 파일: 전통적인 init 스크립트가 systemd 기반 으로 바뀌었다는 것 [user 1@localhost init. d]$ cat README You are looking for the traditional init scripts in /etc/rc. d/init. d, and they are gone? Here's an explanation on what's going on: You are running a systemd-based OS where traditional init scripts have been replaced by native systemd services files. Service files provide very similar functionality to init scripts. To make use of service (생략)





02 systemd 서비스 o 동작 중인 유닛 출력하기 n 옵션이나 명령 없이 systemctl 명령만 사용하면 현재 동작 중 인 유닛이 출력 [user 1@localhost init. d]$ UNIT proc-sys. . . misc. automount sys-devi. . . ock-sr 0. device sys-devi. . . da-sda 1. device sys-devi. . . da-sda 2. device sys-devi. . . ock-sda. device sys-devi. . . db-sdb 1. device sys-devi. . . db-sdb 2. device sys-devi. . . ock-sdb. device sys-devi. . . dc-sdc 1. device sys-devi. . . dc-sdc 2. device sys-devi. . . ock-sdc. device (생략) systemctl LOAD loaded active loaded active loaded active ACTIVE SUB running plugged plugged plugged JOB DESCRIPTION Arbitrary Executable File VMware_Virtual_IDE_CDROM_D VMware_Virtual_S VMware_Virtual_S VMware_Virtual_S

02 systemd 서비스 o 전체 유닛 출력하기 : -a 옵션 n -a 옵션을 지정하면 전체 유닛이 출력 [user 1@localhost init. d]$ systemctl -a (생략) colord. service loaded active running Manage, Install and Gene crond. service loaded active running Command Scheduler cups. service loaded active running CUPS Printing Service dbus. service loaded active running D-Bus System Message Bus dm-event. service loaded inactive dead Device-mapper event daem dracut-shutdown. service loaded inactive dead Restore /run/initramfs ebtables. service loaded inactive dead SYSV: Ethernet Bridge fi emergency. service loaded inactive dead Emergency Shell (생략)
![02 systemd 서비스 o 특정 유닛 출력하기 : -t 옵션 [user 1@localhost init. d]$ 02 systemd 서비스 o 특정 유닛 출력하기 : -t 옵션 [user 1@localhost init. d]$](http://slidetodoc.com/presentation_image_h/834c9d1d08c9e87e6d5041efe2a9990e/image-20.jpg)
02 systemd 서비스 o 특정 유닛 출력하기 : -t 옵션 [user 1@localhost init. d]$ systemctl -t service UNIT LOAD ACTIVE SUB JOB DESCRIPTION abrt-ccpp. service loaded active exited Install ABRT coredump hook abrt-oops. service loaded active running ABRT kernel log watcher abrt-vmcore. service loaded active exited Harvest vmcores for ABRT abrt-xorg. service loaded active running ABRT Xorg log watcher abrtd. service loaded active running ABRT Automated Bug Reportin accounts-daemon. service loaded active running Accounts Service atd. service loaded active running Job spooling tools auditd. service loaded active running Security Auditing Service avahi-daemon. service loaded active running Avahi m. DNS/DNS-SD Stack bluetooth. service loaded active running Bluetooth service (생략) o 유닛의 상태 확인하기 : status [user 1@localhost init. d]$ systemctl status bluetooth. service - Bluetooth service Loaded: loaded (/usr/lib/systemd/system/bluetooth. service; enabled) Active: active (running) since Fri, 2013 -06 -07 17: 24: 34 KST Main PID: 555 (bluetoothd) CGroup: name=systemd: /system/bluetooth. service └ 555 /usr/sbin/bluetoothd -n (생략) [user 1@localhost init. d]$
![02 systemd 서비스 o 유닛 서비스 정지하기 : stop [root@localhost ~]# systemctl stop bluetooth. 02 systemd 서비스 o 유닛 서비스 정지하기 : stop [root@localhost ~]# systemctl stop bluetooth.](http://slidetodoc.com/presentation_image_h/834c9d1d08c9e87e6d5041efe2a9990e/image-21.jpg)
02 systemd 서비스 o 유닛 서비스 정지하기 : stop [root@localhost ~]# systemctl stop bluetooth. service [root@localhost ~]# systemctl status bluetooth. service - Bluetooth service Loaded: loaded (/usr/lib/systemd/system/bluetooth. service; enabled) Active: inactive (dead) since Fri, 2013 -06 -07 16: 00 KST; 12 s ago Process: 555 Exec. Start=/usr/sbin/bluetoothd -n (code=exited, status=0/ SUCCESS) CGroup: name=systemd: /system/bluetooth. service Jun 07 15: 59: 56 localhost. localdomain bluetoothd[555]: Endpoint unregistered: . . . Jun 07 15: 59: 57 localhost. localdomain bluetoothd[555]: Endpoint unregistered: . . . Jun 07 15: 59 localhost. localdomain bluetoothd[555]: Stopping SDP server Jun 07 15: 59 localhost. localdomain bluetoothd[555]: Exit Jun 07 16: 00 localhost. localdomain systemd[1]: Stopped Bluetooth service. [root@localhost ~]# o 유닛 서비스 시작하기 : start [root@localhost ~]# systemctl start bluetooth. service [root@localhost ~]# systemctl is-active bluetooth. service active [root@localhost ~]#

02 systemd 서비스 o systemd와 런레벨 o 런레벨 변경하기 n n systemd에서 런레벨을 변경하는 것도 isolate 명령으로 간단히 해결 예: 런레벨 3로 변경 [root@localhost ~]# systemctl isolate multi-user. target o 또는 [root@localhost ~]# systemctl isolate runlevel 3. target [그림 8 -8] 런레벨 3 화면
![02 systemd 서비스 o 런레벨 변경하기 n 런레벨 5로 다시변경하기 [root@localhost ~]# systemctl isolate 02 systemd 서비스 o 런레벨 변경하기 n 런레벨 5로 다시변경하기 [root@localhost ~]# systemctl isolate](http://slidetodoc.com/presentation_image_h/834c9d1d08c9e87e6d5041efe2a9990e/image-23.jpg)
02 systemd 서비스 o 런레벨 변경하기 n 런레벨 5로 다시변경하기 [root@localhost ~]# systemctl isolate graphical. target [root@localhost ~]# systemctl isolate runlevel 5. target o init 명령으로 런레벨 변경하기 n init 명령으로 런레벨 변경 가능 [root@localhost ~]# cd /sbin [root@localhost ~]# ls -l /sbin/init lrwxrwxrwx. 1 root 22 10월 3 21: 45 init ->. . /lib/systemd [root@localhost ~]#

02 systemd 서비스 o init 명령으로 런레벨 변경하기 n init 명령만 입력하면 다음과 같이 출력 [root@localhost ~]# init [OPTIONS. . . ] {COMMAND} Send control commands to the init daemon. --help Show this help --no-wall Don't send wall message before halt/power-off/reboot Commands: 0 Power-off the machine 6 Reboot the machine 2, 3, 4, 5 Start runlevel. X. target unit 1, s, S Enter rescue mode q, Q Reload init daemon configuration u, U Reexecute init daemon [root@localhost ~]#

02 systemd 서비스 o telinit 명령으로 런레벨 변경하기 n telinit 명령을 실행하면 init 명령과 같은 결과가 출력 [root@localhost ~]# telinit [OPTIONS. . . ] {COMMAND} Send control commands to the init daemon. --help Show this help --no-wall Don't send wall message before halt/power-off/reboot Commands: 0 Power-off the machine 6 Reboot the machine 2, 3, 4, 5 Start runlevel. X. target unit 1, s, S Enter rescue mode q, Q Reload init daemon configuration u, U Reexecute init daemon [root@localhost ~]#


02 systemd 서비스 o 기본 런레벨 지정하기 n n n 예전: 부팅할 때 동작할 기본 런레벨은 예전에는 /etc/inittab 파일에 지정 현재: /etc/systemd/system 디렉터리 아래의 default. target으로 지정-> 다른 target 유닛에 대한 심벌릭 링크 예: 그래픽 모드(런레벨 5)로 기본 런레벨을 지정 n 예: 런레벨 3을 기본으로 지정 [root@localhost ~]# ln -sf /lib/systemd/system/graphical. target /etc/systemd/ system/default. target [root@localhost ~]# ln -sf /lib/systemd/system/multi-user. target /etc/systemd/ system/default. target n 런레벨 0이나 런레벨 6을 기본 런레벨로 지정하면 안됨 -> 왜? [root@localhost ~]# runlevel 5 현재 런레벨 확인하기 [root@localhost ~]# 확인은 runlevel 명령을 사용 n 현재 런레벨 o. S
![02 systemd 서비스 o 현재 런레벨 확인하기 n systemctl 명령으로 target을 확인 [root@localhost ~]# 02 systemd 서비스 o 현재 런레벨 확인하기 n systemctl 명령으로 target을 확인 [root@localhost ~]#](http://slidetodoc.com/presentation_image_h/834c9d1d08c9e87e6d5041efe2a9990e/image-28.jpg)
02 systemd 서비스 o 현재 런레벨 확인하기 n systemctl 명령으로 target을 확인 [root@localhost ~]# systemctl -t target UNIT LOAD ACTIVE SUB JOB DESCRIPTION basic. target loaded active Basic System cryptsetup. target loaded active Encrypted Volumes getty. target loaded active Login Prompts graphical. target loaded active Graphical Interface local-fs-pre. target loaded active Local File Systems (Pre) local-fs. target loaded active Local File Systems multi-user. target loaded active Multi-User network. target loaded active Network remote-fs. target loaded active Remote File Systems sockets. target loaded active Sockets swap. target loaded active Swap sysinit. target loaded active System Initialization syslog. target loaded active Syslog LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i. e. generalization of SUB = The low-level unit activation state, values depend on unit type. JOB = Pending job for the unit. 13 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'. [root@localhost ~]#



03 리눅스 시스템의 종료 o shutdown 한다는 메시지 보내고 종료하기 n n n 시스템을 종료할 때 shutdown 명령으로 메시지를 보낼 수 있음 사용자들이 메시지를 받고 정리할 시간이 필요하므로 시간을 now로 지 정하면 안 되고 특정 시간을 지정 예: 2분 후에 종료한다는 메시지 발송 [root@localhost ~]# shutdown -h +2 "System is going down in 2 min" [user 1@localhost ~]$ 사용자 출력 Broadcast o message from 터미널 root@localhost. localdomain (Sat, 2013 -06 -08 14: 25: 38 KST): System is going down in 2 min The system is going down for power-off at Sat, 2013 -06 -08 14: 27: 38 KST! o shutdown 명령으로 시스템 재시작하기: -r 옵션 사용 [root@localhost ~]# shutdown -r +3 Broadcast message from root@localhost. localdomain (Sat, 2013 -06 -08 14: 29: 35 KST): The system is going down for reboot at Sat, 2013 -06 -08 14: 32: 35 KST!
![03 리눅스 시스템의 종료 o shutdown 명령 취소하기: -c 옵션 [root@localhost ~]# shutdown -c 03 리눅스 시스템의 종료 o shutdown 명령 취소하기: -c 옵션 [root@localhost ~]# shutdown -c](http://slidetodoc.com/presentation_image_h/834c9d1d08c9e87e6d5041efe2a9990e/image-32.jpg)
03 리눅스 시스템의 종료 o shutdown 명령 취소하기: -c 옵션 [root@localhost ~]# shutdown -c n 앞의 3분 후 재시작 명령 취소할 경우 메시지 출력 Broadcast message from root@localhost. localdomain (Sat, 2013 -06 -08 14: 29: 43 KST): The system shutdown has been cancelled at Sat, 2013 -06 -08 14: 30: 42 KST! o shutdown 메시지만 보내기: -k 옵션 [root@localhost ~]# shutdown -k 2 Broadcast message from root@localhost. localdomain (Sat, 2013 -06 -08 14: 37: 19 KST): The system is going down for power-off at Sat, 2013 -06 -08 14: 39: 19 KST!
![03 리눅스 시스템의 종료 o 런레벨 변경하기 n 런레벨을 0으로 [root@localhost ~]# telinit 0 03 리눅스 시스템의 종료 o 런레벨 변경하기 n 런레벨을 0으로 [root@localhost ~]# telinit 0](http://slidetodoc.com/presentation_image_h/834c9d1d08c9e87e6d5041efe2a9990e/image-33.jpg)
03 리눅스 시스템의 종료 o 런레벨 변경하기 n 런레벨을 0으로 [root@localhost ~]# telinit 0 바꾸면 시스템이 종료 [root@localhost ~]# telinit 6 n 재시작하려면 런레벨을 6으로 변경 [root@localhost ~]# systemctl isolate runlevel 6. target o systemd로 종료하기 [root@localhost ~]# systemctl isolate runlevel 0. target [root@localhost ~]# systemctl isolate poweroff. target o systemd로 재시작하기 [root@localhost ~]# systemctl isolate reboot. target



04 데몬 프로세스 o o 데몬의 조상 : systemd와 커널 스레드 데몬 systemd 데몬 n n init을 대체한 데몬으로 대부분의 프로세스의 조상 프로세스 pstree 명령으로 확인 [root@localhost sbin]# pstree systemd─┬─Network. Manager─┬─dhclient │ └─3*[{Network. Manager}] ├─2*[abrt-watch-log] ├─abrtd ├─accounts-daemon───{accounts-daemon} ├─at-spi-bus-laun─┬─dbus-daemon───{dbus-daemon} │ └─3*[{at-spi-bus-laun}] ├─at-spi 2 -registr───{at-spi 2 -registr} ├─atd ├─auditd─┬─audispd─┬─sedispatch │ │ └─{audispd} │ └─{auditd} ├─avahi-daemon────avahi-daemon ├─bluetoothd ├─chronyd ├─crond (생략)

04 데몬 프로세스 o 커널 스레드 데몬 n n n 커널의 일부분을 프로세스처럼 관리하는 데몬 ps 명령으로 확인했을 때 대괄호([ ])로 둘러싸여 있는 프로세스들 예전에는 대부분 k로 시작했으나 요즘은 이를 반드시 준수하지는 않음 커널 데몬은 대부분 입출력이나 메모리 관리, 디스크 동기화 등을 수행하며 대체로 PID 가 낮은 번호로 할당 커널 데몬을 동작시키는 조상 데몬은 커널 스레드 데몬(kthreadd): PID 2번 [root@localhost sbin]# ps -ef | UID PPID C STIME TTY root 1 0 0 20: 35 ? hed-root --system --deserialize 21 root 2 0 0 20: 35 ? root 3 2 0 20: 35 ? root 5 2 0 20: 35 ? root 7 2 0 20: 35 ? root 8 2 0 20: 35 ? root 9 2 0 20: 35 ? root 10 2 0 20: 35 ? root 12 2 0 20: 35 ? root 13 2 0 20: 35 ? (생략) more TIME 00: 13 CMD /usr/lib/systemd --switc 00: 00 [kthreadd] 00: 00 [ksoftirqd/0] 00: 00 [kworker/0: 0 H] 00: 00 [kworker/u: 0 H] 00: 02 [migration/0] 00: 00 [watchdog/0] 00: 04 [migration/1] 00: 00 [kworker/1: 0 H] 00: 00 [ksoftirqd/1]



05 부트 로더 o GRUB 2 관련 디렉터리와 파일 n /boot/grub 2/grub. cfg 파일: 기존의 menu. lst 파일을 대체하는 기본 설정 파일 [root@localhost sbin]# more /boot/grub 2/grub. cfg # # DO NOT EDIT THIS FILE # # It is automatically generated by grub 2 -mkconfig using templates # from /etc/grub. d and settings from /etc/default/grub # ### BEGIN /etc/grub. d/00_header ### if [ -s $prefix/grubenv ]; then load_env fi set default="${saved_entry}" if [ x"${feature_menuentry_id}" = xy ]; then menuentry_id_option="--id" else menuentry_id_option="" fi (생략)

05 부트 로더 o GRUB 2 관련 디렉터리와 파일 n /etc/grub. d 디렉터리: GRUB 스크립트를 가지고 있으며 GRUB의 명령이 실 행될 때 순서대로 읽혀 grub. cfg 파일이 생성 [root@localhost sbin]# ls /etc/grub. d 00_header 20_linux_xen 30_os-prober 41_custom 10_linux 20_ppc_terminfo 40_custom README [root@localhost sbin]# n /etc/default/grub 파일: GRUB 메뉴 설정 내용이 저장 [root@localhost sbin]# cat /etc/default/grub GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release. *$, , g' /etc/system-release)" GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="rd. lvm. lv=fedora/swap rd. md=0 rd. dm=0 vconsole. keymap=us $([ -x /usr/sbin/rhcrashkernel-param ] && /usr/sbin/rhcrashkernel-param || : ) rd. luks=0 vconsole. font=latarcyrheb-sun 16 rd. lvm. lv=fedora/root rhgb quiet" GRUB_DISABLE_RECOVERY="true" [root@localhost sbin]#






- Slides: 47