레이블이 Linux-init/systemd인 게시물을 표시합니다. 모든 게시물 표시
레이블이 Linux-init/systemd인 게시물을 표시합니다. 모든 게시물 표시

1/27/2020

systemd 로만 관리될 경우 정리

1. systemd 로 부팅


1.1 systemctl 사용법

systemd 에서는 기본 control은 systemctl 이지만 이외에도 사용되어지는 command들이 존재하며 이부분은 이전 내용참조

  • systemctl 와 이외 사용되어지는 명령어 사용법 
  1. systemctl  사용법 
  2. networkctl 사용법 
  3. timedatectl 사용법 

systemctl 및 이외 명령 관련내용 참조  (반드시 참고)
  https://ahyuo79.blogspot.com/2017/03/systemctl.html

systemctl Manual 
  https://www.freedesktop.org/software/systemd/man/systemctl.html#


2. systemd의 Unit 구성 및 종류


  • Unit의 종류 (11개의 종류이지만 필요한것만 사용)
  1. *.service units : 주로 daemon 과 일반 process로 구성
  2. *.socket units:  IPC or Socket 기반의 활동 (encapsulate동작)
  3. *.target units:  Unit들을 group 화 하고 boot 동기화를 할때 유용
  4. *.device units:  Kernel device를 사용할 경우 udev sys
  5. *.mount units:  filesystem 안에 mount point
  6. *.automount units:  filesystem의 automount
  7. *.timer units: 다른 unit의 timer기반의 trigger로 사용
  8. *.swap units:  mount unit 과 유사하며 memory sway 과 OS의 file (encapsulate동작)
  9. *.path units: path 기반으로 변경될 때 동작되는 구조
  10. *.slice units: group unit으로 scope와 service를 계층으로 관리가 가능
  11. *.scope units:  service unit과 거의 유사하지만 외부 process 관리목적

상위 이외에도 systemd.exec 및 systemd.kill 존재하는데, 중복이 되는 것을 알수 있으며,  각 실행파일이 있으므로, 
모든 Section의 Directives의 Index에서 세부파악하자 

모든 Section의 Directives(Option) Index (중요)

  • Unit의 역할이 이미 정해진 것들 반드시 확인
Unit의 종류와 다양한 기능이 존재하지만, 이미 역할이 거의 정해진 것이 많으므로 각각의 특징을 알아보며 세부역할을 알자 

systemd 기반의 Init 관련된 부분 (SysVinit 과 차이)
  https://www.freedesktop.org/software/systemd/man/init.html#

사용용도가 특별한용도로 정해진것 아래에서 확인필요 (반드시 확인)
  https://www.freedesktop.org/software/systemd/man/systemd.special.html#


2.1 Unit의 기본구성 및 문법 

Unit의 기본 문법구성은 SectionDirective(Option)으로 설정이 가능하며 관련 Manual을 찾아서 각 기능을 보자

systemd 의 기본문법 및 구조소개 
  https://www.freedesktop.org/software/systemd/man/systemd.syntax.html#

  • 기본으로 Service 부분 Simple 예
아래의 경우 3개의 Section [Unit] 와 [Service] 와 [Install]로 구성되며 각각의 Manual 참조
$ cat *.service or *.target 
## 주석 
[Unit]  ## Section 이라고함 
Description=Wait for Network to be Configured   ## Section의 Directive or Options 이라고함 
Documentation=man:systemd-networkd-wait-online.service(8)
DefaultDependencies=no

[Service]  ## Section에 따라 Directive의 기능이 달라지므로 주의 
Type=oneshot


[Install]   ## 모든 Unit이 필요한것이 아니므로 주의 
WantedBy=multi-user.target

상위 Service의 기본 분석은 아래의 두개로 시작을 하면 될 것이다.

Unit Section 과 Unit의 Directives(Option) 기능확인
System Unit Search PATH부터 정확히 파악하고 각각의 설정을 파악 
  https://www.freedesktop.org/software/systemd/man/systemd.unit.html
  https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files

Service Section 과 Service의 Directives(Option)기능확인
  https://www.freedesktop.org/software/systemd/man/systemd.service.html#


  • 세부분석을 위한 참조사항 
상위에서 설명했듯이 세부분석시 중요 

모든 Section의 Directives(Option) Index
  https://www.freedesktop.org/software/systemd/man/systemd.directives.html

systemd의 사용되어지는 File index
  https://www.freedesktop.org/software/systemd/man/index.html

  • Target Unit 
systemd의 Unit Target 에 내부 Wants 와 Requires 
  https://www.freedesktop.org/software/systemd/man/systemd.target.html#


2.2 Unit 의 기본분석 

Systemd의 Unit는 다양하므로 본인이 원하는 기능을 볼때 동작 여부와 종속성을 확인하여 정확하게 어떻게 동작하는지 파악하자.

systemctl 및 이외 명령 관련내용 참조  (반드시 참고)
  https://ahyuo79.blogspot.com/2017/03/systemctl.html

  • 각 Unit Linux 분석 (target)
현재 Target Unit의 동작여부를 ACTIVE에서 확인가능.

$ systemctl list-units --type target    // target을 분석 (화살표키로 움직임가능) 
UNIT                LOAD   ACTIVE SUB    DESCRIPTION
basic.target        loaded active active Basic System
getty.target        loaded active active Login Prompts
local-fs-pre.target loaded active active Local File Systems (Pre)
local-fs.target     loaded active active Local File Systems
machines.target     loaded active active Containers
multi-user.target   loaded active active Multi-User System
network.target      loaded active active Network
nss-lookup.target   loaded active active Host and Network Name Lookups
paths.target        loaded active active Paths
remote-fs.target    loaded active active Remote File Systems
slices.target       loaded active active Slices
sockets.target      loaded active active Sockets
swap.target         loaded active active Swap
sysinit.target      loaded active active System Initialization
time-sync.target    loaded active active System Time Synchronized
timers.target       loaded active active Timers
LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

  • 각 Unit 의 종류 및 동작상태 확인 
$ systemctl list-units --type target | grep target    // target을 분석 (나열식) 
상위와 동일 

$ systemctl list-units --type target --state active   // 보통 Service를 Target중심으로 하면 Active되었는지 확인 
or
$ systemctl list-units --type target --state active | grep target 

$ systemctl list-units --all --full | grep ".device"  // device을 세부분석 (나열식으로 전체를 볼수있음)  
  dev-disk-by\x2did-mmc\x2d00000_0x0cf64c62.device                                                                    loaded    active   plugged   /dev/disk/by-id/mmc-00000_0x0cf64c62
  dev-disk-by\x2did-mmc\x2d00000_0x0cf64c62\x2dpart1.device                                                           loaded    active   plugged   /dev/disk/by-id/mmc-00000_0x0cf64c62-part1
  dev-disk-by\x2did-mmc\x2dS0J57X_0x184f6793.device                                                                   loaded    active   plugged   /dev/disk/by-id/mmc-S0J57X_0x184f6793
  dev-disk-by\x2did-mmc\x2dS0J57X_0x184f6793\x2dpart1.device                                                          loaded    active   plugged   /dev/disk/by-id/mmc-S0J57X_0x184f6793-part1
  dev-disk-by\x2did-mmc\x2dS0J57X_0x184f6793\x2dpart2.device                                                          loaded    active   plugged   /dev/disk/by-id/mmc-S0J57X_0x184f6793-part2
  dev-disk-by\x2did-mmc\x2dS0J57X_0x184f6793\x2dpart3.device                                                          loaded    active   plugged   /dev/disk/by-id/mmc-S0J57X_0x184f6793-part3
  dev-disk-by\x2did-mmc\x2dS0J57X_0x184f6793\x2dpart4.device                                                          loaded    active   plugged   /dev/disk/by-id/mmc-S0J57X_0x184f6793-part4
  dev-disk-by\x2did-mmc\x2dS0J57X_0x184f6793\x2dpart5.device                                                          loaded    active   plugged   /dev/disk/by-id/mmc-S0J57X_0x184f6793-part5
  dev-disk-by\x2did-mmc\x2dS0J57X_0x184f6793\x2dpart6.device                                                          loaded    active   plugged   /dev/disk/by-id/mmc-S0J57X_0x184f6793-part6
  dev-disk-by\x2dlabel-boot.device                                                                                    loaded    active   plugged   /dev/disk/by-label/boot
.....


  • Target Unit의 종속성확인

$ systemctl status  // 현재 systemd의 실행상태확인 가능하며, 종속성 확인 (주의: 실행한 후 종료된 것은 제외됨) 
........

$ systemctl list-dependencies --all  // 전체 종속관계 확인  
.....

$ systemctl list-dependencies multi-user.target  // 전체구조파악 하며, 이 안에서 다시 세부 Target 분석  
.....

$ systemctl list-dependencies sockets.target // sockets.target 분석하며, 일반적인 Server Bind 분석  
.....

$ systemctl list-dependencies network-online.target // network-online.target 종속부분확인 
network-online.target
● └─systemd-networkd-wait-online.service


  • 상위 Target 종속성을 확인 후 관련 서비스 확인 
$ cat /lib/systemd/system/systemd-networkd-wait-online.service // network-online.target에 관련된 service분석 
#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Wait for Network to be Configured
Documentation=man:systemd-networkd-wait-online.service(8)
DefaultDependencies=no
Conflicts=shutdown.target
Requires=systemd-networkd.service
After=systemd-networkd.service
Before=network-online.target shutdown.target

[Service]
Type=oneshot
ExecStart=/lib/systemd/systemd-networkd-wait-online
RemainAfterExit=yes

[Install]
WantedBy=network-online.target


$ readelf -a /lib/systemd/systemd-networkd-wait-online // 말그대로 network가 online이 될때까지 기다리는 실행파일  

  • systemd-analyze 분석 (중요)
systemd-analyze를 이용하여 booting 속도 및 각 Unit 연관성을 세부적으로 분석가능하므로 반드시 알아야함

systemd-analyze 부분 아래 참조 
  https://ahyuo79.blogspot.com/2017/04/systemd-analyze.html
  https://jlk.fjfi.cvut.cz/arch/manpages/man/systemd-analyze.1

  • network.target 및 관련내용 
  https://unix.stackexchange.com/questions/209832/debian-systemd-network-online-target-not-working
  https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
  https://www.freedesktop.org/software/systemd/man/systemd-networkd-wait-online.service.html


2.3 기본 Service Unit 문법 


$ vi *.service
[Unit]
Description=Mx Encrypted Folder
Requires=local-fs.target
After=local-fs.target

## Requires 와 After 설정 중요하며, 종속(dependency)이 아니라면 Requreis 제거 
## After 의 local-fs.target Local File System Mount 된 시점
## After 의 network.target (network.target 진입 후 )
## After 의 network-online.target (network 가 연결될 경우)

[Service]
Type=oneshot
ExecStart=/usr/bin/mxmountencrypted
RemainAfterExit=true
ExecStop=/usr/bin/mxunmountencrypted

## ExecStart 이 서비스가 시작시 
## ExecStop 이 서비스를 systemctl stop으로 중지가능 
## RemainAfterExit yes or no로 Exit되어도 유지하는지 설정 (아래 Directives Index 참조)
## StandardOutput=journal  (systemd-journal log로 사용)


[Install]
WantedBy=multi-user.target

## WantedBy or RequiredBy= [Install] Section에서 주로 사용된다 
## 더불어 각각 *.wants 와 .requres directory에 심볼링크를 생성한다 
## 이 대표적인 예가 systemctl enable/disable 설정이 될 것 같다. 


기본 Service Example 
  https://stackoverflow.com/questions/47293195/running-systemd-unit-directly-after-local-fs-target-and-before-basic-target
  https://www.freedesktop.org/software/systemd/man/systemd.service.html

각 Section 과 Directive 한글설명 
  https://fmd1225.tistory.com/93


  • 내가 만든 service 기본서비스
Network가 물리적으로 online되면, 즉 After 와 Wants를 확인

$ vi *.service  //systemd 가 network를 물리적으로 online 된 경우 실행 
## Unit Section 
[Unit]
Description=Setup and Start my Service
After=network-online.target
Wants=network-online.target

## After network-online.target 후 동작가능 (HW Network가 동작가능)
## Wants 충분조건이라고 함 Requires가 필요조건

[Service]
Type=simple
ExecStart=/usr/bin/setup.sh
Restart=on-failure

