0

When connecting to the Pi by the serial console, I'd like to have the default TERM be xterm, rather than the current default of vt102:

pi@raspberrypi:~$ echo $TERM
vt102
pi@raspberrypi:~$ tty
/dev/ttyS0

I know I could add this to .bashrc, etc. - but I only want to change the current default, and to otherwise not impact other types of connections.

https://www.debian.org/releases/jessie/i386/ch05s03.html.en seems to indicate that I should be able to add TERM=xterm to the boot parameters - which are at /boot/cmdline.txt. As such, I tried updating the following:

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

to:

dwc_otg.lpm_enable=0 console=serial0,115200 TERM=xterm console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

... and then rebooting, but with no change. Now, http://man7.org/linux/man-pages/man7/bootparam.7.html indicates that this may be a "(useless?) example" (for reasons I don't understand).

Now, I did find /lib/systemd/system/serial-getty@.service, which contains the following:

[Service]
ExecStart=-/sbin/agetty --keep-baud 115200,38400,9600 %I $TERM

... but I can't find where the default $TERM is being defined.

I did add the following here:

    Environment=TERM=xterm

This is working - but it seems that I'm still missing part of the puzzle here, as to where this is defaulting to vt102, or why this can't be set in cmdline.txt.

(Other sources I've already referenced:)

ziesemer
  • 263
  • 2
  • 10

1 Answers1

2

Had I read the "Docs" section of the output from systemctl status serial-getty@ttyS0.service, it includes a link to http://0pointer.de/blog/projects/serial-console.html . From there:

serial-getty@.service is responsible for all other terminals, including serial ports such as /dev/ttyS0. It differs in a couple of ways from getty@.service: among other things the $TERM environment variable is set to vt102 (hopefully a good default for most serial terminals) rather than linux (which is the right choice for VTs only), and a special logic that clears the VT scrollback buffer (and only work on VTs) is skipped.

So, this is apparently a hard-coded default. This is also supported by the following:

However, for completeness - I'm still searching for where this is actually coded.

ziesemer
  • 263
  • 2
  • 10
  • Xterm is a vt102 terminal emulator for X windows. Your question makes no sense to me. Try another explanation. – PaulF8080 Aug 26 '16 at 02:39
  • @PaulF8080 - it is somewhat ambiguous. In this context, maybe take it to mean that we want the terminal to "function like xterm". See also: http://unix.stackexchange.com/questions/23764/changing-terminal-emulators and http://unix.stackexchange.com/questions/43945/whats-the-difference-between-various-term-variables ? – ziesemer Aug 26 '16 at 07:59
  • Xterm and the console both emulate the old DEC VT102 terminal – PaulF8080 Aug 26 '16 at 19:57
  • @PaulF8080 - sure, but xterm is supposed to be a superset of vt220 - while also supporting colors and other features. Bottom line, a lot of things are disabled when TERM=vt102, but work with TERM=xterm. Look at how many bashrc and such files are checking for TERM=xterm various things... – ziesemer Aug 26 '16 at 20:21
  • The vt102 does color and cursor control with ANSI escape sequences. Does that solve your problem, then? – PaulF8080 Aug 26 '16 at 21:09
  • @PaulF8080 - vt102 emulation does not support color. Please refer to the references I included in my first reply to you above. Even if it would, most OS distributions are configured to disable color support and related features unless TERM=xterm (or xterm* with pattern matching). The question here is/was how to change the default TERM environment variable for serial console connections, not whether or not it is required (please). – ziesemer Aug 26 '16 at 21:15
  • I still don't get, sorry. The TERM variable has nothing to do with the serial port operation. You set it according to what's on the other end of the cable. The serial port will gladly send ANSI characters. Only software sending the text needs to look at TERM – PaulF8080 Aug 27 '16 at 03:57
  • @PaulF8080 - in this case, the Pi running Raspbian is what is on the other end of the cable. By default, when connecting to the Pi, combined with the bashrc files and such I mentioned above, it restricts itself to no colors - including the prompt, directory listings, etc. - based on TERM=vt102 (and not being TERM=xterm. Once connected to the Pi, I can send it export TERM=xterm to enable color support and other functionality. All this Q/A was intended for was how to have this properly set by default, respecting the considerations listed. – ziesemer Aug 27 '16 at 12:22