systemd下設置串口自動登錄並添加自啓動腳本的方法

注:詳細介紹見文末原文。

開機串口控制檯自動登錄:

1.一般來說,關於系統啓動的相關服務會放在/etc/systemd/system/下面,進入其中搜索關於getty自動登錄程序

find -iname "*getty*"

./getty.target.wants
./getty.target.wants/[email protected]

2.結果搜索到相關服務目錄,進入目錄查看: ls -l

總用量 0
lrwxrwxrwx 1 lsy lsy 41  1月 22 10:52 [email protected] -> /lib/systemd/system/[email protected]

可以看的這個服務鏈接到/lib/systemd/system/[email protected]

3.打開/lib/systemd/system/[email protected],在[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 
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章