## ExecStart 상위 조건을 만족하면 실행 
## Restart=on-failure 비정상 종료면 다시 실행
or 
## Restart=always , 상위는 비정상 종료일 경우만 실행이지만, 이는 항상 무조건 실행
## RestartSec=1     매번 Restart시 1s Delay 
 

[Install]
WantedBy=multi-user.target

 https://wiki.archlinux.org/index.php/systemd
 https://wiki.archlinux.org/index.php/systemd#Targets
 https://www.freedesktop.org/wiki/Software/systemd/
 https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/


2.4 NTP Client 설정 

systemd의 NTP Client 설정은 아래와 같이 기본으로 timesyncd에서 담당한다.

  • NTP Client 관련기본설정 
systemd의 NTP Service

$ cat /etc/systemd/timesyncd.conf
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See timesyncd.conf(5) for details.

[Time]
#NTP=
#FallbackNTP=time1.google.com time2.google.com time3.google.com time4.google.com
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048

상위 timedatectl 명령어 참조 

$ timedatectl show-timesync --all //명령어로 확인 

// 이곳에 설정하면 NTP와 DNS를 같이 설정가능
// 이 설정이 상위 NTP에도 적용가능 
// 이 설정이 /etc/resolv.conf에 적용가능 

systemd의 NTP (timesyncd)
  https://stackframe.tistory.com/16
  https://www.freedesktop.org/software/systemd/man/timesyncd.conf.html
  https://wiki.archlinux.org/index.php/systemd-timesyncd

timedatectl (상위 링크참조)
  https://ahyuo79.blogspot.com/2017/03/systemctl.html

timedatectl (manual and example)
  http://man7.org/linux/man-pages/man1/timedatectl.1.html
  http://man7.org/linux/man-pages/man1/systemd-firstboot.1.html
  https://www.tecmint.com/set-time-timezone-and-synchronize-time-using-timedatectl-command/


2.5 SSH Server 설정 및 동작

  • SSH Server 설정변경 

$ cat /etc/ssh/sshd_config              //sftp 지원을 위해 수정 
# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

# 이곳에서 Port는 설정하지 말자 
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile      .ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
PermitEmptyPasswords yes

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM no

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#PermitUserEnvironment no
Compression no
ClientAliveInterval 15
ClientAliveCountMax 4
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Jeonghun
# changed options for SFTP 
# override default of no subsystems
#Subsystem      sftp    /usr/libexec/sftp-server
Subsystem       sftp    internal-sftp

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server

  • SSH Server Port 설정 변경 및 확인 

//sshd.service는 별도로 없으며, sshd.socket만 존재하므로 관련부분 검색 
$ find /lib -name sshd.socket
/lib/systemd/system/sshd.socket

$ find /etc -name sshd.socket                               //sshd.service는 별도로 없으며, sshd.socket만 존재 
/etc/systemd/system/sockets.target.wants/sshd.socket

$ find /etc -name sshd*                                     //상위로도 못찾을 경우 
$ find /lib -name sshd*      


// systemd 는 /lib -> /etc 찾아실행되므로 최종은 etc 이며, 보통 이럴 경우 link임 
$ cat /etc/systemd/system/sockets.target.wants/sshd.socket   // sshd.socket에서 직접 port 변경 
[Unit]
Conflicts=sshd.service

[Socket]
ExecStartPre=/bin/mkdir -p /var/run/sshd
#ListenStream=22
ListenStream=3333
Accept=yes

## 아래의 WantedBy 부분참조하면, 
## systemctl enable/disable 할 경우 sockets.target.wants directory에 심볼 link 생성/삭제됨 
## /lib/systemd/system/sshd.socket 기반으로 link 생성/삭제 
[Install]
WantedBy=sockets.target 

  • SSH Server Port 적용 및 상태확인 

$ systemctl status sshd.socket        // sshd.socket 동작상태 확인 
or
$ systemctl status sshd               // sshd.service 동작상태 확인 (현재 없음) 


$ systemctl daemon-reload
$ systemctl restart sshd.socket.      //sshd.socket  만 있을 경우 sshd 재시작 
or 
$ systemctl restart sshd              //sshd.service 가 있을 경우 


  • SSH or SFTP 동작안될 경우 재확인 

$ netstat -a | grep 3333    // 우선적으로 SSH or SFTP 변경된 Port 동작 검색  
tcp        0      0 :::3333                 :::*                    LISTEN

$ systemctl status sshd.socket // sshd.socket 상태확인  

// 방화벽으로 인한부분 확인
$ iptables -S               // Iptables 설정확인  
-P INPUT DROP               // Iptables INPUT이 DROP이므로 별도 추가 하거나 Policy 변경  
-P FORWARD DROP
-P OUTPUT ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A OUTPUT -p icmp -j ACCEPT
-A OUTPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A OUTPUT -p tcp -m tcp --dport 53 -j ACCEPT
-A OUTPUT -p udp -m udp --dport 53 -j ACCEPT
-A OUTPUT -p tcp -m tcp --dport 123 -j ACCEPT
-A OUTPUT -p udp -m udp --dport 123 -j ACCEPT

$ iptables -A INPUT  -p tcp --dport 3333  -j ACCEPT // Iptables INPUT 새로변경된 Port 추가        
$ iptables -A OUTPUT -p tcp --dport 3333  -j ACCEPT 


  • SSH or SFTP TEST 진행 
$ ssh -p 3333 root@192.168.1.60
$ sftp -P 3333 root@192.168.1.60    //만약 server의 key 정보가 다르다면 ssh-keygen 한 후 재연결 (ssh-keygen -f "/home/jhlee/.ssh/known_hosts" -R 192.168.1.60) 
sftp> pwd                           // remote path 확인
sftp> help                          // 기본 명령어 확인 
sftp> get test                      // remote path의 test file 가져옴 
$ sftp -P 3333 root@192.168.1.60:test1     // sftp로 바로 get test1 


2.6 SysV 기반의 Network 설정 (Systemd 같이사용)

SysV Script 기반으로는 /etc/network/interfaces 에 Network Interface를 추가하여, service로 각각의 관리를 진행을 했다.
이 부분은 systemd 와 SysV Script를 혼합해서 사용할 경우 알아두도록 하자 

  • 일반적인 /etc/network/interface 예제 (SysV Script)
SysV Script 기반으로 구성되며, Main은 ifup/ifdown이 전체 Control 하고 각각의 Shell Script 같이 분석해야함 

$ cat /etc/network/interfaces  //systemd로만 구성할 경우 사용안함 
source-directory /etc/network/interfaces.d

# The loopback network interface
auto lo
iface lo inet loopback

## DHCPC Client 예제
auto eth0
iface eth0 inet dhcp
## Static IP 예제
auto eth1
iface eth1 inet static
	address 192.168.1.11 
	netmask 255.255.255.0
	gateway 192.168.1.1
## USB hotplug
allow-hotplug usb0
iface usb0 inet static
	address 192.168.3.7
	netmask 255.255.255.0
    
$ ls /etc/network/     //각 Shell Script 과 Interface 확인 
if-down.d  if-post-down.d  if-pre-up.d  if-up.d  interfaces  interfaces.d

$ ls /etc/network/if-up.d/  //각각의 Shell script 혹은 Symbol Link  내부에서 $IFACE로 Interface 구분 
000resolvconf  avahi-daemon  ethtool  wpasupplicant

$ service --status-all    //network 관련서비스 name 확인 (SysV Script 사용할 경우 service이용) 
...
$ sudo service networking restart //network 관련서비스 재실행 
or
$ systemctl restart networking.service

  • ifup/ifdown  (상위 설정 및 Shell Script 연결)
$ cat /lib/systemd/system/networking.service //ifup ifdown 이 /etc/network/interfaces 사용
.......
[Install]
WantedBy=multi-user.target
WantedBy=network-online.target

[Service]
Type=oneshot
EnvironmentFile=-/etc/default/networking
ExecStart=/sbin/ifup -a --read-environment
ExecStop=/sbin/ifdown -a --read-environment --exclude=lo
RemainAfterExit=true
TimeoutStartSec=5min

/etc/network/interfaces 관련 좋은예제

/sbin/ifup and ifdown 관련사항


2.7 Systemd 의 Network 설정

처음에 NTP 및 DNS / DHCP 관련부분 설정을 다른 곳에서 설정하려고 했으나 아래와 같이 한곳에서 설정하면 다 적용이 되는 부분을 찾았다.

  • systemd 로만 network 설정할 경우 
systemd의 network interface 설정은 기존과 다른게 systemd-networkd에서 담당한다

만약 systemd로만 구성할 경우 /etc/network/interface의 설정은 불필요한 것으로 보이는데,여기서 설정하지 못하는 것은 
추가로 상위와 같이 보완용 ifup/ifdown 기반으로 넣을 수도 있을 것 같다. 

systemd로만 network를 구성할 경우  /etc/systemd/network/xxx.network 로 network interface를 추가하고 설정하는 구조이다

일반 MII기반의 ethernet은 ethx.network  , USB-CDC 기반의 network는 usbx.network
이외의 network의 이름일 경우 상위와 동일하게 각 interface name으로 설정.
** 주의 우선순위가 될 것이며, /etc 가 가장 높으므로, 이 위주로 설정진행  
** 주의 wvdial의 ppp의 경우 이곳에서 설정하지 않음 
  • eth0 Interface기반 Network DHCP 설정
$ cat /etc/systemd/network/eth0.network  
[Match]
Name=eth0

[Network]
DHCP=yes
NTP=1.kr.pool.ntp.org
DNS=8.8.8.8
DefaultRouteOnDevice=yes

  • eth0 Interface기반 Network Static IP설정
$ cat /etc/systemd/network/eth0.network  
[Match]
Name=eth0

[Network]
##Static IP로 직접설정  192.168.1.67/24  24는 NetMask의 bits수 Netmask 255.255.255.0 
Address=192.168.1.67/24
Gateway=192.168.1.1
NTP=1.kr.pool.ntp.org
DNS=8.8.8.8
DefaultRouteOnDevice=yes

DefaultRouteOnDevice를 해야지 route table에 default로 등록가능

/etc/systemd/network/eth0.network  설정사항
  https://www.freedesktop.org/software/systemd/man/systemd.network.html

/etc/systemd/network/99-default.link (현재 /dev/null 로 link됨)

  • Route Table 설정확인 및 분석
$ route  
or
$ netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
192.168.1.1     0.0.0.0         255.255.255.255 UH        0 0          0 eth0

$ ls /etc/network/
if-down.d       if-post-down.d  if-pre-up.d


  • DNS Server 설정확인
/var/run/resolv.conf
/etc/resolve.conf


  • RTC 관련사항
/dev/rtc 기능으로  i.MX SNVS
PMIC의 별도의 Battery Generator 와 i.MX의 RTC기능이며, 배터리로 RTC가 유지가 되어진다.

세부사항은 timedatectl 설정에서 확인가능
  https://www.digi.com/resources/documentation/digidocs/90001546/reference/bsp/cc6/r_real_time_clock.htm
  https://developer.toradex.com/knowledge-base/how-to-use-the-real-time-clock-in-linux

4/15/2019

syslog 와 rsyslog 설정

1. syslog 와 rsyslog

syslog는 linux에서 사용되어지는 application log system이며, 보통 klogd와 함께 사용되어진다.
그래서, klogd의 message와 호환이 되기 때문에 kernel message도 출력이 가능하다.

syslog는 기본으로 2가지 설정(Facility 와 Level)으로 구성이 되며, 여기에 추가적으로 tag도 별도로 첨부가 가능하여 
log 저장방법의 다양성을 제공해주고 있다.

  • Facility
Log message의 장치 및 source를 말하며, Facility Code or keyword로 쉽게 구분을 하여 본인이 원하는 message들을 log가 가능하다.
Facility code Keyword Description
0 kern Kernel messages
1 user User-level messages
2 mail Mail system
3 daemon System daemons
4 auth Security/authentication messages
5 syslog Messages generated internally by syslogd
6 lpr Line printer subsystem
7 news Network news subsystem
8 uucp UUCP subsystem
9 cron Clock daemon
10 authpriv Security/authentication messages
11 ftp FTP daemon
12 ntp NTP subsystem
13 security Log audit
14 console Log alert
15 solaris-cron Scheduling daemon
16–23 local0 – local7 Locally used facilities

  • Level
