---
tags: Linux Usage
---
# Ubuntu 16.04 & 18.04 & 20.04 and CentOS 7 serial console and Ubuntu (20.04) cmd login
###### tags: serial console
## ubuntu 16.04
https://www.hiroom2.com/2016/06/06/ubuntu-16-04-grub2-and-linux-with-serial-console/
## ubuntu 18.04
(1)在/etc/default/grub下的GRUB_CMDLINE_LINUX尾部加上指令:
console=tty0 console=ttyS0,115200n8 rhel quiet
(2)sudo update-grub
(3)reboot
## ubuntu 20.04
```
~
~
"/etc/default/grub" [readonly] 36L, 1369C 1,1 All
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=1
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200"
GRUB_CMDLINE_LINUX_DEFAULT=""
#GRUB_CMDLINE_LINUX="console=tty1 console=ttyS0, 115200"
GRUB_CMDLINE_LINUX="console=ttyS0,115200n8 rhel quiet splash"
# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"
# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console
# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true
# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"
# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"
```
### source
1. https://blog.csdn.net/wbcuc/article/details/108888227
2. https://blog.wataash.com/ubuntu_console/
## centOS 7
(1)下指令:sudo vi /etc/sysconfig/grub
(2)找到含有GRUB_CMDLINE LINUX的那行,尾部加上console=tty0 console=ttyS0,115200n8 quiet
(3)儲存並離開
(4)下指令:stty -F /dev/ttyS0 speed 115200
(5)下指令:grub2-mkconfig -o /boot/grub2/grub.cfg,若是UEFI模式,要下指令:grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
(6)下指令:sudo systemctl start getty@ttyS0
(7)reboot
理論上這樣就可以了----
(8)萬一還是不行的話,檢查兩個檔案:/etc/sysconfig/grub和/boot/grub2/grub.cfg,搜尋tty字眼,看在裡面是否同時有tty0和ttyS0
(9)若是我文件寫太爛看不懂,請看網址:http://chrisreinking.com/how-to-enable-serial-console-output-in-centos/?fbclid=IwAR0gXenDn5lWTtsoZi3RZvWdJEYk_dRFl67Yv7x85eaVFiiiqZmrBIhHl3M
(10)萬一這樣還是不行,跟可以的同伴借一下他們的/etc/sysconfig/grub和/boot/grub2/grub.cfg檔案(沒錯同步驟8的檔案),搜尋有tty的部分,把自己的改成跟他們一樣,記得要下上面的指令(4)(5)(6)
補充:tty是什麼,https://flykof.pixnet.net/blog/post/24277709-%5B%E8%BD%89%E8%BC%89%E6%95%B4%E7%90%86%5Dwhat-is-tty%3F
## Ubuntu (20) autologin root
```bash=
sudo systemctl edit getty@tty1
```
in getty@tty1, type
```
ExecStart=
ExecStart=/sbin/agetty --autologin root --noclear %I $TERM
```
and then...
```bash=
sudo vim /root/.bashrc
```
```bash=
sudo vim /home/[user]/.bashrc
```
write this at the bottom of these two files
```
export TERM=xterm
```
### source
https://www.linuxquestions.org/questions/showthread.php?p=6230215#post6230215
https://blog.longwin.com.tw/2010/05/linux-unknown-terminal-type-fix-2010/