systemd下设置串口自动登录并添加自启动脚本的方法

注:详细介绍见文末原文。

开机串口控制台自动登录:

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 
版权声明:本文为博主原创文章,转载请附上博文链接!

  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值