상위 Facility가 정해졌으며, 각 log의 Level을 설정이 가능하여, Message 양을 조절이 가능하다.
Value Severity Keyword Deprecated keywords Description
0 Emergency emerg panic[7] System is unusable
1 Alert alert Action must be taken immediately
2 Critical crit Critical conditions
3 Error err error[7] Error conditions
4 Warning warning warn[7] Warning conditions
5 Notice notice Normal but significant conditions
6 Informational info Informational messages
7 Debug debug Debug-level messages

syslog의 설정관련기본 정보(상위도표)
  https://en.wikipedia.org/wiki/Syslog

syslog의 kernel message는 klogd에서 전달받음

  • klogd
/proc/kmsg 에서 읽어서 syslogd 로 전송 

  • syslogd or rsyslogd 
/dev/log 를 사용하여 local에서 read 하며, network bind 514 port  


1.1 syslog의 설정 및 기본테스트 

syslog의 설정은 /etc/syslog.conf 이곳에서 설정이 되며, ps로 syslogd의 동작을 반드시 확인을 하자.
만약 미동작이라면, systemd or sysVinit 방식으로 syslogd를 실행을 시켜주자

  • syslog 설정 (/etc/syslog.conf)
$ vi /etc/rsyslog.conf    // 보통 내부에 include 사용하여 /etc/rsyslog.d/*.conf 확장 
or
$ vi /etc/rsyslog.d/*.conf   // rsyslogd 각 설정  (설정변경후 service restart, systemctl restart rsyslogd )

$ vi /etc/syslog.conf    // 보통 내부에 include 사용하여 /etc/syslog.d/*.conf 확장 
or
$ vi /etc/syslog.d/*.conf   // syslogd 각 설정  (설정변경후 service restart, systemctl restart syslogd ) 

#  /etc/syslog.conf     Configuration file for busybox's syslogd utility

########
#
# 
# 
# "*"    : Faclity or Severity level에서 사용 (모든 Faclity or Severity level) 
# "none" : Severity level에서만 사용          ( message를 미기록)
# ";"    ; 연속으로 
#  "="   ; Severity level의 정의하여 그 이상만 설정 
#  "@"   ; 외부 Server 
# 
#  facility.level;facility.level         logpath 
#  
#  /var/log/messages : default 저장되는 장소 (만약 설정을 안했다면, 기본으로 이곳에 저장)
#
# 
########

*.info;mail.none;news.none;authpriv.none       /var/log/messages

*.alert              root

local0.notice       /var/log/local0    

local1.*            /var/log/local1
local2.info         /var/log/local2

## console로 출력 
local3.*            /dev/console

local4.*            /var/log/test

# 해당 메시지를 192.168.1.17의 syslogd으로 전송 
local5.*            @192.168.1.17  
# 전송과 동시에 저장
local5.*            /var/log/local5           

# 해당 메시지를 jhleehost 의 syslogd으로 UDP 전송
local6.*            @jhleehost     
# 전송과 동시에 저장 
local6.*            /var/log/local6          

# 해당 메시지를 logserver 의 syslogd으로 전송
local7.*            @logserver     
# 전송과 동시에 저장 
local7.*            /var/log/local7          

syslog 와 rsyslog TCP/UDP 설정 ($UDPServerRun 514 , $InputTCPServerRun 514 )
  https://m.blog.naver.com/PostView.nhn?blogId=scvpark&logNo=221017723884&proxyReferer=https:%2F%2Fwww.google.com%2F

  • hostname 설정 및 변경 ( syslog에 반영)
$ cat /etc/hostname
jhleehost

$ cat /etc/hosts
127.0.0.1 localhost.localdomain           localhost
127.0.1.1 jhleehost
192.168.1.100  logserver

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters


  • syslog의 network 설정 
$ ps | grep syslog*  // 현재설정확인
  247 root      2724 S    /sbin/syslogd -n
  620 root      2724 S    grep syslog*
 

$ grep -r syslogd /lib/systemd/         //systemd 방식의 Service 찾기
/lib/systemd/system/busybox-syslog.service:ExecStart=/sbin/syslogd -n $OPTIONS

$ grep -r syslogd /etc/systemd/         //systemd 방식의 Service 찾기 (상위링크임)
/etc/systemd/system/syslog.service:ExecStart=/sbin/syslogd -n $OPTIONS
/etc/systemd/system/multi-user.target.wants/busybox-syslog.service:ExecStart=/sbin/syslogd -n $OPTIONS

$ vi /etc/init.d/sysklogd  //sysVinit 방식 
or
$ vi /lib/systemd/system/busybox-syslog.service //systemd 방식 

/sbin/syslogd –r –m 0 이용하여 원격Log Server 동작가능 (-r 옵션추가)

-r 옵션을 추가하면, logserver 기능이 추가되며, 외부의 Message를 받아 저장가능



syslogd 의 사용법 
/sbin/syslogd 에서 위치하며 상위 설정기반으로 Service 형태로 동작 
klogd 의 사용법
/sbin/klogd 에 대부분 위치하며, Kernel Message만 관리하며, Service 형태로 동작
syslogd를 걸쳐서 오는 것으로 보이며, syslogd가 더 중요 
  https://linux.die.net/man/8/klogd

/etc/syslog.conf 와 syslogd 관련정리내용
  https://www.linux.co.kr/lecture/lec_linux_01/lec-data/11data.pdf


1.2  logger로 syslog 테스트 

logger program을 이용하여 간단히 syslog를 테스트가 가능하며, 이를 이용하여 기록확인이 가능하다
  1. -p 옵션 : Facility 와 level 설정
  2. -t  옵션 : Tag  (별도의 본인의 Tag 설정)

상위 /etc/syslog.conf  설정변경 후 syslogd를  재실행 혹은 Reboot 후  아래와 같이 테스트 진행하며 
설정값(/etc/syslog.conf)을 변경하지 않는다면, 그대로 테스트 

  • /var/log/local0에 기록 (/etc/syslog.conf참조)
$ echo "hello local0" |  logger -t test_user0 -p local0.notice

$ cat /var/log/local0  //날짜 시간 hostname facility.level tag   message 
Mar 13 15:40:45 jhleehost local0.notice test_user0: hello local0


  • /var/log/local1에 기록
$ echo "hello local1" |  logger -t test_user1 -p local1.notice
$ cat /var/log/local1
Mar 13 15:45:50 jhleehost local1.notice test_user1: hello local1


  • /var/log/local2에 기록
$ echo "hello local2" |  logger -t test_user2 -p local2.info
$ cat /var/log/local2
Mar 13 15:49:31 jhleehost local2.info test_user2: hello local2


  • 바로 Consol 출력 미기록
$ echo "hello local3" |  logger -t test_user2 -p local3.info         
Mar 13 15:50:41 jhleehost local3.info test_user2: hello local3


  • Network로 Message 출력
$ echo "hello local5" |  logger -t test_user2 -p local5.info   
$ echo "hello local5" |  logger -t test_user2 -p local5.notice     
$ cat /var/log/message    //192.168.1.17로 기록 
.....
Mar 13 15:54:19 jhleehost local5.info test_user2: hello local5
Mar 13 15:56:24 jhleehost local5.notice test_user2: hello local5

$ cat /var/log/local5    // local로 기록 
Mar 13 16:05:57 jhleehost local5.info test_user2: hello local5
Mar 13 16:06:06 jhleehost local5.notice test_user2: hello local5


  • Shellscript 과 logger로 TEST진행
2>&1 을 이용하여 표준에러를 표준입력으로 변경하여 출력

$ test1.sh | logger -t test_1 -p local0.notice

$ test2.sh 2>&1 | logger -t test_2 -p local0.notice

2. syslog를 이용한 Programming 


Application에서 printf 대신 syslog를 이용하여 손쉽게 저장이 가능하며, 이를 이용하는 방식에 대해 간단히 요약한다.

2.1 syslog message format 방식 


syslog가 network도 지원이 되다보니, Protocol 방식이 존재하며, 더불어 TLS 같은 보안기능까지 지원가능 한 것으로 보인다.

  https://sematext.com/blog/what-is-syslog-daemons-message-formats-and-protocols/
  https://stackify.com/syslog-101/

  • syslogd의 실행 및 옵션 
  https://linux.die.net/man/3/syslog
  http://man7.org/linux/man-pages/man5/rsyslog.conf.5.html


2.2 언어 C를 사용하여 syslog 구현 

기본적으로 C에서 syslog를 이용하고 싶다면 아래와 같이 선언을 하고 build 진행

//Facility
#define LOG_KERN    (0<<3)  /* kernel messages */
#define LOG_USER    (1<<3)  /* random user-level messages */
#define LOG_MAIL    (2<<3)  /* mail system */
#define LOG_DAEMON  (3<<3)  /* system daemons */
#define LOG_AUTH    (4<<3)  /* security/authorization messages */
#define LOG_SYSLOG  (5<<3)  /* messages generated internally by syslogd */
#define LOG_LPR     (6<<3)  /* line printer subsystem */
#define LOG_NEWS    (7<<3)  /* network news subsystem */
#define LOG_UUCP    (8<<3)  /* UUCP subsystem */
#define LOG_CRON    (9<<3)  /* clock daemon */
#define LOG_AUTHPRIV    (10<<3) /* security/authorization messages (private) */
#define LOG_FTP     (11<<3) /* ftp daemon */
#define LOG_LOCAL0  (16<<3) /* reserved for local use */
#define LOG_LOCAL1  (17<<3) /* reserved for local use */
#define LOG_LOCAL2  (18<<3) /* reserved for local use */
#define LOG_LOCAL3  (19<<3) /* reserved for local use */
#define LOG_LOCAL4  (20<<3) /* reserved for local use */
#define LOG_LOCAL5  (21<<3) /* reserved for local use */
#define LOG_LOCAL6  (22<<3) /* reserved for local use */
#define LOG_LOCAL7  (23<<3) /* reserved for local use */

//Level
#define LOG_EMERG   0   /* system is unusable */
#define LOG_ALERT   1   /* action must be taken immediately */
#define LOG_CRIT    2   /* critical conditions */
#define LOG_ERR     3   /* error conditions */
#define LOG_WARNING 4   /* warning conditions */
#define LOG_NOTICE  5   /* normal but significant condition */
#define LOG_INFO    6   /* informational */
#define LOG_DEBUG   7   /* debug-level messages */



#include <syslog.h>

void openlog(const char *ident, int option, int facility);
void syslog(int priority, const char *format, ...);
void closelog(void);

#include <stdarg .h>

void vsyslog(int priority, const char *format, va_list ap); 


#include <syslog.h>

int main()
{
     syslog(LOG_INFO|LOG_LOCAL1, "test local 0 \n");
     syslog(LOG_INFO|LOG_LOCAL2, "test local 1 \n");
     syslog(LOG_INFO|LOG_LOCAL3, "test local 2 \n");

     return 0;
}

Linux의 Application에서 직접 Syslog 사용할 경우 C의 예제 사용법 
  https://www.joinc.co.kr/w/Site/system_programing/Unix_Env/syslog_1
3. syslog 기타사항 정리 



3.1 /var/log 의 검색방법 

/var/log/ 안에 다양한 log들이 존재할 것이며 정확한 Log를 분석하기 위해서 아래와 같이 날짜기반으로 검색하거나, 
혹은 Facility 와 각 Level 기반으로 검색 부터 Tag 를 사용하여 세부 검색을 이용하자 

  • grep를 이용하여 검색 후 분석 
$ grep "Feb 28 22:" /var/log/message  // 날짜기반으로 검색 
$ grep "Feb 28 22:" /var/log/message | head -n 100   // 날짜기반으로 검색 

$ grep "local0.notice" /var/log/message  // Facility 와 Level 기반으로 검색 
$ grep "local0.notice" /var/log/message | tail -n 100  // Facility 와 Level 기반으로 검색 

$ grep -e "local0.notice" -e "Feb 28 22:" /var/log/message  // 날짜기반에 Facility 와 Level 기반으로 검색 
$ grep -e "local0.notice" -e "Feb 28 22:" /var/log/message | tail -n 100  // 날짜기반에 Facility 와 Level 기반으로 검색  

  • grep/egrep/awk/sed 이용한 Pattern 검색
$ grep "PATTERN1\|PATTERN2" FILE
$ grep -E "PATTERN1|PATTERN2" FILE
$ grep -e PATTERN1 -e PATTERN2 FILE
$ egrep "PATTERN1|PATTERN2" FILE

