了解 OpenWRT / Procd
更新記錄
item | note |
---|---|
20170331 | 第一版 |
目錄
Procd
openwrt-procd
在OpenWrt規劃下,procd主要取代busybox(initd,klogd,syslogd,watchdog)等功能Init Scripts
procd的init脚本]
舊的OpenWrt採用iniscript,新的改為採用procdopenwrt深入学习笔记.pdf
原生的Linux内核默认启动的第一个用户空间进程是/sbin/init
Openwrt将其修改为默认启动的第一个用户空间进程为/etc/preinit
procd-2015-10-29.1
- 產生檔案如下
1
2
3
4
5-rwxr-xr-x 1 root root 12K Apr 8 2016 askfirst
-rwxr-xr-x 1 root root 55K Apr 8 2016 init
-rwxr-xr-x 1 root root 255K Apr 8 2016 procd
-rwxr-xr-x 1 root root 8.7K Apr 8 2016 libsetlbf.so
-rwxr-xr-x 1 root root 19K Apr 8 2016 udevtrigger
procd
- procd帶參數說明如下:
-sPath to ubus socket
-hrun as hotplug daemon
-dEnable debug messages
procd main
- procd
init
- init
由init會帶出下到兩個程序- /sbin/procd -H /etc/hotplug-preinit.json
- /bin/sh /etc/preinit
/etc/hotplug-preinit.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21root@OpenWrt:/etc# cat /etc/hotplug-preinit.json
[
[ "case", "ACTION", {
"add": [
[ "if",
[ "has", "FIRMWARE" ],
[
[ "exec", "/sbin/hotplug-call", "%SUBSYSTEM%" ],
[ "load-firmware", "/lib/firmware" ],
[ "return" ]
]
],
],
}, ],
[ "if",
[ "and",
[ "eq", "SUBSYSTEM", "button" ],
],
[ "exec", "/etc/rc.button/failsafe" ]
],
]/etc/preinit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47root@OpenWrt:/etc# cat preinit
#!/bin/sh
# Copyright (C) 2006 OpenWrt.org
# Copyright (C) 2010 Vertical Communications
[ -z "$PREINIT" ] && exec /sbin/init
export PATH=/usr/sbin:/usr/bin:/sbin:/bin
pi_ifname=
pi_ip=192.168.1.1
pi_broadcast=192.168.1.255
pi_netmask=255.255.255.0
fs_failsafe_ifname=
fs_failsafe_ip=192.168.1.1
fs_failsafe_broadcast=192.168.1.255
fs_failsafe_netmask=255.255.255.0
fs_failsafe_wait_timeout=2
pi_suppress_stderr="y"
pi_init_suppress_stderr="y"
pi_init_path="/usr/sbin:/usr/bin:/sbin:/bin"
pi_init_cmd="/sbin/init"
. /lib/functions.sh
. /lib/functions/preinit.sh
. /lib/functions/system.sh
boot_hook_init preinit_essential
boot_hook_init preinit_main
boot_hook_init failsafe
boot_hook_init initramfs
boot_hook_init preinit_mount_root
for pi_source_file in /lib/preinit/*; do
. $pi_source_file
done
boot_run_hook preinit_essential
pi_mount_skip_next=false
pi_jffs2_mount_success=false
pi_failsafe_net_message=false
boot_run_hook preinit_main/lib/preinit/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16root@OpenWrt:/etc# ls -l /lib/preinit/
-rw-rw-r-- 1 root root 111 Apr 6 14:58 02_default_set_state
-rw-rw-r-- 1 root root 105 Apr 6 14:58 03_preinit_do_ar71xx.sh
-rw-rw-r-- 1 root root 1102 Apr 6 14:58 05_set_iface_mac_ar71xx
-rw-rw-r-- 1 root root 679 Apr 6 14:58 05_set_preinit_iface_ar71xx
-rw-rw-r-- 1 root root 352 Apr 6 14:58 10_indicate_failsafe
-rw-rw-r-- 1 root root 1033 Apr 6 14:58 10_indicate_preinit
-rw-rw-r-- 1 root root 346 Apr 6 14:58 10_sysinfo
-rw-rw-r-- 1 root root 2400 Apr 6 14:58 30_failsafe_wait
-rw-rw-r-- 1 root root 257 Apr 6 14:58 40_run_failsafe_hook
-rw-rw-r-- 1 root root 254 Apr 6 14:58 50_indicate_regular_preinit
-rw-rw-r-- 1 root root 243 Apr 6 14:58 70_initramfs_test
-rw-rw-r-- 1 root root 316 Apr 6 14:58 80_mount_root
-rw-rw-r-- 1 root root 1178 Apr 6 14:58 82_patch_ath10k
-rw-rw-r-- 1 root root 362 Apr 6 14:58 99_10_failsafe_login
-rw-rw-r-- 1 root root 162 Apr 6 14:58 99_10_run_initps
只看到procd,沒有init?1
2
3
4
5
6root@OpenWrt:/etc/rc.d# ps
PID USER VSZ STAT COMMAND
1 root 1408 S /sbin/procd
2 root 0 SW [kthreadd]
3 root 0 SW [ksoftirqd/0]
4 root 0 SW [kworker/0:0]
OpenWRT開機程序
- OpenWRT開機程序如下
先執行init,之後是procd1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16[ 2.150000] Freeing unused kernel memory: 252K (80371000 - 803b0000)
[ 3.690000] init: Console is alive
[ 3.700000] init: - watchdog -
[ 5.700000] init: - preinit -
[ 6.560000] random: procd urandom read with 10 bits of entropy available
Press the [f] key and hit [enter] to enter failsafe mode
Press the [1], [2], [3] or [4] key and hit [enter] to select the debug level
[ 10.020000] jffs2: notice: (328) jffs2_build_xattr_subsystem: complete building xattr subsystem, 0 of xdatum (0 unchecked, 0 orphan) and 0 of xref (0 dead, 0 orphan) found.
[ 10.040000] mount_root: switching to jffs2 overlay
[ 10.090000] procd: - early -
[ 10.100000] procd: - watchdog -
[ 11.030000] procd: - ubus -
[ 12.040000] procd: - init -
Please press Enter to activate this console.
[ 13.140000] NET: Registered protocol family 10
[ 13.150000] ip6_tables: (C) 2000-2006 Netfilter Core Team