Utilisation d'une console série sur Ubuntu 20.04

serial console

English

sudo cp -nv /etc/default/grub   /etc/default/grub.orig
sudo cp -nv /boot/grub/grub.cfg /boot/grub/grub.cfg.orig
sudo vim /etc/default/grub

/etc/default/grub:

## remove (optional):
# GRUB_TIMEOUT_STYLE=hidden

## change:
# (optional)
# GRUB_TIMEOUT=0
GRUB_TIMEOUT=2

## add:
GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200"

## change:
# GRUB_CMDLINE_LINUX=""
GRUB_CMDLINE_LINUX="console=tty1 console=ttyS0,115200"

<détails>

Description </ summary>
Si vous supprimez GRUB_TIMEOUT_STYLE = hidden et définissez GRUB_TIMEOUT = 2, le menu GRUB sera affiché au démarrage.

GRUB menu

Si GRUB_TIMEOUT vaut 1 ou plus (ou -1), le menu peut être ouvert en appuyant sur la touche Echap </ kbd> même si GRUB_TIMEOUT_STYLE = hidden ([ref.](Https: /) /www.gnu.org/software/grub/manual/grub/html_node/Simple-configuration.html)).

En ajoutant GRUB_TERMINAL =" console serial ", le menu GRUB sera affiché à la fois sur la console VGA et sur le terminal série.

GRUB menu in both VGA console and serial terminal

Si vous ne voyez pas la sortie de la console série, reportez-vous au manuel (https://www.gnu.org/software/grub/manual/grub/html_node/serial.html) et faites correspondre le matériel avec `GRUB_SERIAL_COMMAND = Essayez de changer "serial --speed = 115200".

GRUB_CMDLINE_LINUX =" console = tty1 console = ttyS0,115200 " est paramètre de ligne de commande du noyau Linuxest. Similaire à GRUB_TERMINAL =" console serial ", cette option permet l'entrée / sortie tty à la fois sur la console VGA (tty1) et la console série (ttyS0).

tty output on both tty1 and ttyS0

Cela peut également être modifié dans le menu GRUB au démarrage.

Modify command-line parameter in GRUB menu


Après avoir édité / etc / default / grub, exécutez sudo update-grub pour générer / boot / grub / grub.cfg qui est effectivement chargé au démarrage. Il exécute en interne grub-mkconfig -o / boot / grub / grub.cfg.


<détails>

/ etc / default / grub original, modifié, diff </ summary>

Original (selon l'environnement, il s'agit de QEMU):

# 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=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX=""

# 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"

Modifié:

# 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=2
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="console=tty1 console=ttyS0,115200"

# 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
#GRUB_TERMINAL="console serial"
GRUB_TERMINAL="console serial"
GRUB_SERIAL_COMMAND="serial --speed=115200"

# 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"

diff:

sudo apt install python3-pip
pip3 install icdiff
~/.local/bin/icdiff /etc/default/grub.orig   /etc/default/grub
~/.local/bin/icdiff /boot/grub/grub.cfg.orig /boot/grub/grub.cfg

diff /etc/default/grub

Le diff de / boot / grub / grub.cfg est grand, veuillez donc le vérifier de vos propres yeux.


Après le redémarrage, dmesg sera lu sur la console série et l'invite de connexion sera affichée.

<img alt = "Creative Commons License" style = "border-width: 0" src = "https" //i.creativecommons.org/l/by/4.0/88x31.png "/>
Ce travail est <a rel =" license "href =" http://creativecommons.org/ Licences / par / 4.0 / "> Licence internationale Creative Commons Attribution 4.0 .

Recommended Posts