$ awk '/PATTERN1|PATTERN2/' FILE

$ sed -e '/PATTERN1/b' -e '/PATTERN2/b' -e d FILE

grep 과 awk / sed 로 검색방법 
  https://www.shellhacks.com/grep-or-grep-and-grep-not-match-multiple-patterns/


3.2 rsyslog , syslog , syslog-ng 차이 


  • syslog 
1980년대에 시작되어 계속 개발중 
  1. UDP기반으로 syslog protocol 완성된 log관리 시스템 
  2. 상위 syslogd Manual 보면 Network은 UDP만 지원 

  • syslog-ng 
1988년에 syslog protocol 과 함께 시작되어 계속 개발중 
  1. content-based filtering  (Filter 기능을 제공하는 것으로 추측)
  2. Logging directly into a database ( Database 제공?)
  3. TCP for transport (UDP가 아닌 TCP로 안정화)
  4. TLS encryption (TLS 암호화까지 지원)

  • rsyslog
2004년에 syslog protocol 과 함께 시작되어 계속 개발중 
  1. RELP Protocol support
  2. Buffered operation support
  3. 상위 설정으로 봐서 TCP도 지원

결론적으로 각각 독립적으로 Open Source가 지원이 되는 것 같은데, 암호화 부분은 syslog-ng가 되어 낫을 것 같다. 


아래 링크 글을 보면 근본적으로 거의 차이가 없는 것(syslog protocol 모두 지원)으로 보이며, 하지만, 세부동작과 동작방식이 다른 것으로 보인다.

출처:
  https://serverfault.com/questions/692309/what-is-the-difference-between-syslog-rsyslog-and-syslog-ng


3.3 systemd-journal 의 사용법

기본적으로 Binary로 데이타를 저장하고 저장장소역시 이미 정해져있고, 현재 테스트만 해봤지만,  장점이 무엇인지 정확하게 모르겠음

추후 사용해보고 정리

systemd-journal 사용법
  https://haker.tistory.com/52
  https://www.loggly.com/ultimate-guide/linux-logging-with-systemd/


journal 이용방법
  https://serverfault.com/questions/573946/how-can-i-send-a-message-to-the-systemd-journal-from-the-command-line

3.4 rsyslog

현재 Ubuntu에서 syslogd 대신 사용하고 있으며, 추후 사용해보고 정리 
각 기능을 확인

  https://www.thegeekdiary.com/configuring-remote-logging-using-rsyslog-in-centos-rhel/
  http://pubs.opengroup.org/onlinepubs/007908799/xsh/syslog.h.html
  https://en.wikipedia.org/wiki/Syslog
  https://en.wikipedia.org/wiki/Rsyslog
  https://en.wikipedia.org/wiki/Reliable_Event_Logging_Protocol

정리해야할 사항들 및 참고사항
  https://cleverdj.tistory.com/130
  https://system-monitoring.readthedocs.io/en/latest/log.html
  http://apollo89.com/wordpress/?p=554
  https://en.wikipedia.org/wiki/Syslog
  https://haker.tistory.com/52

echo 'hello' | systemd-cat
journalctl -f


 https://serverfault.com/questions/573946/how-can-i-send-a-message-to-the-systemd-journal-from-the-command-line

journalctl -fu lora-start.service
  https://www.digitalocean.com/community/tutorials/how-to-use-journalctl-to-view-and-manipulate-systemd-logs

  https://www.freedesktop.org/software/systemd/man/systemd.html#

  https://www.joinc.co.kr/w/Site/system_programing/Unix_Env/syslog_1
  https://www.joinc.co.kr/w/Site/system_programing/Unix_Env/syslog_2

  https://reebok.tistory.com/69

cron
  https://stackframe.tistory.com/14
  https://wiki.archlinux.org/index.php/Systemd/Timers

4/09/2017

Linux systemd 구조분석 (AM335x-SK)

1 TI-Sitara(AM335x-SK)

AM335x-SK, Start Kit 관련하여 File system을 간단히 분석을 해보고, 이를 최적화를 하려고 한다.
분석을 해보면, /sbin/init 을 systemd로 이용하고 SysVinit의 bootscript 을 혼용해서 사용하고 있다.
TI의 경우는 변화 도중 인지 몰라도 /lib/systemd/systemd boot 후 SysVInit Script모드를 사용한다.
현재의 추세가 SysVInit 에서 systemd로 변환되어지는 구조이며, 혼용해서 사용하는 독특한 구조이다.

Systemd 와 SysVInit 혼용
  https://ahyuo79.blogspot.com/2017/04/linux-init-script.html

1.1 기본동작분석

boot parameter 확인하고, file system의 구조를 파악을 하자

  • PID 1의 boot parameter 확인 
Kernel은 Filesystem이 존재하지 않으면 Booting이 되지 않기때문에 아래의 두개의 중요
  1. root= filesystem
  2. init=  init program ( 현재 설정하지 않았기 때문에 기본설정 /sbin/init)

root@am335x-evm:~# cat /proc/cmdline 
console=ttyO0,115200n8 root=PARTUUID=000390f5-02 rw rootfstype=ext4 rootwait

root@am335x-evm:~# cat /proc/1/cmdline  // init args 확인 
root@am335x-evm:~# ls /proc/1/fd     // 관련 FD 확인 부모 Process / 자식 Process
or
root@am335x-evm:~# ls /proc/1/fdinfo 

상위 커널 Argument를 보면 현재 /sbin/init로 기반으로 동작

/sbin/init ->  /lib/systemd/systemd  (현재 /sbin/init 은 /lib/systemd/systemd에 link)

  • /sin/init 와 runlevel 존재 확인 
root@am335x-evm:~# ls /sbin      
agetty                  e2fsck                  fsck.minix              ifup                    losetup                 mkswap.util-linux       route                   switch_root.util-linux
arp                     e2image                 fsck.minix.util-linux   init                    losetup.util-linux      modinfo                 routef                  sysctl
badblocks               e2label                 fsck.msdos              insmod                  lsmod                   modinfo.kmod            routel                  sysctl.procps
blkid                   e2undo                  fsck.util-linux         insmod.kmod             mkdosfs                 modprobe                rtmon                   syslogd
blockdev                e4crypt                 fsck.vfat               ip                      mke2fs                  modprobe.kmod           rtpr                    tc
blockdev.util-linux     e4defrag                fstrim                  ip.iproute2             mkfs.ext2               mount-copybind          runlevel                tune2fs
bridge                  fatlabel                fw_printenv             iwconfig                mkfs.ext3               mount.nfs               setconsole              udevd
cfdisk                  fdisk                   fw_setenv               iwgetid                 mkfs.ext4               mount.nfs4              shutdown                udhcpc
ctrlaltdel              fdisk.util-linux        getty                   iwlist                  mkfs.ext4dev            nologin                 start-stop-daemon       uevent
debugfs                 filefrag                halt                    iwpriv                  mkfs.fat                pivot_root              sulogin                 umount.nfs
depmod                  fsck                    hdparm                  iwspy                   mkfs.minix              pivot_root.util-linux   sulogin.util-linux      umount.nfs4
depmod.kmod             fsck.ext2               hdparm.hdparm           klogd                   mkfs.minix.util-linux   populate-extfs.sh       swapoff                 vconfig
dosfsck                 fsck.ext3               hwclock                 ldconfig                mkfs.msdos              poweroff                swapoff.util-linux      vigr
dosfslabel              fsck.ext4               ifcfg                   loadkmap                mkfs.vfat               reboot                  swapon                  vigr.shadow
dumpe2fs                fsck.ext4dev            ifconfig                logread                 mklost+found            rmmod                   swapon.util-linux       vipw
e2freefrag              fsck.fat                ifdown                  logsave                 mkswap                  rmmod.kmod              switch_root             vipw.shadow


  • runlevel 0~6까지 존재하며, init를 통해 다시 확인가능
  1. init 0 : Halt 
  2. init 1 : Single-user Mode 
  3. init 2 : Multi-user Mode  (Not support network)
  4. init 3 : Multi-user Mode with Networking
  5. init 4 : Not used/User-definable  (For special purposes)
  6. init 5 : Graphic-user Mode ( As runlevel 3 + display manager)
  7. init 6 : Reboot  (Reboots the system)

  https://wiki.kldp.org/KoreanDoc/html/Boot_Process-KLDP/iterateinittab.html

  • systemd 관련 명령어 (system damon)
systemd 명령어와 관련 명령어 검색

root@am335x-evm:~# find / -name systemd
/var/lib/systemd
/lib/systemd
/lib/systemd/systemd   // 실제 user를 위한 system daemon 이며 이동작을 확인 (systemctl) 
/etc/systemd
/etc/xdg/systemd
/sys/fs/cgroup/systemd
/run/user/0/systemd
/run/udev/tags/systemd
/run/systemd
/usr/lib/systemd
/usr/share/systemd
/usr/include/systemd
/tmp/0-runtime-dir/systemd

다양한 systemd의 실행이며 각각의 역할이 있으며, 이 부분은 좀 더 자세히 알아보자

root@am335x-evm:~# ls /lib/systemd/ 
network                       systemd-ac-power              systemd-initctl               systemd-networkd-wait-online  systemd-shutdown              systemd-udevd
system                        systemd-backlight             systemd-journald              systemd-quotacheck            systemd-sleep                 systemd-update-done
system-generators             systemd-bootchart             systemd-localed               systemd-random-seed           systemd-socket-proxyd         systemd-update-utmp
system-preset                 systemd-cgroups-agent         systemd-logind                systemd-remount-fs            systemd-sysctl                systemd-user-sessions
system-shutdown               systemd-fsck                  systemd-machined              systemd-reply-password        systemd-sysv-install          systemd-vconsole-setup
system-sleep                  systemd-hibernate-resume      systemd-modules-load          systemd-resolved              systemd-timedated
systemd                       systemd-hostnamed             systemd-networkd              systemd-rfkill                systemd-timesyncd

root@am335x-evm:~# /lib/systemd/systemd --help

systemd [OPTIONS...]

Starts up and maintains the system or user services.

  -h --help                      Show this help
     --test                      Determine startup sequence, dump it and exit
     --no-pager                  Do not pipe output into a pager
     --dump-configuration-items  Dump understood unit configuration items
     --unit=UNIT                 Set default unit
     --system                    Run a system instance, even if PID != 1
     --user                      Run a user instance
     --dump-core[=BOOL]          Dump core on crash
     --crash-vt=NR               Change to specified VT on crash
     --crash-reboot[=BOOL]       Reboot on crash
     --crash-shell[=BOOL]        Run shell on crash
     --confirm-spawn[=BOOL]      Ask for confirmation when spawning processes
     --show-status[=BOOL]        Show status updates on the console during bootup
     --log-target=TARGET         Set log target (console, journal, kmsg, journal-or-kmsg, null)
     --log-level=LEVEL           Set log level (debug, info, notice, warning, err, crit, alert, emerg)
     --log-color[=BOOL]          Highlight important log messages
     --log-location[=BOOL]       Include code location in log messages
     --default-standard-output=  Set default standard output for services
     --default-standard-error=   Set default standard error output for services


systemd의 설명
  https://www.freedesktop.org/software/systemd/man/systemd.html#


  • systemd의 설정 (system/user 설정 값확인)
  1. /etc/systemd/system.conf
  2. /etc/systemd/user.conf
  https://www.freedesktop.org/software/systemd/man/systemd-system.conf.html#


1.2 systemd-x program들 

각 systemd-xxx program 설치는 옵션이므로, 대부분 필요한 것들을 별도설치

root@am335x-evm:~# ls -al /usr/bin/systemd-*
-rwxr-xr-x    1 root     root         26160 Dec 15 00:09 /usr/bin/systemd-cat
-rwxr-xr-x    1 root     root        256116 Dec 15 00:09 /usr/bin/systemd-cgls
-rwxr-xr-x    1 root     root        268436 Dec 15 00:09 /usr/bin/systemd-cgtop
-rwxr-xr-x    1 root     root         54932 Dec 15 00:09 /usr/bin/systemd-delta
-rwxr-xr-x    1 root     root         30256 Dec 15 00:09 /usr/bin/systemd-detect-virt
-rwxr-xr-x    1 root     root        535036 Dec 15 00:09 /usr/bin/systemd-nspawn
-rwxr-xr-x    1 root     root         34348 Dec 15 00:09 /usr/bin/systemd-path
-rwxr-xr-x    1 root     root        292980 Dec 15 00:09 /usr/bin/systemd-resolve
-rwxr-xr-x    1 root     root        334168 Dec 15 00:09 /usr/bin/systemd-run
-rwxr-xr-x    1 root     root         46672 Dec 15 00:09 /usr/bin/systemd-socket-activate
-rwxr-xr-x    1 root     root        239724 Dec 15 00:09 /usr/bin/systemd-stdio-bridge
...


