linux Usb serial console
ubuntu
Usb serial console 能够把下电时打印输出到串口上,可以记录,而netconsole只能输出下电到disk 之前的打印
- Usb串口线,ftdi或pl2303都可以
- 如果是ubuntu,需要重新编译内核,CONFIG_USB_SERIAL_CONSOLE=y
CONFIG_USB_SERIAL=y,其他可以把ftdi或pl2303编译进内核。注2
- 编辑/etc/default/grub
找到GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" 替换成 GRUB_CMDLINE_LINUX_DEFAULT="debug ignore_loglevel console=tty0 console=ttyUSB0,115200n8 ",注意Ubuntu需要加ignore_loglevel4. centos执行grub2-mkconfig –o /boot/grub2/grub.cfg (grub.cfg也可能在/boot/efi/里)。Ubuntu执行update-grub5. reboot6. Ubuntu会显示login,原因是systemd主动把ttyUSB0加到getty了,可以chmod a-x /lib/systemd/system-generators/system-getty-generator
附录参考
注1:
Serial Console
Serial console enables one to dump out console messages over a serial cable. Most modern PCs do not have legacy serial ports, so instead, one can use a USB serial dongle instead. A "null serial cable" or "universal file transfer cable" is needed to connect the target computer with the host. Most commonly this will be a DB9 female to DB9 female null serial cable. In addition, one needs to enable USB serial support as a kernel build configuration:
CONFIG_USB_SERIAL_CONSOLE=y
CONFIG_USB_SERIAL=y
and enable the appropriate driver, e.g.:
CONFIG_USB_SERIAL_PL2303=y
and boot this kernel with
console=ttyUSB0,9600n8
one may need to adjust the baud rate appropriately.
Note: Generally, there is NO hardware or software flow control on serial console drivers, which means one may get dropped characters when running very high speed tty baud rates, such as 115200 baud.
注2,ubuntu 内核编译
1.下载对应源码 apt-get source linux-image-$(uname -r)
2.安装编译工具略
https://wiki.ubuntu.com/Kernel/BuildYourOwnKernel
centos8+ASUA B560M-Plus
centos8中的默认串口为ttyS0
首先连接串口线:如下图
修改grub配置:
打开/etc/default/grub,增加如下配置。
GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200"
更新grub
grub2-mkconfig -o /boot/grub2/grub.cfg
用其他电脑连接串口。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)