openkylin、ubuntu等系统实现串口自动登录

先查看系统是否有 serial-getty@.service 模板,查看设备串口节点是 /dev/ttyFIQ0,可通过自定义 serial-getty@.service 单元文件来实现

bash 复制代码
$ dmesg |grep tty
[    5.032998] systemd[1]: Created slice system-getty.slice - Slice /system/getty.
[    5.041364] systemd[1]: Created slice system-serial\x2dgetty.slice - Slice /system/serial-getty.
[    5.045980] systemd[1]: Expecting device dev-ttyFIQ0.device - /dev/ttyFIQ0...

不要直接修改 /lib/systemd/system/serial-getty@.service,而是复制一份到 /etc/systemd/system/ 下并重命名,以便针对特定串口进行配置:

bash 复制代码
sudo cp /lib/systemd/system/serial-getty@.service /etc/systemd/system/serial-getty@ttyFIQ0.service
sudo vim /etc/systemd/system/serial-getty@ttyFIQ0.service
找到 ExecStart= 行,将其修改为:因为用户名是openkylin
ExecStart=-/sbin/agetty -a openkylin --keep-baud 1500000,115200 %I  $ TERM

-a openkylin:表示自动以 openkylin 用户登录

%I 会被替换为 ttyFIQ0,即设备路径 /dev/ttyFIQ0

--keep-baud 是为了兼容不同波特率(根据你的硬件调整,若确定波特率可简化为 - 1500000)

设置完 serial-getty@ttyFIQ0.service 之后,就已经能自动登录了

bash 复制代码
openkylin@openkylin:~$ dmesg |grep tty
[    1.285665] Kernel command line: storagemedia=emmc androidboot.storagemedia=emmc androidboot.mode=normal  androidboot.verifiedbootstate=orange rw rootwait earlycon=uart8250,mmio32,0xfe660000 console=ttyFIQ0 root=PARTUUID=614e0000-0000
[    1.604248] Registered FIQ tty driver
[    2.316094] printk: console [ttyFIQ0] enabled
[    2.317539] Registered fiq debugger ttyFIQ0
[    2.447218] fe670000.serial: ttyS3 at MMIO 0xfe670000 (irq = 33, base_baud = 1500000) is a 16550A
[    2.448004] fe680000.serial: ttyS4 at MMIO 0xfe680000 (irq = 34, base_baud = 1500000) is a 16550A
[    2.448701] fe690000.serial: ttyS5 at MMIO 0xfe690000 (irq = 35, base_baud = 1500000) is a 16550A
[    2.449453] fe6b0000.serial: ttyS7 at MMIO 0xfe6b0000 (irq = 36, base_baud = 1500000) is a 16550A
[    2.450022] fe6d0000.serial: ttyS9 at MMIO 0xfe6d0000 (irq = 37, base_baud = 1500000) is a 16550A
[    5.032998] systemd[1]: Created slice system-getty.slice - Slice /system/getty.
[    5.041364] systemd[1]: Created slice system-serial\x2dgetty.slice - Slice /system/serial-getty.
[    5.045980] systemd[1]: Expecting device dev-ttyFIQ0.device - /dev/ttyFIQ0...
bash 复制代码
$ cat /etc/systemd/system/serial-getty@ttyFIQ0.service
#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  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=https://0pointer.de/blog/projects/serial-console.html
BindsTo=dev-%i.device
After=dev-%i.device systemd-user-sessions.service plymouth-quit-wait.service getty-pre.target
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

# IgnoreOnIsolate causes issues with sulogin, if someone isolates
# rescue.target or starts rescue.service from multi-user.target or
# graphical.target.
Conflicts=rescue.service
Before=rescue.service

[Service]
# The '-o' option value tells agetty to replace 'login' arguments with an
# option to preserve environment (-p), followed by '--' for safety, and then
# the entered username.
ExecStart=-/sbin/agetty -a openkylin --keep-baud 1500000,115200 %I $TERM
Type=idle
Restart=always
UtmpIdentifier=%I
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
IgnoreSIGPIPE=no
SendSIGHUP=yes
ImportCredential=agetty.*
ImportCredential=login.*

[Install]
WantedBy=getty.target
相关推荐
sbjdhjd7 分钟前
Docker | 核心概念科普 + 保姆级部署
linux·运维·服务器·docker·云原生·面试·eureka
charlie1145141917 分钟前
嵌入式C++教程实战之Linux下的单片机编程(9):HAL时钟使能 —— 不开时钟,外设就是一坨睡死的硅
linux·开发语言·c++·单片机·嵌入式硬件·c
Agent产品评测局9 分钟前
企业生产报工自动化落地,数据采集全流程实现方案 —— 2026制造业数字化转型深度选型指南
运维·人工智能·ai·chatgpt·自动化
以太浮标10 分钟前
华为eNSP模拟器综合实验之- DHCP、DNS、HTTP和FTP服务器配置案例Client-Server
linux·服务器·windows·http·华为·信息与通信
志栋智能11 分钟前
安全超自动化如何缩短平均检测与响应时间?
运维·安全·自动化
Project_Observer16 分钟前
为您的项目选择最合适的Zoho Projects自动化巧能
大数据·运维·人工智能·深度学习·机器学习·自动化·编辑器
西柚小萌新17 分钟前
【人工智能:Agent】--OpenClaw设计架构解析
运维·服务器·架构
摇滚侠18 分钟前
Vmvare 虚拟机安装 Linux CentOS 7 操作系统 一键安装 Docker 1Panel 一键安装 MySQL Redis OpenClaw
linux·docker·centos
路溪非溪24 分钟前
如何使用procfs来排查问题
linux·arm开发·驱动开发
帕里亚36 分钟前
ubuntu18.04 APT升级 glibc2.28 (Jetson)
linux·运维·windows