systemd-cat
  https://www.freedesktop.org/software/systemd/man/systemd-cat.html#

systemd-cgls
  https://www.freedesktop.org/software/systemd/man/systemd-cgls.html#

systemd-cgtop
  https://www.freedesktop.org/software/systemd/man/systemd-cgtop.html#

systemd-run
  https://www.freedesktop.org/software/systemd/man/systemd-run.html

systemd-nspanwn
  https://www.freedesktop.org/software/systemd/man/systemd-nspawn.html

systemd-xxx 검색
  https://www.freedesktop.org/software/systemd/man/index.html

systemd-analyze가 없음 (추후 설치)
  https://www.freedesktop.org/software/systemd/man/systemd-analyze.html

systemd의 service 등록방법
  https://chhanz.github.io/linux/2019/01/18/linux-how-to-create-custom-systemd-service/
  https://fmd1225.tistory.com/93

systemd의 Yocto service 등록방법
  https://community.nxp.com/thread/472820

systemd-analyze 못찾을 경우
  https://stackoverflow.com/questions/34501611/systemd-apparently-not-finding-service-file

backup
  https://stackoverflow.com/questions/50354012/systemctl-failing-with-unknown-section-timer

1.3 Process 의 PID 분석 

Process의 PID를 보고 현재 실행되는 순서를 역분석을 해보면, 아래와 같이 /sbin/init 가 PID가 1 지만, link만 존재하므로 systemd가 실행이 되어있다.

확인할 경우 아래와 같이 ps -ax or ps -aux 전체사항을 확인하고 필요한 사항이 있다면, grep or head or tail 사용하자.

root@am335x-evm:~# ps -aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  9.9  1.7   5232  4384 ?        Ss   23:15   0:08 /sbin/init
root         2  0.0  0.0      0     0 ?        S    23:15   0:00 [kthreadd]
root         3  0.1  0.0      0     0 ?        S    23:15   0:00 [ksoftirqd/0]
root         4  0.0  0.0      0     0 ?        S    23:15   0:00 [kworker/0:0]
root         5  0.0  0.0      0     0 ?        S<   23:15   0:00 [kworker/0:0H]
root         6  0.0  0.0      0     0 ?        S    23:15   0:00 [kworker/u2:0]
root         7  0.2  0.0      0     0 ?        S    23:15   0:00 [rcu_preempt]
root         8  0.0  0.0      0     0 ?        S    23:15   0:00 [rcu_sched]
root         9  0.0  0.0      0     0 ?        S    23:15   0:00 [rcu_bh]
root        10  0.0  0.0      0     0 ?        S    23:15   0:00 [kdevtmpfs]
root        11  0.0  0.0      0     0 ?        S<   23:15   0:00 [netns]
root        12  0.0  0.0      0     0 ?        S<   23:15   0:00 [perf]
root        13  0.0  0.0      0     0 ?        S    23:15   0:00 [kworker/0:1]
root        14  0.0  0.0      0     0 ?        S<   23:15   0:00 [writeback]
root        15  0.0  0.0      0     0 ?        S<   23:15   0:00 [crypto]
root        16  0.0  0.0      0     0 ?        S<   23:15   0:00 [bioset]
root        17  0.0  0.0      0     0 ?        S<   23:15   0:00 [kblockd]
root        18  0.0  0.0      0     0 ?        S<   23:15   0:00 [edac-poller]
root        19  0.0  0.0      0     0 ?        S<   23:15   0:00 [rpciod]
root        20  0.0  0.0      0     0 ?        S    23:15   0:00 [kswapd0]
root        21  0.0  0.0      0     0 ?        S    23:15   0:00 [fsnotify_mark]
root        22  0.0  0.0      0     0 ?        S<   23:15   0:00 [nfsiod]
root        31  0.0  0.0      0     0 ?        S<   23:15   0:00 [dma_wq]
root        32  0.7  0.0      0     0 ?        S    23:15   0:00 [kworker/u2:1]
root        33  0.0  0.0      0     0 ?        S<   23:15   0:00 [bioset]
root        34  0.0  0.0      0     0 ?        S<   23:15   0:00 [bioset]
root        35  0.0  0.0      0     0 ?        S<   23:15   0:00 [bioset]
root        36  0.0  0.0      0     0 ?        S<   23:15   0:00 [bioset]
root        37  0.0  0.0      0     0 ?        S<   23:15   0:00 [bioset]
root        38  0.0  0.0      0     0 ?        S<   23:15   0:00 [bioset]
root        39  0.0  0.0      0     0 ?        S<   23:15   0:00 [bioset]
root        40  0.0  0.0      0     0 ?        S<   23:15   0:00 [bioset]
root        43  0.0  0.0      0     0 ?        S<   23:15   0:00 [kpsmoused]
root        44  0.0  0.0      0     0 ?        S    23:15   0:00 [irq/180-4803c00]
root        45  0.0  0.0      0     0 ?        S    23:15   0:00 [irq/179-4803c00]
root        46  0.0  0.0      0     0 ?        S<   23:15   0:00 [ipv6_addrconf]
root        47  0.0  0.0      0     0 ?        S<   23:15   0:00 [deferwq]
root        48  0.0  0.0      0     0 ?        S    23:15   0:00 [irq/159-44e0b00]
root        49  0.1  0.0      0     0 ?        S    23:15   0:00 [kworker/u2:2]
root        50  0.0  0.0      0     0 ?        S    23:15   0:00 [irq/33-48060000]
root        51  0.0  0.0      0     0 ?        S    23:15   0:00 [kworker/u2:3]
root        52  0.0  0.0      0     0 ?        S<   23:15   0:00 [bioset]
root        53  1.6  0.0      0     0 ?        S    23:15   0:01 [mmcqd/0]
root        54  0.1  0.0      0     0 ?        S<   23:15   0:00 [kworker/0:1H]
root        55  0.0  0.0      0     0 ?        S    23:15   0:00 [jbd2/mmcblk0p2-]
root        56  0.0  0.0      0     0 ?        S<   23:15   0:00 [ext4-rsv-conver]
root        68  0.0  0.0      0     0 ?        S    23:15   0:00 [kworker/0:2]
root        76  0.0  0.0      0     0 ?        S<   23:15   0:00 [cryptodev_queue]
root        98  2.3  0.7   3616  1908 ?        Ss   23:15   0:01 /lib/systemd/systemd-journald // log를 위해 시작 
root       121  0.1  0.0      0     0 ?        S    23:15   0:00 [kworker/0:3]
root       127  1.6  1.0  10524  2528 ?        Ss   23:15   0:01 /lib/systemd/systemd-udevd  //udevd 시작 
root       325  0.0  0.0      0     0 ?        S<   23:15   0:00 [pvr_timer]
systemd+   398  0.2  0.6  12136  1608 ?        Ssl  23:15   0:00 /lib/systemd/systemd-timesyncd
root       432  0.0  0.0      0     0 ?        S    23:15   0:00 [irq/195-remotep]
root       437  0.0  0.0      0     0 ?        S    23:15   0:00 [irq/197-remotep]
root       456  0.0  0.0      0     0 ?        S    23:15   0:00 [scsi_eh_0]
root       457  0.0  0.0      0     0 ?        S<   23:15   0:00 [scsi_tmf_0]
root       458  0.0  0.0      0     0 ?        S    23:15   0:00 [usb-storage]
root       460  0.0  0.5   1956  1300 ?        Ss   23:15   0:00 /sbin/klogd -n
root       469  2.5  2.5   8864  6408 ?        Ss   23:15   0:01 /usr/sbin/ofonod -n
root       471  0.1  0.7   2600  1812 ?        Ss   23:15   0:00 /lib/systemd/systemd-logind
root       475  0.1  0.5   1908  1440 ?        Ss   23:15   0:00 /usr/libexec/ipsec/starter --daemon charon --nofork
root       480  0.1  0.4   1972  1244 ?        Ss   23:15   0:00 /sbin/syslogd -n -C
avahi      483  0.0  0.9   4660  2484 ?        Ss   23:15   0:00 avahi-daemon: running [am335x-evm.local]
message+   492  0.5  0.9   4320  2496 ?        Ss   23:15   0:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
root       494  0.0  0.0      0     0 ?        S<   23:15   0:00 [bioset]
avahi      501  0.0  0.7   4660  1792 ?        S    23:15   0:00 avahi-daemon: chroot helper
root       513  0.0  0.0      0     0 ?        S    23:15   0:00 [file-storage]
systemd+   535  0.2  0.8   2776  2056 ?        Ss   23:15   0:00 /lib/systemd/systemd-networkd
root       562  0.2  1.8 142008  4528 ?        Ssl  23:15   0:00 /usr/libexec/ipsec/charon
systemd+   677  0.0  0.7   2984  1904 ?        Ss   23:15   0:00 /lib/systemd/systemd-resolved
root       682  0.0  0.4   1780  1184 tty1     Ss+  23:15   0:00 /sbin/agetty --noclear tty1 linux
root       688  0.1  0.8   4864  2132 ttyS0    Ss   23:15   0:00 /bin/login --
root       689  0.0  0.4   1780  1196 ttyGS0   Ss+  23:15   0:00 /sbin/agetty -8 -L ttyGS0 115200 xterm
root       691  0.2  1.1   5160  2984 ?        Ss   23:15   0:00 /usr/sbin/lighttpd -D -f /etc/lighttpd.conf
root       773  0.0  0.0      0     0 ?        S<   23:15   0:00 [pvr_workqueue]
root       807  0.0  0.7   2664  1776 tty4     Ss+  23:15   0:00 /bin/sh /usr/bin/runWeston
root       810  0.5  5.0  19144 12556 tty4     S+   23:15   0:00 weston --idle-time=0
root       815  0.0  0.3   1956   868 ?        Ss   23:15   0:00 /usr/sbin/telnetd
root       822  0.2  2.0   7008  5096 tty4     S+   23:15   0:00 /usr/libexec/weston-keyboard
root       823  0.2  2.0   7016  5024 tty4     S+   23:15   0:00 /usr/libexec/weston-desktop-shell
nobody     829  0.0  0.6   2448  1632 ?        Ss   23:15   0:00 /usr/sbin/thttpd -d /srv/www -p 8080
root       835  0.0  0.3   2292   928 ?        Ss   23:15   0:00 /usr/sbin/rngd -r /dev/urandom
root       843  8.3 24.3 176048 60924 ?        Sl   23:15   0:04 /usr/bin/matrix_browser http://localhost:80/
root       860  0.0  0.0      0     0 ?        S    23:15   0:00 [kworker/0:4]
root       863  0.0  0.0      0     0 ?        S    23:15   0:00 [kworker/0:5]
root       867  0.4  0.0      0     0 ?        S    23:15   0:00 [kworker/0:6]
root       894  1.3  1.7   5348  4388 ?        Ss   23:15   0:00 /lib/systemd/systemd --user  //user용 systemd 실행 (일반서비스) 
root       898  0.0  0.9   7492  2352 ?        S    23:15   0:00 (sd-pam)
root       901  0.0  0.8   2668  2044 ttyS0    S    23:15   0:00 -sh
root       918  0.2  0.4   1780  1212 ?        Ss   23:16   0:00 /sbin/agetty -8 -L ttyS3 115200 xterm
root       922  0.0  0.5   2612  1272 ttyS0    R+   23:16   0:00 ps -aux


2 systemd 와 init script 혼합 (telinit) 

/sbin/telinit  확인필요

  • run level 3 확인 (init.d link)
root@am335x-evm:~# runlevel 
N 3   // multi-user mode 

