一,查看系统是否支持串口
[root@localhost ~]# dmesg |grep tty
console [tty0] enabled
serial8250: ttyS0 at I/O 0x3f8 (irq = 3) is a 16550A
serial8250: ttyS1 at I/O 0x2f8 (irq = 4) is a 16550A
00:09: ttyS0 at I/O 0x3f8 (irq = 3) is a 16550A
00:0a: ttyS1 at I/O 0x2f8 (irq = 4) is a 16550A
二,Centos7下串口配置
1,修改/etc/defaule/grub,增加:
GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0,115200"
[root@localhost ~]# vi /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap biosdevname=0 net.ifnames=0 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"
GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0,115200"
2,更新grub。grub2-mkconfig -o /boot/grub2/grub.cfg
[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-862.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-862.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-bcfdd64db72c4cce8e4ea8a33b2f64a3
Found initrd image: /boot/initramfs-0-rescue-bcfdd64db72c4cce8e4ea8a33b2f64a3.img
done
三,Centos6下串口配置
1,修改/etc/inittab, 增加s0:2345:respawn:/sbin/agetty -L -f /etc/issue.serial 115200 ttyS0 vt100
[root@localhost ~]# vi /etc/inittab
s0:2345:respawn:/sbin/agetty -L -f /etc/issue.serial 115200 ttyS0 vt100
2,编辑/etc/securetty文件,增加ttyS0,表示可以root登录终端
[root@localhost ~]# vi /etc/securetty
ttyS0
3,修改 /boot/grub/grub.conf文件,在kernel行最后加console=tty0 console=ttyS0,115200n8
[root@localhost ~]# vi /boot/grub/grub.conf
title CentOS 6 (2.6.32-696.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb console=tty0 console=ttyS0,115200n8 quiet
initrd /initramfs-2.6.32-696.el6.x86_64.img
4,重启验证
————————————————
版权声明:本文为CSDN博主「王鉴」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_42414349/article/details/83538159