5

I have read a lot of articles and SE questions regarding how and where the default $TERM environmental variable gets set.

Unfortunately in Debian 8.1 I can't seem to find where the default $TERM variable is set when logging in to the system from tty1.

I would love to be pointed in the right direction if this is indeed a duplicate question but the following questions didn't seem like they provided an answer:

tmux, TERM and 256 colours support

Where does the TERM environment variable default get set?

Is it correct to set the $TERM variable manually?

Edit

When I log in via tty1 here is what $TERM is set to:

$> echo $TERM
linux

Listing of /usr/lib/systemd/, note that there is no system directory here.

$> ls -al
total 28
drwxr-xr-x  7 root root 4096 Aug 19 13:37 .
drwxr-xr-x 44 root root 4096 Aug 20 14:28 ..
drwxr-xr-x  2 root root 4096 Aug 19 13:37 catalog
drwxr-xr-x  2 root root 4096 May 26 02:07 network
drwxr-xr-x  2 root root 4096 Aug 19 13:37 ntp-units.d
drwxr-xr-x  2 root root 4096 Aug 19 13:37 user
drwxr-xr-x  2 root root 4096 May 26 02:07 user-generators
111---
  • 4,516
  • 3
  • 30
  • 52
  • The second link did say that right . On systemd systems, one can see this in the /usr/lib/systemd/system/getty@.service unit file, which reads Environment=TERM=linux – neuron Aug 20 '15 at 19:26
  • @neuron Yeah I thought that might be where it should be but see my edits to the question. That file does not seem to exist on this system. FWIW it was a fresh installation of 8.1. – 111--- Aug 20 '15 at 19:33
  • Yup, @yaegashi is right – neuron Aug 20 '15 at 19:48

2 Answers2

6

I suppose TERM is set to linux for the init process (pid 1) by Linux kernel here and there. You can see it in /proc/1/environ (sorry the following output is from Ubuntu 15.04):

$ sudo strings /proc/1/environ 
HOME=/
init=/sbin/init
recovery=
TERM=linux
BOOT_IMAGE=/boot/vmlinuz-3.19.0-25-generic.efi.signed
PATH=/sbin:/usr/sbin:/bin:/usr/bin
PWD=/
rootmnt=/root

On Debian/Ubuntu systemd based systems it gets propagated to child getty processes by definitions in /lib/systemd/system/getty@.service.

[Service]
# the VT is cleared by TTYVTDisallocate
ExecStart=-/sbin/agetty --noclear %I $TERM

So you might be able to override TERM in the kernel command line. Try to edit /etc/default/grub and run update-grub and reboot.

GRUB_CMDLINE_LINUX="TERM=vt100"
yaegashi
  • 12,326
  • Thanks, the file I was looking for was /lib/systemd/system/getty@.service and your suggestion for modifying the GRUB_CMDLINE_LINUX works nicely to change this. The system is running on embedded hardware so there will only be one serial console. Thanks. – 111--- Aug 20 '15 at 20:08
  • @111--- As of 2024 (since when?) systemd sets the serial console $TERM based on /lib/systemd/system/serial-getty@.service . e.g.: One needs to add Environment=TERM=linux at the start of the [Service] section – Petru Zaharia Mar 22 '24 at 18:20
-1

The $TERM variable is normally set in /etc/profile or .bashrc depends on the distro ur using.

Read http://www.tldp.org/HOWTO/Keyboard-and-Console-HOWTO-11.html

Ray BSD
  • 161
  • /etc/profile just sets $PATH and $PS1 and my .bashrc does not seem to explicitly set the $TERM variable. – 111--- Aug 20 '15 at 18:19
  • What is the content of /etc/profile.d/ ? Can u find with cat and grep on TERM to see if there are files/scripts that sets the environment for TERM ? – Ray BSD Aug 20 '15 at 19:15
  • Debian does not do this. It also does not make sense to do so, since your shell has no information whatsoever what the right value should be. – Wouter Verhelst Aug 22 '15 at 11:19