root@am335x-evm:/etc# ls -al  rc3.d    // Runlevel 3 분석 
drwxr-xr-x    2 root     root          4096 Dec 15  2016 .
drwxr-xr-x   46 root     root          4096 Dec 14 23:15 ..
lrwxrwxrwx    1 root     root            20 Dec 15  2016 S01networking -> ../init.d/networking
lrwxrwxrwx    1 root     root            16 Dec 15  2016 S02dbus-1 -> ../init.d/dbus-1
lrwxrwxrwx    1 root     root            19 Dec 15  2016 S03uim-sysfs -> ../init.d/uim-sysfs
lrwxrwxrwx    1 root     root            16 Dec 15  2016 S08rc.pvr -> ../init.d/rc.pvr
lrwxrwxrwx    1 root     root            18 Dec 15  2016 S10dropbear -> ../init.d/dropbear
lrwxrwxrwx    1 root     root            17 Dec 15  2016 S10telnetd -> ../init.d/telnetd
lrwxrwxrwx    1 root     root            17 Dec 15  2016 S12rpcbind -> ../init.d/rpcbind
lrwxrwxrwx    1 root     root            21 Dec 14 23:36 S15mountnfs.sh -> ../init.d/mountnfs.sh
lrwxrwxrwx    1 root     root            19 Dec 15  2016 S19nfscommon -> ../init.d/nfscommon
lrwxrwxrwx    1 root     root            24 Dec 15  2016 S20busybox-udhcpd -> ../init.d/busybox-udhcpd
lrwxrwxrwx    1 root     root            20 Dec 15  2016 S20hwclock.sh -> ../init.d/hwclock.sh
lrwxrwxrwx    1 root     root            16 Dec 15  2016 S20syslog -> ../init.d/syslog
lrwxrwxrwx    1 root     root            16 Dec 15  2016 S20thttpd -> ../init.d/thttpd
lrwxrwxrwx    1 root     root            22 Dec 15  2016 S21avahi-daemon -> ../init.d/avahi-daemon
lrwxrwxrwx    1 root     root            15 Dec 15  2016 S22ofono -> ../init.d/ofono
lrwxrwxrwx    1 root     root            19 Dec 15  2016 S30rng-tools -> ../init.d/rng-tools
lrwxrwxrwx    1 root     root            18 Dec 15  2016 S70lighttpd -> ../init.d/lighttpd
lrwxrwxrwx    1 root     root            24 Dec 15  2016 S97matrix-gui-2.0 -> ../init.d/matrix-gui-2.0
lrwxrwxrwx    1 root     root            18 Dec 15  2016 S98parse-ip -> ../init.d/parse-ip
lrwxrwxrwx    1 root     root            27 Dec 15  2016 S98thermal-zone-init -> ../init.d/thermal-zone-init
lrwxrwxrwx    1 root     root            22 Dec 15  2016 S99gplv3-notice -> ../init.d/gplv3-notice
lrwxrwxrwx    1 root     root            22 Dec 14 23:36 S99rmnologin.sh -> ../init.d/rmnologin.sh


  • /etc/init.d  확인 
root@am335x-evm:/etc# ls -al init.d/
drwxr-xr-x    2 root     root          4096 Dec 15  2016 .
drwxr-xr-x   46 root     root          4096 Dec 14 23:15 ..
-rw-r--r--    1 root     root          1150 Dec 15 00:09 README
-rwxr-xr-x    1 root     root           250 Dec 14 23:23 alignment.sh
-rwxr-xr-x    1 root     root           811 Dec 14 23:45 alsa-state
-rwxr-xr-x    1 root     root          4491 Dec 15 00:13 avahi-daemon
-rwxr-xr-x    1 root     root           492 Dec 14 23:23 banner.sh
-rwxr-xr-x    1 root     root          1922 Dec 14 23:23 bootmisc.sh
-rwxr-xr-x    1 root     root          1042 Dec 14 23:50 busybox-udhcpd
-rwxr-xr-x    1 root     root          3581 Dec 14 23:23 checkroot.sh
-rwxr-xr-x    1 root     root          2887 Dec 15 00:11 dbus-1
-rwxr-xr-x    1 root     root           526 Dec 14 23:23 devpts.sh
-rwxr-xr-x    1 root     root           353 Dec 14 23:23 dmesg.sh
-rwxr-xr-x    1 root     root          3002 Dec 15 00:00 dropbear
lrwxrwxrwx    1 root     root            33 Dec 15  2016 functions -> /etc/init.d/functions.initscripts
-rw-r--r--    1 root     root          2141 Dec 14 23:23 functions.initscripts
-rwxr-xr-x    1 root     root          2389 Dec 14 23:48 gplv3-notice
-rwxr-xr-x    1 root     root           510 Dec 14 23:23 halt
-rwxr-xr-x    1 root     root           546 Dec 15 00:00 hostapd
-rwxr-xr-x    1 root     root           580 Dec 14 23:23 hostname.sh
-rwxr-xr-x    1 root     root          2541 Dec 14 23:50 hwclock.sh
-rwxr-xr-x    1 root     root           579 Dec 14 23:50 inetd.busybox
-rwxr-xr-x    1 root     root           632 Dec 14 23:52 lighttpd
-rwxr-xr-x    1 root     root          1102 Dec 14 23:51 matrix-gui-2.0
-rwxr-xr-x    1 root     root          1223 Dec 14 23:48 modutils.sh
-rwxr-xr-x    1 root     root           859 Dec 14 23:23 mountall.sh
-rwxr-xr-x    1 root     root          1522 Dec 14 23:23 mountnfs.sh
-rwxr-xr-x    1 root     root          2124 Dec 14 23:48 networking
-rwxr-xr-x    1 root     root          1609 Dec 14 23:49 nfscommon
-rwxr-xr-x    1 root     root           516 Dec 15 00:15 ofono
-rwxr-xr-x    1 root     root          1950 Dec 15 00:00 parse-ip
-rwxr-xr-x    1 root     root          6721 Dec 14 23:23 populate-volatile.sh
-rwxr-xr-x    1 root     root           521 Dec 14 23:50 psplash.sh
-rwxr-xr-x    1 1001     1001          3203 Dec 14 23:15 rc.pvr
-rwxr-xr-x    1 root     root           968 Dec 14 23:23 read-only-rootfs-hook.sh
-rwxr-xr-x    1 root     root           289 Dec 14 23:23 reboot
-rwxr-xr-x    1 root     root           585 Dec 14 23:23 rmnologin.sh
-rwxr-xr-x    1 root     root          1098 Dec 14 23:48 rng-tools
-rwxr-xr-x    1 root     root          1827 Dec 15 00:12 rpcbind
-rwxr-xr-x    1 root     root            25 Dec 14 23:47 run-postinsts
-rwxr-xr-x    1 root     root           336 Dec 14 23:23 save-rtc.sh
-rwxr-xr-x    1 root     root           438 Dec 14 23:23 sendsigs
-rwxr-xr-x    1 root     root           578 Dec 14 23:23 single
-rwxr-xr-x    1 root     root           782 Dec 14 23:23 sysfs.sh
lrwxrwxrwx    1 root     root            26 Dec 15  2016 syslog -> /etc/init.d/syslog.busybox
-rwxr-xr-x    1 root     root          1715 Dec 14 23:50 syslog.busybox
-rwxr-xr-x    1 root     root          3183 Dec 15 00:09 systemd-udevd
-rwxr-xr-x    1 root     root          1455 Dec 14 23:48 telnetd
-rwxr-xr-x    1 root     root           414 Dec 14 23:48 thermal-zone-init
-rwxr-xr-x    1 root     root          1033 Dec 14 23:48 thttpd
-rwxr-xr-x    1 root     root           663 Dec 15 00:00 uim-sysfs
-rwxr-xr-x    1 root     root           516 Dec 14 23:23 umountfs
-rwxr-xr-x    1 root     root           711 Dec 14 23:23 umountnfs.sh
-rwxr-xr-x    1 root     root          1473 Dec 14 23:23 urandom
-rwxr-xr-x    1 root     root          2750 Dec 15 00:00 weston


2.1 systemctl 확인 사항 

상위 init script에 대해 알아봤으니, 이제 systemd의 기본 명령어인 systemctl 을 이용하여 기본설정과 현재 동작하는 순서에 대해서 알아보자.

  • systemctl 명령어
root@am335x-evm:/# systemctl get-default // default mode 확인

root@am335x-evm:/# systemctl list-dependencies multi-user.target  // default-mode 관련부분 list 확인 
.......
root@am335x-evm:/# systemctl list-unit-files // unit 관련 list 전부확인
........


2.2 systemd unit 기능 확인 (AM335x-SK)

  • 현재 boot mode 확인
# systemctl get-default  // 현재 boot mode 3 
multi-user.target

상위 runlevel과 동일하며, 3에 해당하는 유저로, 만약 X Server를 이용한다면, graphical. target으로 나올 것이다.

default.target -> /lib/systemd/system/multi-user.target



  • Unit 분석 방법

이런식으로 현재 분석을 하고 있으며, 추후 더 시간이 있을 경우 다시 분석

$ grep WantedBy=multi-user.target -r /lib/systemd/system  // 확인 
$ grep WantedBy=multi-user.target -r /etc/systemd/system  // 확인
$ grep WantedBy=sysinit.target -r /lib/systemd/system 
$ ls multi-user.target.wants // 확인 

Unit 문법확인
  https://www.freedesktop.org/software/systemd/man/systemd.unit.html

일반적인 사용되는 Unit 전체구조 설명
  https://www.freedesktop.org/software/systemd/man/systemd.special.html#

*. slice 의 부분설명 (machine.slice, system.slice, user.slice )
  https://www.freedesktop.org/software/systemd/man/systemd.special.html#Special%20Slice%20Units

sysinit.target : 기본적으로 실행되는 곳
  https://www.freedesktop.org/software/systemd/man/systemd.special.html#sysinit.target


  • 각 unit 확인 (/etc/systemd/system)
/etc/systemd/system 의 unit은 대부분 link로 구성이 되며 사용되는것은 /lib/systemd/system 에 연결 or 사용되지 않는다면 /dev/null 연결
별도로 추가한다면 이곳에 추가
root@am335x-evm:/# cd /etc/systemd/system  // 사용하는 service는 /lib or /etc/systemd/system 
root@am335x-evm:/etc/systemd/system# ls -al
drwxr-xr-x   11 root     root          4096 Dec 15 02:24 .
drwxr-xr-x    5 root     root          4096 Dec 14 23:43 ..
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 banner.service -> /dev/null  // 사용하지 않는다면, /dev/null link 하며, 사용한다면, /lib/systemd/system link 
drwxr-xr-x    2 root     root          4096 Dec 14 23:15 basic.target.wants
drwxr-xr-x    2 root     root          4096 Dec 15 02:23 bluetooth.target.wants
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 bootmisc.service -> /dev/null
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 busybox-udhcpc.service -> /dev/null
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 checkfs.service -> /dev/null
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 checkroot.service -> /dev/null
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 dbus-1.service -> /dev/null
lrwxrwxrwx    1 root     root            37 Dec 15 02:23 dbus-org.bluez.service -> /lib/systemd/system/bluetooth.service
lrwxrwxrwx    1 root     root            40 Dec 15 02:23 dbus-org.freedesktop.Avahi.service -> /lib/systemd/system/avahi-daemon.service
lrwxrwxrwx    1 root     root            37 Dec 15 02:24 default.target -> /lib/systemd/system/multi-user.target
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 devpts.service -> /dev/null
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 dmesg.service -> /dev/null
drwxr-xr-x    2 root     root          4096 Dec 15 02:22 getty.target.wants
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 hostname.service -> /dev/null
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 hwclock.service -> /dev/null
drwxr-xr-x    2 root     root          4096 Dec 15 02:23 local-fs.target.wants
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 modutils.service -> /dev/null
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 mountall.service -> /dev/null
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 mountnfs.service -> /dev/null
drwxr-xr-x    2 root     root          4096 Dec 15 02:23 multi-user.target.wants
drwxr-xr-x    2 root     root          4096 Dec 15 00:09 network-online.target.wants
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 networking.service -> /dev/null
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 nfscommon.service -> /dev/null
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 nfsserver.service -> /dev/null
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 populate-volatile.service -> /dev/null
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 psplash.service -> /dev/null
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 read-only-rootfs-hook.service -> /dev/null
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 rmnologin.service -> /dev/null
drwxr-xr-x    2 root     root          4096 Dec 15 02:23 sockets.target.wants
-rw-r--r--    1 root     root           327 Dec 15 00:09 sync-clocks.service
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 sysfs.service -> /dev/null
drwxr-xr-x    2 root     root          4096 Dec 14 23:15 sysinit.target.wants
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 syslog.busybox.service -> /dev/null
lrwxrwxrwx    1 root     root            42 Dec 15 02:23 syslog.service -> /lib/systemd/system/busybox-syslog.service
-rw-r--r--    1 root     root           709 Dec 15 00:09 systemd-hostnamed.service
drwxr-xr-x    2 root     root          4096 Dec 15 02:23 systemd-random-seed.service.wants
-rw-r--r--    1 root     root           843 Dec 15 00:09 systemd-udevd.service
lrwxrwxrwx    1 root     root             9 Dec 15 02:23 urandom.service -> /dev/null

  • 각 unit 확인 (/lib/systemd/system)
