参考链接:
linux_systemd启动方式解析,如何开机自动登录,开机自动运行程序
https://blog.csdn.net/a617996505/article/details/88423794
涉及文件:
OK3399-linux-ubuntu/lib/systemd/system/serial-getty@.service
serial-getty@.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=Serial Getty on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=http://0pointer.de/blog/projects/serial-console.html
BindsTo=dev-%i.device
After=dev-%i.device systemd-user-sessions.service plymouth-quit-wait.service
After=rc-local.service
# If additional gettys are spawned during boot then we should make
# sure that this is synchronized before getty.target, even though
# getty.target didn't actually pull it in.
Before=getty.target
IgnoreOnIsolate=yes
[Service]
ExecStart=-/sbin/agetty --autologin forlinx --keep-baud 115200,38400,9600 %I $TERM
Type=idle
Restart=always
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
KillMode=process
IgnoreSIGPIPE=no
SendSIGHUP=yes
[Install]
WantedBy=getty.target
该服务通过运行/sbin/agetty程序,登录终端。
787 ttyFIQ0 Ss 0:00 /bin/login -f
789 tty1 Ss+ 0:00 /sbin/agetty -o -p -- \u --noclear tty1 linux
forlinx@forlinx:~$ ps
PID TTY TIME CMD
826 ttyFIQ0 00:00:00 bash
925 ttyFIQ0 00:00:00 ps
看一下agetty程序的配置选项:
forlinx@forlinx:~$ /sbin/agetty --help
Usage:
agetty [options] <line> [<baud_rate>,...] [<termtype>]
agetty [options] <baud_rate>,... <line> [<termtype>]
Open a terminal and set its mode.
Options:
-8, --8bits assume 8-bit tty
-a, --autologin <user> login the specified user automatically
-c, --noreset do not reset control mode
-E, --remote use -r <hostname> for login(1)
-f, --issue-file <file> display issue file
-h, --flow-control enable hardware flow control
-H, --host <hostname> specify login host
-i, --noissue do not display issue file
-I, --init-string <string> set init string
-J --noclear do not clear the screen before prompt
-l, --login-program <file> specify login program
-L, --local-line[=<mode>] control the local line flag
-m, --extract-baud extract baud rate during connect
-n, --skip-login do not prompt for login
-N --nonewline do not print a newline before issue
-o, --login-options <opts> options that are passed to login
-p, --login-pause wait for any key before the login
-r, --chroot <dir> change root to the directory
-R, --hangup do virtually hangup on the tty
-s, --keep-baud try to keep baud rate after break
-t, --timeout <number> login process timeout
-U, --detect-case detect uppercase terminal
-w, --wait-cr wait carriage-return
--nohints do not print hints
--nohostname no hostname at all will be shown
--long-hostname show full qualified hostname
--erase-chars <string> additional backspace chars
--kill-chars <string> additional kill chars
--chdir <directory> chdir before the login
--delay <number> sleep seconds before prompt
--nice <number> run login with this priority
--reload reload prompts on running agetty instances
--list-speeds display supported baud rates
--help display this help
--version display version
For more details see agetty(8).
所以如果要配置自动登录的话就可以修改这个服务,添加" -a, --autologin "即可.