使用usb串口线作为console

您所在的位置:网站首页 usb转console线怎么制作 使用usb串口线作为console

使用usb串口线作为console

2023-10-24 09:50| 来源: 网络整理| 查看: 265

1 检查是否支持 USB 串口线 dmesg | grep tty > usb 1-5: pl2303 converter now attached to ttyUSB0 > console [ttyUSB0] enabled 2 修改/etc/default/grub配置文件

修改文件: /etc/default/grub

修改前:

GRUB_CMDLINE_LINUX="crashkernel=auto spectre_v2=retpoline rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"

修改后:

GRUB_CMDLINE_LINUX="crashkernel=auto spectre_v2=retpoline rd.lvm.lv=centos/root rd.lvm.lv=centos/swap" GRUB_CMDLINE_LINUX_DEFAULT="console=ttyUSB0,115200n8 console=tty0 LANG=utf-8"

修改备注:

去除 rhgb:redhat graphical boot. 打印更多的开机信息。去除 quiet:hides the majority of boot messages before rhgb starts. 打印更多的开机信息。增加 console=ttyUSB0,115200n8:设置 为 /dev/ttyUSB0,8 为数据为,无校验,1位停止位。

参考: What is “rhgb” on the grub, kernel line?

3 更新grub.cfg配置文件 grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg 4 启动[email protected]服务 systemctl enable [email protected] 5 修改/usr/lib/systemd/system/[email protected]配置文件

修改文件: /usr/lib/systemd/system/[email protected]

修改前:

ExecStart=-/sbin/agetty --keep-baud 115200,38400,9600 %I $TERM

修改后:

ExecStart=-/sbin/agetty -t 60 115200 %I $TERM

修改备注:

增加 -t 60:60秒登录超时。 6 让root可以通过serial console登录

配置文件/etc/securetty用于管理root用户可以登录的设备, 将serial console的设备名添加到该文件,即可使root用户通过serial console登录。

修改文件: /etc/securetty

追加一行:

ttyUSB0

参考: 为Linux系统配置serial console

7 无法登录问题

以上的步骤,虽然可以令到串口有输出,但是却无法弹出login提示符。用户无法登录。

7.1 问题表现: # view journal journalctl -u [email protected] > localhost.localdomain agetty[2962]: /dev/ttyUSB0: Permission denied > ^^^^^^^^^^^^^^^^^ > localhost.localdomain systemd[1]: [email protected] holdoff time over, scheduling restart. > localhost.localdomain systemd[1]: Stopped Serial Getty on ttyUSB0. > localhost.localdomain systemd[1]: Started Serial Getty on ttyUSB0. # view log message tail -f /var/log/messages > localhost python: SELinux is preventing agetty from setattr access on the chr_file ttyUSB0. > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > ***** Plugin catchall (100. confidence) suggests ************************** > If you believe that agetty should be allowed setattr access on the ttyUSB0 chr_file by default. > Then you should report this as a bug. > You can generate a local policy module to allow this access. > Do allow this access for now by executing: > # ausearch -c 'agetty' --raw | audit2allow -M my-agetty > # semodule -i my-agetty.pp > localhost systemd: [email protected] holdoff time over, scheduling restart. > localhost systemd: Stopped Serial Getty on ttyUSB0. > localhost systemd: Started Serial Getty on ttyUSB0. > localhost dbus[1486]: [system] Activating service name='org.fedoraproject.Setroubleshootd' (using servicehelper) > localhost dbus[1486]: [system] Successfully activated service 'org.fedoraproject.Setroubleshootd' > localhost setroubleshoot: SELinux is preventing agetty from setattr access on the chr_file ttyUSB0. For complete SELinux messages run: sealert -l 73e8a504-0153-4ca5-8beb-5627509d949c 7.2 解决方法: 7.2.1 将用户加入dialout组别。

由于/dev/ttyUSB0属于dialout组别,需要将用户加入该组别。

使用命令

# add root to dialout group # syntax: gpasswd --add dialout gpasswd --add root dialout # verify groups root > root : root dialout

参考: minicom: cannot open /dev/ttyS0: Permission denied

7.2.2 暴力关闭 SELinux

暴力关闭 SELinux 后。用户可以正常登录。

修改文件: /etc/selinux/config

修改前:

SELINUX=enforcing

修改后:

SELINUX=disabled 8 遗留问题

使用/dev/ttyUSB0做为串口输出,只可以输出启动信息后半段的内容。前半部分GRUB的信息是无法打印出来的。 这是因为USB串口线要等到 linux 启动后的第7秒才插入模块(可以通过dmesg命令查看)。

以下用于GRUB固定串口的设置。是无法应用于/dev/ttyUSB0的。

修改文件: /etc/default/grub

修改前:

GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="crashkernel=auto spectre_v2=retpoline rd.lvm.lv=centos/root rd.lvm.lv=centos/swap"

修改后:

GRUB_TERMINAL="console serial" GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1" GRUB_CMDLINE_LINUX="crashkernel=auto spectre_v2=retpoline rd.lvm.lv=centos/root rd.lvm.lv=centos/swap" GRUB_CMDLINE_LINUX_DEFAULT="console=ttyUSB0,115200n8 console=tty0 LANG=utf-8"

参考CentOS 7: GRUB2 and Linux with serial console



【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3