기본으로 제공되는 unit으로 많이사용하는 것을 이곳에 넣어 보관

root@am335x-evm:/# cd /lib/systemd/system
root@am335x-evm:/lib/systemd/system# ls -al
-rw-r--r--    1 root     root           403 Dec 15 00:09 -.slice
drwxr-xr-x   19 root     root         12288 Dec 15 02:23 .
drwxr-xr-x    8 root     root          4096 Dec 14 23:50 ..
-rw-r--r--    1 root     root           506 Dec 15 00:10 alsa-restore.service
-rw-r--r--    1 root     root           410 Dec 15 00:10 alsa-state.service
lrwxrwxrwx    1 root     root            14 Dec 15 00:09 autovt@.service -> getty@.service
-rw-r--r--    1 root     root          1044 Dec 15 00:13 avahi-daemon.service
-rw-r--r--    1 root     root           874 Dec 15 00:13 avahi-daemon.socket
-rw-r--r--    1 root     root           879 Dec 15 00:09 basic.target
drwxr-xr-x    2 root     root          4096 Dec 15 00:10 basic.target.wants
-rw-r--r--    1 root     root           176 Dec 15 00:13 bluetooth.service
-rw-r--r--    1 root     root           379 Dec 15 00:09 bluetooth.target
-rw-r--r--    1 root     root           358 Dec 15 00:09 busnames.target
drwxr-xr-x    2 root     root          4096 Dec 15 00:09 busnames.target.wants
-rw-r--r--    1 root     root           116 Dec 14 23:50 busybox-klogd.service
-rw-r--r--    1 root     root           270 Dec 14 23:50 busybox-syslog.service
-rw-r--r--    1 root     root           770 Dec 15 00:09 console-getty.service
-rw-r--r--    1 root     root           752 Dec 15 00:09 console-shell.service
-rw-r--r--    1 root     root           791 Dec 15 00:09 container-getty@.service
lrwxrwxrwx    1 root     root            13 Dec 15 00:09 ctrl-alt-del.target -> reboot.target
lrwxrwxrwx    1 root     root            25 Dec 15 00:09 dbus-org.freedesktop.hostname1.service -> systemd-hostnamed.service
lrwxrwxrwx    1 root     root            23 Dec 15 00:09 dbus-org.freedesktop.locale1.service -> systemd-localed.service
lrwxrwxrwx    1 root     root            22 Dec 15 00:09 dbus-org.freedesktop.login1.service -> systemd-logind.service
lrwxrwxrwx    1 root     root            24 Dec 15 00:09 dbus-org.freedesktop.machine1.service -> systemd-machined.service
lrwxrwxrwx    1 root     root            24 Dec 15 00:09 dbus-org.freedesktop.network1.service -> systemd-networkd.service
lrwxrwxrwx    1 root     root            24 Dec 15 00:09 dbus-org.freedesktop.resolve1.service -> systemd-resolved.service
lrwxrwxrwx    1 root     root            25 Dec 15 00:09 dbus-org.freedesktop.timedate1.service -> systemd-timedated.service
-rw-r--r--    1 root     root           366 Dec 15 00:11 dbus.service
-rw-r--r--    1 root     root           106 Dec 15 00:11 dbus.socket
drwxr-xr-x    2 root     root          4096 Dec 15 00:11 dbus.target.wants
-rw-r--r--    1 root     root          1008 Dec 15 00:09 debug-shell.service
lrwxrwxrwx    1 root     root            16 Dec 15 00:09 default.target -> graphical.target
-rw-r--r--    1 root     root           670 Dec 15 00:09 dev-hugepages.mount
-rw-r--r--    1 root     root           624 Dec 15 00:09 dev-mqueue.mount
-rw-r--r--    1 root     root           131 Dec 15 00:00 dropbear.socket
-rw-r--r--    1 root     root           384 Dec 15 00:00 dropbear@.service
-rw-r--r--    1 root     root           453 Dec 15 00:00 dropbearkey.service
-rw-r--r--    1 root     root           995 Dec 15 00:09 emergency.service
-rw-r--r--    1 root     root           431 Dec 15 00:09 emergency.target
-rw-r--r--    1 root     root           501 Dec 15 00:09 exit.target
-rw-r--r--    1 root     root           440 Dec 15 00:09 final.target
-rw-r--r--    1 root     root           420 Dec 15 00:00 gadget-init.service
-rw-r--r--    1 root     root           460 Dec 15 00:09 getty.target
-rw-r--r--    1 root     root          1536 Dec 15 00:09 getty@.service
-rw-r--r--    1 root     root           198 Dec 14 23:48 gplv3-notice.service
-rw-r--r--    1 root     root           558 Dec 15 00:09 graphical.target
drwxr-xr-x    2 root     root          4096 Dec 15 00:09 graphical.target.wants
-rw-r--r--    1 root     root           565 Dec 15 00:09 halt-local.service
-rw-r--r--    1 root     root           487 Dec 15 00:09 halt.target
-rw-r--r--    1 root     root           447 Dec 15 00:09 hibernate.target
-rw-r--r--    1 root     root           468 Dec 15 00:09 hybrid-sleep.target
-rw-r--r--    1 root     root           630 Dec 15 00:09 initrd-cleanup.service
-rw-r--r--    1 root     root           553 Dec 15 00:09 initrd-fs.target
-rw-r--r--    1 root     root           790 Dec 15 00:09 initrd-parse-etc.service
-rw-r--r--    1 root     root           526 Dec 15 00:09 initrd-root-fs.target
-rw-r--r--    1 root     root           640 Dec 15 00:09 initrd-switch-root.service
-rw-r--r--    1 root     root           691 Dec 15 00:09 initrd-switch-root.target
-rw-r--r--    1 root     root           664 Dec 15 00:09 initrd-udevadm-cleanup-db.service
-rw-r--r--    1 root     root           671 Dec 15 00:09 initrd.target
-rw-r--r--    1 root     root           501 Dec 15 00:09 kexec.target
-rw-r--r--    1 root     root           677 Dec 15 00:09 kmod-static-nodes.service
-rw-r--r--    1 root     root           658 Dec 15 00:09 ldconfig.service
-rw-r--r--    1 root     root           292 Dec 14 23:52 lighttpd.service
-rw-r--r--    1 root     root           395 Dec 15 00:09 local-fs-pre.target
-rw-r--r--    1 root     root           507 Dec 15 00:09 local-fs.target
drwxr-xr-x    2 root     root          4096 Dec 15 00:09 local-fs.target.wants
-rw-r--r--    1 root     root           405 Dec 15 00:09 machine.slice
-rw-r--r--    1 root     root           531 Dec 15 00:09 machines.target
-rw-r--r--    1 root     root           492 Dec 15 00:09 multi-user.target
drwxr-xr-x    2 root     root          4096 Dec 15 02:22 multi-user.target.wants
-rw-r--r--    1 root     root           464 Dec 15 00:09 network-online.target
-rw-r--r--    1 root     root           461 Dec 15 00:09 network-pre.target
-rw-r--r--    1 root     root           480 Dec 15 00:09 network.target
-rw-r--r--    1 root     root           250 Dec 14 23:49 nfs-statd.service
-rw-r--r--    1 root     root           514 Dec 15 00:09 nss-lookup.target
-rw-r--r--    1 root     root           473 Dec 15 00:09 nss-user-lookup.target
-rw-r--r--    1 root     root           183 Dec 15 00:15 ofono.service
-rw-r--r--    1 root     root           521 Dec 14 23:50 opkg-configure.service
-rw-r--r--    1 root     root           554 Dec 15 00:09 org.freedesktop.hostname1.busname
-rw-r--r--    1 root     root           550 Dec 15 00:09 org.freedesktop.locale1.busname
-rw-r--r--    1 root     root           598 Dec 15 00:09 org.freedesktop.login1.busname
-rw-r--r--    1 root     root           549 Dec 15 00:09 org.freedesktop.machine1.busname
-rw-r--r--    1 root     root           675 Dec 15 00:09 org.freedesktop.network1.busname
-rw-r--r--    1 root     root           763 Dec 15 00:09 org.freedesktop.resolve1.busname
-rw-r--r--    1 root     root           480 Dec 15 00:09 org.freedesktop.systemd1.busname
-rw-r--r--    1 root     root           538 Dec 15 00:09 org.freedesktop.timedate1.busname
-rw-r--r--    1 root     root           354 Dec 15 00:09 paths.target
-rw-r--r--    1 root     root           552 Dec 15 00:09 poweroff.target
drwxr-xr-x    2 root     root          4096 Dec 15 00:09 poweroff.target.wants
-rw-r--r--    1 root     root           377 Dec 15 00:09 printer.target
-rw-r--r--    1 root     root           178 Dec 15 00:16 ptpd.service
-rw-r--r--    1 root     root           576 Dec 15 00:09 quotaon.service
-rw-r--r--    1 root     root           612 Dec 15 00:09 rc-local.service
-rw-r--r--    1 root     root           543 Dec 15 00:09 reboot.target
drwxr-xr-x    2 root     root          4096 Dec 15 00:09 reboot.target.wants
-rw-r--r--    1 root     root           396 Dec 15 00:09 remote-fs-pre.target
-rw-r--r--    1 root     root           482 Dec 15 00:09 remote-fs.target
-rw-r--r--    1 root     root           988 Dec 15 00:09 rescue.service
-rw-r--r--    1 root     root           486 Dec 15 00:09 rescue.target
drwxr-xr-x    2 root     root          4096 Dec 15 00:09 rescue.target.wants
-rw-r--r--    1 root     root           212 Dec 15 00:12 rpcbind.service
-rw-r--r--    1 root     root           132 Dec 15 00:12 rpcbind.socket
-rw-r--r--    1 root     root           500 Dec 15 00:09 rpcbind.target
-rw-r--r--    1 root     root           385 Dec 14 23:47 run-postinsts.service
lrwxrwxrwx    1 root     root            15 Dec 15 00:09 runlevel0.target -> poweroff.target
lrwxrwxrwx    1 root     root            13 Dec 15 00:09 runlevel1.target -> rescue.target
drwxr-xr-x    2 root     root          4096 Dec 15 00:09 runlevel1.target.wants
lrwxrwxrwx    1 root     root            17 Dec 15 00:09 runlevel2.target -> multi-user.target
drwxr-xr-x    2 root     root          4096 Dec 15 00:09 runlevel2.target.wants
lrwxrwxrwx    1 root     root            17 Dec 15 00:09 runlevel3.target -> multi-user.target
drwxr-xr-x    2 root     root          4096 Dec 15 00:09 runlevel3.target.wants
lrwxrwxrwx    1 root     root            17 Dec 15 00:09 runlevel4.target -> multi-user.target
drwxr-xr-x    2 root     root          4096 Dec 15 00:09 runlevel4.target.wants
lrwxrwxrwx    1 root     root            16 Dec 15 00:09 runlevel5.target -> graphical.target
drwxr-xr-x    2 root     root          4096 Dec 15 00:09 runlevel5.target.wants
lrwxrwxrwx    1 root     root            13 Dec 15 00:09 runlevel6.target -> reboot.target
-rw-r--r--    1 root     root          1059 Dec 14 23:23 serial-getty@.service
-rw-r--r--    1 root     root           402 Dec 15 00:09 shutdown.target
-rw-r--r--    1 root     root           362 Dec 15 00:09 sigpwr.target
-rw-r--r--    1 root     root           420 Dec 15 00:09 sleep.target
-rw-r--r--    1 root     root           409 Dec 15 00:09 slices.target
-rw-r--r--    1 root     root           380 Dec 15 00:09 smartcard.target
-rw-r--r--    1 root     root           356 Dec 15 00:09 sockets.target
drwxr-xr-x    2 root     root          4096 Dec 15 02:22 sockets.target.wants
-rw-r--r--    1 root     root           380 Dec 15 00:09 sound.target
-rw-r--r--    1 root     root           204 Dec 15 00:03 strongswan.service
-rw-r--r--    1 root     root           441 Dec 15 00:09 suspend.target
-rw-r--r--    1 root     root           353 Dec 15 00:09 swap.target
-rw-r--r--    1 root     root           715 Dec 15 00:09 sys-fs-fuse-connections.mount
-rw-r--r--    1 root     root           719 Dec 15 00:09 sys-kernel-config.mount
-rw-r--r--    1 root     root           662 Dec 15 00:09 sys-kernel-debug.mount
-rw-r--r--    1 root     root           518 Dec 15 00:09 sysinit.target
drwxr-xr-x    2 root     root          4096 Dec 15 02:22 sysinit.target.wants
lrwxrwxrwx    1 root     root             9 Dec 14 23:50 syslog.service -> /dev/null
-rw-r--r--    1 root     root          1235 Dec 15 00:09 syslog.socket
-rw-r--r--    1 root     root           585 Dec 15 00:09 system-update.target
-rw-r--r--    1 root     root           436 Dec 15 00:09 system.slice
-rw-r--r--    1 root     root           646 Dec 15 00:09 systemd-ask-password-console.path
-rw-r--r--    1 root     root           653 Dec 15 00:09 systemd-ask-password-console.service
-rw-r--r--    1 root     root           574 Dec 15 00:09 systemd-ask-password-wall.path
-rw-r--r--    1 root     root           681 Dec 15 00:09 systemd-ask-password-wall.service
-rw-r--r--    1 root     root           724 Dec 15 00:09 systemd-backlight@.service
-rw-r--r--    1 root     root           650 Dec 15 00:09 systemd-bootchart.service
-rw-r--r--    1 root     root           497 Dec 15 00:09 systemd-exit.service
-rw-r--r--    1 root     root           755 Dec 15 00:09 systemd-firstboot.service
-rw-r--r--    1 root     root           574 Dec 15 00:09 systemd-fsck-root.service
-rw-r--r--    1 root     root           600 Dec 15 00:09 systemd-fsck@.service
-rw-r--r--    1 root     root           544 Dec 15 00:09 systemd-halt.service
-rw-r--r--    1 root     root           631 Dec 15 00:09 systemd-hibernate-resume@.service
-rw-r--r--    1 root     root           501 Dec 15 00:09 systemd-hibernate.service
-rw-r--r--    1 root     root           710 Dec 15 00:09 systemd-hostnamed.service
-rw-r--r--    1 root     root           778 Dec 15 00:09 systemd-hwdb-update.service
-rw-r--r--    1 root     root           519 Dec 15 00:09 systemd-hybrid-sleep.service
-rw-r--r--    1 root     root           480 Dec 15 00:09 systemd-initctl.service
-rw-r--r--    1 root     root           524 Dec 15 00:09 systemd-initctl.socket
-rw-r--r--    1 root     root           667 Dec 15 00:09 systemd-journal-catalog-update.service
-rw-r--r--    1 root     root           731 Dec 15 00:09 systemd-journal-flush.service
-rw-r--r--    1 root     root           607 Dec 15 00:09 systemd-journald-audit.socket
-rw-r--r--    1 root     root          1090 Dec 15 00:09 systemd-journald-dev-log.socket
-rw-r--r--    1 root     root          1293 Dec 15 00:09 systemd-journald.service
-rw-r--r--    1 root     root           842 Dec 15 00:09 systemd-journald.socket
-rw-r--r--    1 root     root           557 Dec 15 00:09 systemd-kexec.service
-rw-r--r--    1 root     root           691 Dec 15 00:09 systemd-localed.service
-rw-r--r--    1 root     root          1126 Dec 15 00:09 systemd-logind.service
-rw-r--r--    1 root     root           693 Dec 15 00:09 systemd-machine-id-commit.service
-rw-r--r--    1 root     root           948 Dec 15 00:09 systemd-machined.service
-rw-r--r--    1 root     root           967 Dec 15 00:09 systemd-modules-load.service
-rw-r--r--    1 root     root           685 Dec 15 00:09 systemd-networkd-wait-online.service
-rw-r--r--    1 root     root          1339 Dec 15 00:09 systemd-networkd.service
-rw-r--r--    1 root     root           591 Dec 15 00:09 systemd-networkd.socket
-rw-r--r--    1 root     root          1378 Dec 15 00:09 systemd-nspawn@.service
-rw-r--r--    1 root     root           553 Dec 15 00:09 systemd-poweroff.service
-rw-r--r--    1 root     root           618 Dec 15 00:09 systemd-quotacheck.service
-rw-r--r--    1 root     root           717 Dec 15 00:09 systemd-random-seed.service
-rw-r--r--    1 root     root           548 Dec 15 00:09 systemd-reboot.service
-rw-r--r--    1 root     root           757 Dec 15 00:09 systemd-remount-fs.service
-rw-r--r--    1 root     root           907 Dec 15 00:09 systemd-resolved.service
-rw-r--r--    1 root     root           696 Dec 15 00:09 systemd-rfkill.service
-rw-r--r--    1 root     root           617 Dec 15 00:09 systemd-rfkill.socket
-rw-r--r--    1 root     root           497 Dec 15 00:09 systemd-suspend.service
-rw-r--r--    1 root     root           649 Dec 15 00:09 systemd-sysctl.service
-rw-r--r--    1 root     root           655 Dec 15 00:09 systemd-timedated.service
-rw-r--r--    1 root     root          1032 Dec 15 00:09 systemd-timesyncd.service
-rw-r--r--    1 root     root           598 Dec 15 00:09 systemd-tmpfiles-clean.service
-rw-r--r--    1 root     root           450 Dec 15 00:09 systemd-tmpfiles-clean.timer
-rw-r--r--    1 root     root           703 Dec 15 00:09 systemd-tmpfiles-setup-dev.service
-rw-r--r--    1 root     root           683 Dec 15 00:09 systemd-tmpfiles-setup.service
-rw-r--r--    1 root     root           823 Dec 15 00:09 systemd-udev-settle.service
-rw-r--r--    1 root     root           743 Dec 15 00:09 systemd-udev-trigger.service
-rw-r--r--    1 root     root           578 Dec 15 00:09 systemd-udevd-control.socket
-rw-r--r--    1 root     root           570 Dec 15 00:09 systemd-udevd-kernel.socket
-rw-r--r--    1 root     root           842 Dec 15 00:09 systemd-udevd.service
-rw-r--r--    1 root     root           630 Dec 15 00:09 systemd-update-done.service
-rw-r--r--    1 root     root           757 Dec 15 00:09 systemd-update-utmp-runlevel.service
-rw-r--r--    1 root     root           754 Dec 15 00:09 systemd-update-utmp.service
-rw-r--r--    1 root     root           573 Dec 15 00:09 systemd-user-sessions.service
-rw-r--r--    1 root     root           613 Dec 15 00:09 systemd-vconsole-setup.service
-rw-r--r--    1 root     root           395 Dec 15 00:09 time-sync.target
-rw-r--r--    1 root     root           405 Dec 15 00:09 timers.target
drwxr-xr-x    2 root     root          4096 Dec 15 00:09 timers.target.wants
-rw-r--r--    1 root     root           625 Dec 15 00:09 tmp.mount
-rw-r--r--    1 root     root           417 Dec 15 00:09 umount.target
-rw-r--r--    1 root     root           392 Dec 15 00:09 user.slice
-rw-r--r--    1 root     root           528 Dec 15 00:09 user@.service
-rw-r--r--    1 root     root           475 Dec 15 00:09 var-lib-machines.mount
-rw-r--r--    1 root     root           496 Dec 14 23:22 var-volatile-lib.service



