Lines of
init.mk
from check-in f49abe7565
that are changed by the sequence of edits moving toward
check-in 1c381d3eeb:
1: # Meta targets
2:
3: TARGETS:=adjkerntz bootfs cleanvar cleartmp cloned devfs dmesg dumpon fsck \
4: hostname ip6addrctl kld ldconfig microcode mixer mount mountlate \
5: mounttmpfs msgs netif newsyslog nextboot nfsclient pf pwcheck random root \
6: runshm savecore swap sysctl sysdb udevd_check utmpx wlans zfs
7:
8: OTHER_TARGETS+=mixer_exit nfsclient_exit random_exit
9:
10: DAEMON: pwcheck sysctl sysdb NETWORK SERVERS ldconfig nfsclient cleartmp pflogd
11:
12: LOGIN: DAEMON dntpd msgs powerd pflogd
13:
14: NETWORK: netif devd hostname
15:
16: SERVERS: swap mountlate syslogd newsyslog
17:
18: SERVICE: netif mount random hostname cleanvar
19:
20: # regular targets
21:
22: adjkerntz: random mount
23: echo "MRC:$@> Adjust kernel timezone."
24: adjkerntz -i &
25:
26: bootfs: fsck
27: echo "MRC:$@> Checking whether we need /boot mounted."
28: mount -vadr | grep -q ' /boot$$' && mount -r /boot || true
29:
30: cleanvar: mount
31: echo "MRC:$@> Cleaning '/var's."
32: .for dir in ${CLEANVAR_DIRS}
33: if [ -d ${dir} ]; then \
34: /rescue/find ${dir} -mindepth 1 -delete; \
35: fi
36: .endfor
37:
38: cleartmp: mountlate
39: echo "MRC:$@> Clearing tmp."
40: find -x /tmp -mindepth 1 ! -name lost+found ! -name snapshots \
41: ! -path "./snapshots/*" ! -name quota.user ! -name quota.group \
42: -delete -type d -prune
43: rm -fr /tmp/.X11-unix /tmp/.X*-lock
44: mkdir -m 1777 /tmp/.X11-unix
45:
46: cloned: kld
47: .if !empty(CLONED_INTERFACES)
48: echo "MRC:$@> Cloning interfaces: ${CLONED_INTERFACES}"
49: . for iface in ${CLONED_INTERFACES}
50: ifconfig ${iface} create
51: . endfor
52: .endif
53:
54: devfs:
55: echo "MRC:$@> Applying rules: ${DEVFS_CONFIG_FILES}"
56: .for file in ${DEVFS_CONFIG_FILES}
57: . if exists(${file})
58: devfsctl -a -f ${file}
59: . endif
60: .endfor
61:
62: dmesg: mountlate
63: .if !empty(DMESG_FILE)
64: echo "MRC:$@> Writing dmesg."
65: ( umask 022 ; dmesg -a > ${DMESG_FILE} ;)
66: .endif
67:
68: dumpon: random
69: .if !empty(DUMPDEV)
70: if [ -e ${DUMPDEV} ]; then \
71: echo "MRC:$@> Setting dumpon device to ${DUMPDEV}"; \
72: dumpon -v ${DUMPDEV}; \
73: fi
74: .endif
75:
76: fsck:
77: echo "MRC:$@> Checking disks."
78: fsck -p; \
79: case $$? in \
80: 0) ;; \
81: 2) exit 1 \
82: ;; \
83: 4) echo "Rebooting..."; \
84: reboot ;\
85: echo "Reboot failed; help!"; \
86: exit 1 \
87: ;; \
88: 8) if [ -n "$${FSCK_Y_ENABLE}" ]; then \
89: echo "File system preen failed, trying fsck -y."; \
90: fsck -y || { \
91: echo "Automatic file system check failed; help!"; \
92: exit 1; \
93: }; \
94: else \
95: echo "Automatic file system check failed; help!"; \
96: exit 1; \
97: fi \
98: ;; \
99: 12) echo "Boot interrupted."; \
100: exit 1 \
101: ;; \
102: 130) exit 1 \
103: ;; \
104: *) echo "Unknown error, help!"; \
105: exit 1 \
106: ;; \
107: esac
108:
109: hostname:
110: echo "MRC:$@> Setting to ${HOSTNAME}."
111: hostname ${HOSTNAME}
112:
113: ip6addrctl: root mount
114: .if empty(HAS_INET6:tl:Mno)
115: /usr/sbin/ip6addrctl flush >/dev/null 2>&1
116: . if !empty(PREFER:MIPV6)
117: echo "MRC:$@> Setting v4/v6 address selection defaults (prefer v6)."
118: printf "\
119: ::1/128 50 0\n\
120: ::/0 40 1\n\
121: ::ffff:0:0/96 35 4\n\
122: 2002::/16 30 2\n\
123: 2001::/32 5 5\n\
124: fc00::/7 3 13\n\
125: ::/96 1 3\n\
126: fec0::/10 1 11\n\
127: 3ffe::/16 1 12\n" |\
128: /usr/sbin/ip6addrctl install /dev/stdin
129: . elif !empty(PREFER:MIPV4)
130: echo "MRC:$@> Setting v4/v6 address selection defaults (prefer v6)."
131: printf "\
132: ::1/128 50 0\n\
133: ::/0 40 1\n\
134: ::ffff:0:0/96 100 4\n\
135: 2002::/16 30 2\n\
136: 2001::/32 5 5\n\
137: fc00::/7 3 13\n\
138: ::/96 1 3\n\
139: fec0::/10 1 11\n\
140: 3ffe::/16 1 12\n" |\
141: /usr/sbin/ip6addrctl install /dev/stdin
142: . else
143: echo "MRC:$@> Setting v4/v6 address selection defaults (none)."
144: . endif
145: .else
146: echo "MRC:$@> No INET6 support in kernel."
147: .endif
148:
149: kld: bootfs
150: .if defined(KLD_LIST)
151: echo "MRC:$@> Loading kernel modules: ${KLD_LIST}"
152: . for KLD in ${KLD_LIST}
153: kldload -n ${KLD} || echo "MRC:$@> Failed to load module: ${KLD}"
154: . endfor
155: true
156: .endif
157:
158: # ldconfig
159: .for path in ${LDCONFIG_PATHS} /etc/ld-elf.so.conf
160: .if exists(${path})
161: ldc+=${path}
162: .endif
163: .endfor
164:
165: .for dir in ${LDCONFIG_LOCAL_DIRS}
166: .if exists(${dir})
167: ldc+=${:!find ${dir} -type f!}
168: .endif
169: .endfor
170:
171: ldconfig: mountlate
172: echo "MRC:$@> Initializing shared libraries: ${ldc}"
173: ldconfig -elf ${ldc}
174:
175: microcode: mountlate
176: if [ -d /usr/local/share/cpucontrol ]; then \
177: echo "MRC:$@> Updating microcode."; \
178: if kldload -n cpuctl; then \
179: for cpu in $$(jot ${NCPU} 0); do \
180: cpucontrol -u /dev/cpuctl$${cpu}; \
181: done; \
182: for cpu in $$(jot ${NCPU} 1); do \
183: cpucontrol -e /dev/cpuctl$${cpu}; \
184: done \
185: else \
186: echo "MRC:$@> Failed to load [cpuctl]."; \
187: fi \
188: fi
189:
f49abe7565 2024-12-29 190: mixer: mount cleanvar kld
191: echo "MRC:$@> Restoring levels."
192: for mixer in $$(find /dev -name 'mixer*' | sed 's|^/dev/||'); do \
193: if [ -r /var/db/$${mixer}-state ]; then \
194: mixer -f /dev/$${mixer} `cat /var/db/$${mixer}-state` || \
195: echo "MRC:$@> /dev/$${mixer} config load failed."; \
196: fi \
197: done
198:
199: mixer_exit:
200: echo "MRC:$@> Saving mixer levels."
201: for mixer in $$(find /dev -name 'mixer*' | sed 's|^/dev/||'); do \
202: if [ -r /dev/$${mixer} ]; then \
203: mixer -f /dev/$${mixer} -s > /var/db/$${mixer}-state; \
204: fi \
205: done
206:
207: DAEMON_EXIT: mixer_exit
208:
209: excludes=${NETFS_TYPES:C/:.*//}
210:
211: mount: root zfs
212: echo "MRC:$@> Mount local FS."
213: mount -p | awk '$$1~/^map$$/{next}$$3!~/^(tmpfs|null|procfs)$$/{print"mount -uo rw "$$1}' | sh
214: mount
215: mount -a -t no${excludes:ts,}
216:
217: mountlate: NETWORK mount cleanvar runshm devd mounttmpfs
218: echo "MRC:$@> Mount late FS."
219: mount -a
220:
221: msgs: mount
222: echo "MRC:$@> Making bounds."
223: test ! -d /var/msgs -o -f /var/msgs/bound -o -L /var/msgs/bounds || \
224: echo 0 > /var/msgs/bounds
225:
226: newsyslog: mountlate sysdb
227: if [ -n "$${NEWSYSLOG_ENABLE}" ]; then \
228: echo "MRC:$@> Trimming log files."; \
229: /usr/sbin/newsyslog ${NEWSYSLOG_FLAGS}; \
230: fi
231:
232: nextboot: mount
233: .if exists(/boot/nextkernel)
234: echo "MRC:$@> Removing nextboot setting."
235: rm -f /boot/nextkernel
236: .endif
237:
238: .if empty(NFSCLIENT_ENABLE:tl:Mno)
239: DAEMON_rpcbind_ENABLE=yes
240: .endif
241:
242: nfsclient: NETWORK rpcbind
243: if [ -n "$${NFSCLIENT_ENABLE}" ]; then \
244: kldload -n nfs; \
245: fi
246:
247: nfsclient_exit: DAEMON_EXIT
248: .if empty(RPC_UMNTALL_ENABLE:tl:Mno)
249: echo "MRC:$@> Sending RPC unmount notifications."
250: test -f /var/db/mounttab || true && rpc.umntall -k
251: .endif
252:
253: NETWORK_EXIT: nfsclient_exit
254:
255: netif: adjkerntz cloned ip6addrctl kld mounttmpfs utmpx wlans
256: echo "MRC:$@> Starting interfaces: ${IFCONFIG_IFACES}"
257: .for iface in ${IFCONFIG_IFACES}
258: . for item in ${IFCONFIG_${iface}:tW:ts;}
259: ifconfig ${iface} ${item}
260: . endfor
261: . undef _IFCONFIG_ARGS
262: .endfor
263:
264: pf: pflogd
265: .if empty(PF_ENABLE:tl:Mno)
266: echo "MRC:$@> Enabling and loading rules."
267: if kldload -n pf; then \
268: if [ -r ${PF_RULES} ]; then \
269: pfctl -Fa || exit 1; \
270: pfctl -f ${PF_RULES} ${PF_FLAGS} || exit 1; \
271: pfctl -Si | grep -q Enabled && pfctl -e; \
272: else \
273: echo "MRC:$@> Can't find file with rules at ${PF_RULES}."; \
274: exit 1; \
275: fi \
276: else \
277: echo "MRC:$@> Failed to load [pf]."; \
278: fi
279: .endif
280:
281: pwcheck: mountlate syslogd
282: echo "MRC:$@> Checking password lock file."
283: .if exists(/etc/ptmp)
284: logger -s -p auth.err \
285: "password file may be incorrect -- /etc/ptmp exists"
286: .endif
287:
288: random: mount devfs
289: echo "MRC:$@> Seeding."
290: sysctl kern.seedenable=1 > /dev/null
291: ( ps -fauxww; sysctl -a; date; df -ib; dmesg; ps -fauxww ;) 2>&1 | \
292: dd status=none of=/dev/random bs=8k 2>/dev/null
293: dd if=/bin/ps status=none of=/dev/random bs=8k 2>/dev/null
294: if [ -d $${ENTROPY_DIR} ]; then \
295: find $${ENTROPY_DIR} -type f | \
296: xargs -n1 -Ifoo dd status=none if=foo of=/dev/random bs=8k 2>/dev/null; \
297: else \
298: if [ -r ${ENTROPY_FILE} ]; then \
299: dd status=none if=${ENTROPY_FILE} of=/dev/random bs=8k 2>/dev/null; \
300: fi \
301: fi
302: sysctl kern.seedenable=0 > /dev/null
303:
304: random_exit:
305: rm -f ${ENTROPY_FILE}; \
306: ( \
307: umask 077; \
308: dd if=/dev/random of=${ENTROPY_FILE} bs=8k count=1 2>/dev/null || \
309: echo "MRC:$@> entropy file write failed."; \
310: )
311:
312: DAEMON_EXIT: random_exit
313:
314: root: fsck bootfs
315: echo "MRC:$@> Mount root R/W."
316: mount -uo rw
317:
318: savecore: dumpon
319: .if empty(DUMPDEV:tl:Mno) && exists(${DUMPDEV}) && exists(${DUMPDIR})
320: echo "MRC:$@> Saving coredump."
321: savecore ${DUMPDIR} ${DUMPDEV}
322: .if empty(CRASHINFO_ENABLE:tl:Mno)
323: crashinfo -d ${DUMPDIR}
324: .endif
325: .endif
326:
327: swap: savecore
328: .if ${:!sysctl -n vm.swap_enabled!}} != 0
329: echo "MRC:$@> Enabling swap."
330: swapon -a
331: .endif
332:
333: sysctl: kld root
334: .if exists(/etc/sysctl.conf)
335: echo "MRC:$@> Setting sysctl defaults."
336: awk '$$0~/^[ ]*(#.*)?$$/{next}{print}' < /etc/sysctl.conf | \
337: xargs -n1 sysctl
338: .endif
339:
340: sysdb: mountlate
341: echo "MRC:$@> Building databases."
342: install -c -m 644 -g wheel /dev/null /var/run/utmpx
343:
344: wlans: kld
345: echo "MRC:$@> Configuring wlans." ;
346: for dev in $$(sysctl -n net.wlan.devices); do \
347: eval all_wlans=\$${WLANS_$${dev}}; \
348: for wlan in $${all_wlans}; do \
349: { \
350: eval wlan_args="\$${WLANS_$${wlan}_ARGS}" && \
351: ifconfig $${wlan} create wlandev $${dev} && \
352: { \
353: ifconfig $${wlan} $${wlan_args}; \
354: ifconfig $${wlan} up; \
355: }; \
356: } || echo "MRC:$@> ERROR: WLAN $${wlan} failed to initialize."; \
357: done \
358: done
359:
360: zfs:
361: .if empty(ZFS_ENABLE:tl:Mno)
362: zfs mount -va || exit $$?
363: zfs share -a || exit $$?
364: touch /etc/zfs/exports
365: .endif
366:
367: runshm: cleanvar
368: echo "MRC:$@> Preparing /var/run."
369: . if exists(TMPFS_VAR_RUN_ENABLE)
370: /rescue/find /var/run -mindepth 1 -delete
371: mount_tmpfs dummy /var/run
372: . else
373: mkdir -p /var/run/shm
374: mount_tmpfs -m 01777 dummy /var/run/shm
375: . endif
376: mtree -deiqU -f /etc/mtree/BSD.var.dist -p /var
377:
378: mounttmpfs: cleanvar
379: echo "MRC:$@> Mount tmpfs and populating /var/run."
380: .if exists(TMPFS_TMP_ENABLE)
381: mount | awk 'BEGIN{x=1}$$3~/\/tmp/{x=0}END{exit(x)}' || { \
382: /rescue/find /tmp -mindepth 1 -delete; \
383: mount_tmpfs -m 01777 dummy /tmp; \
384: }
385: .endif
386:
387: udevd_check: DAEMON
388: echo "MRC:$@> Check udevd PID/socket are accessible."
f49abe7565 2024-12-29 389: if [ ! -e /var/run/udevd.pid ]; then \
390: pkill -HUP -x udevd; \
391: ( \
392: sleep 1; \
f49abe7565 2024-12-29 393: if [ ! -e /var/run/udevd.pid ]; then \
394: svc restart udevd; \
395: fi \
396: ) & \
397: fi
398:
399: utmpx: runshm
400: echo "MRC:$@> Install utmpx."
401: install -m 644 -g wheel /dev/null /var/run/utmpx