Serial Console: Difference between revisions

From NixOS Wiki
imported>Samueldr
m I can't even into syntax it seems
imported>Clerie
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{expansion}}
{{expansion}}
== Connect to serial device ==
Most serial console programs require you to specify a serial device and a baud rate.
=== With <code>tio</code> ===
  tio -b 115200 /dev/ttyS0
=== With <code>screen</code> ===
  screen /dev/ttyS0 115200
== Serial devices ==
Serial devices under NixOS will get expose with the following file names.
The file names relate to the driver used for the serial interface.
* <code>/dev/ttyS*</code>
* <code>/dev/ttyUSB*</code>
* <code>/dev/ttyACM*</code>
== Use serial interface as TTY ==
To use a serial device <code>ttyS0</code> as a TTY to log into the device, you have to tell the kernel and you boot loader about the serial configuration.
An example for GRUB bootloader:
  boot.kernelParams = [ "console=ttyS0,115200n8" ];
  boot.loader.grub.extraConfig = "
    serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1
    terminal_input serial
    terminal_output serial
  ";
== Unprivileged access to serial device ==
Serial devices under NixOS are created with the group <code>dialout</code> by default.
All users that are part of the group <code>dialout</code> can access serial devices.
Add a user to group <code>dialout</code>:
    users.users.<name>.extraGroups = [ "dialout" ];


== Tips ==
== Tips ==
Line 14: Line 58:


This will give you the exact invocation for your current terminal size.
This will give you the exact invocation for your current terminal size.
In case tmux is used an alternative is to add the following snippet to the <code>tmux.conf</code>
  bind R run "echo \"stty columns $(tmux display -p \#{pane_width}); stty rows $(tmux display -p \#{pane_height})\" | tmux load-buffer - ; tmux paste-buffer"
In this case fixing the terminal size can be achieved by pressing R.

Latest revision as of 18:34, 17 December 2023

Connect to serial device

Most serial console programs require you to specify a serial device and a baud rate.

With tio

 tio -b 115200 /dev/ttyS0

With screen

 screen /dev/ttyS0 115200

Serial devices

Serial devices under NixOS will get expose with the following file names. The file names relate to the driver used for the serial interface.

  • /dev/ttyS*
  • /dev/ttyUSB*
  • /dev/ttyACM*

Use serial interface as TTY

To use a serial device ttyS0 as a TTY to log into the device, you have to tell the kernel and you boot loader about the serial configuration.

An example for GRUB bootloader:

 boot.kernelParams = [ "console=ttyS0,115200n8" ];
 boot.loader.grub.extraConfig = "
   serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1
   terminal_input serial
   terminal_output serial
 ";

Unprivileged access to serial device

Serial devices under NixOS are created with the group dialout by default.

All users that are part of the group dialout can access serial devices.

Add a user to group dialout:

   users.users.<name>.extraGroups = [ "dialout" ];

Tips

Serial console wrapping

The remote serial console has no knowledge of your local console. This means that it will wrap with safe defaults.

You can configure the columns/rows of your serial console using stty.

In a console sized like yours, e.g. a new tab or tmux window:

$ echo "stty rows $(tput lines) cols $(tput cols)"

This will give you the exact invocation for your current terminal size.

In case tmux is used an alternative is to add the following snippet to the tmux.conf

 bind R run "echo \"stty columns $(tmux display -p \#{pane_width}); stty rows $(tmux display -p \#{pane_height})\" | tmux load-buffer - ; tmux paste-buffer"

In this case fixing the terminal size can be achieved by pressing R.