root@am335x-evm:/lib/systemd/system# cd /usr/lib/systemd // system 이 존재하지 않음 
root@am335x-evm:/usr/lib/systemd# ls -al
drwxr-xr-x    6 root     root          4096 Dec 15  2016 .
drwxr-xr-x   56 root     root         53248 Dec 15  2016 ..
drwxr-xr-x    2 root     root          4096 Dec 15  2016 catalog
drwxr-xr-x    2 root     root          4096 Dec 15  2016 network
drwxr-xr-x    2 root     root          4096 Dec 15  2016 user
drwxr-xr-x    2 root     root          4096 Dec 15  2016 user-generators


  • 전체 service status 확인 및 기본분석 
방향키가 상 아래가 동작이 되며, 실시간으로 반영이 되기 때문에 확인가능
서비스 종료를 원한다면 q를 사용
  1. /etc/systemd/system.conf  : /lib/systemd/systemd --system 설정 : Consol에서만 가능  
  2. /etc/systemd/user.conf : /lib/systemd/systemd --user 설정 : SSH로 로그인시 확인가능


#systemctl status  // 현재 전체 service 확인 
?? am335x-evm
    State: running
     Jobs: 0 queued
   Failed: 0 units
    Since: Thu 1970-01-01 00:00:02 UTC; 46 years 11 months ago
   CGroup: /
           ???€init.scope  // init.scope 영역 , 만약 ssh를 사용하여 login을 한다면, user.slice가 존재 
           ?? ???€1 /sbin/init  // PID 1 /sbin/init
           ???€system.slice  //systemd 로 실행되는 각 service들 
           ?? ???€avahi-daemon.service
           ?? ?? ???€502 avahi-daemon: running [am335x-evm.local  // 502는 PID, init scirpt도 존재 
           ?? ?? ???€524 avahi-daemon: chroot helpe
           ?? ???€dbus.service
           ?? ??  ???€475 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
           ?? ???€lighttpd.service
           ?? ?? ???€695 /usr/sbin/lighttpd -D -f /etc/lighttpd.conf
           ?? ???€matrix-gui-2.0.service
           ?? ?? ???€857 /usr/bin/matrix_browser http://localhost:80/
           ?? ???€weston.service
           ?? ?? ???€811 /bin/sh /usr/bin/runWeston
           ?? ?? ???€814 weston --idle-time=0
           ?? ?? ???€826 /usr/libexec/weston-keyboard
           ?? ?? ???€828 /usr/libexec/weston-desktop-shell
           ?? ???€busybox-klogd.service
           ?? ?? ???€506 /sbin/klogd -n
           ?? ???€telnetd.service
           ?? ?? ???€819 /usr/sbin/telnetd
           ?? ???€system-serial\x2dgetty.slice
           ?? ?? ???€serial-getty@ttyS3.service
           ?? ?? ?? ???€1018 /sbin/agetty -8 -L ttyS3 115200 xterm
           ?? ?? ???€serial-getty@ttyGS0.service
           ?? ??   ???€685 /sbin/agetty -8 -L ttyGS0 115200 xterm
           ?? ???€systemd-journald.service
           ?? ?? ???€99 /lib/systemd/systemd-journald
           ?? ???€busybox-udhcpd.service
           ?? ?? ???€833 /usr/sbin/udhcpd -S /etc/udhcpd_usb0.conf
           ?? ???€thttpd.service
           ?? ?? ???€831 /usr/sbin/thttpd -d /srv/www -p 8080
           ?? ???€systemd-resolved.service
           ?? ?? ???€687 /lib/systemd/systemd-resolved
           ?? ???€systemd-timesyncd.service
           ?? ?? ???€396 /lib/systemd/systemd-timesyncd
           ?? ???€systemd-logind.service
           ?? ?? ???€465 /lib/systemd/systemd-logind
           ?? ???€systemd-networkd.service
           ?? ?? ???€496 /lib/systemd/systemd-networkd
           ?? ???€system-getty.slice
           ?? ?? ???€getty@tty1.service
           ?? ??   ???€682 /sbin/agetty --noclear tty1 linux
           ?? ???€ofono.service
           .......



  • systemd 관련 관리
  https://wiki.archlinux.org/index.php/systemd
  https://websetnet.com/ko/manage-systemd-services-and-units/
  http://www.phytec.eu/fileadmin/user_upload/downloads/Manuals/L-818e_1.pdf

  • Frame buffer Console 기능
  https://e2e.ti.com/support/embedded/linux/f/354/t/324198