注:详细介绍见文末原文。
开机串口控制台自动登录:
1.一般来说,关于系统启动的相关服务会放在/etc/systemd/system/下面,进入其中搜索关于getty自动登录程序
find -iname "*getty*"
./getty.target.wants
./getty.target.wants/serial-getty@ttymxc0.service
2.结果搜索到相关服务目录,进入目录查看: ls -l
总用量 0
lrwxrwxrwx 1 lsy lsy 41 1月 22 10:52 serial-getty@ttymxc0.service -> /lib/systemd/system/serial-getty@.service
可以看的这个服务链接到/lib/systemd/system/serial-getty@.service,
3.打开/lib/systemd/system/serial-getty@.service,在[Service]项的ExecStart=,添加"-a root"
[Service]
Environment="TERM=xterm"
ExecStart=-/sbin/agetty -a root -8 -L %I 115200 $TERM
Type=idle
Restart=always
RestartSec=0
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
KillMode=process
IgnoreSIGPIPE=no
SendSIGHUP=yes
开机自动运行程序:
sysinit.target服务会进行系统挂载,内存空间分配等,
我们可以在此后面插入一个属于自己的服务,即在local-fs.target.wants中插入:
(1)创建自己的服务vi /lib/systemd/system/embedsky.service:
# 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=Remount Root and Kernel File Systems
Documentation=man:systemd-remount-fs.service(8)
Documentation=https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems
DefaultDependencies=no
Conflicts=shutdown.target
After=systemd-fsck-root.service //在什么服务以后
Before=local-fs-pre.target local-fs.target shutdown.target //在什么服务以前
Wants=local-fs-pre.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/etc/embedsky_conf //执行的程序或者脚本
(2)链接服务:
cd /lib/systemd/system/local-fs.target.wants/
ln -s ../embedsky.service embedsky.service
完成
---------------------
作者:世黎
来源:CSDN
原文:https://blog.csdn.net/a617996505/article/details/88423794
版权声明:本文为博主原创文章,转载请附上博文链接!