Debian – Where is the `$TERM` environmental variable set in Debian Jessie for console logins

consoledebianenvironment-variablessystemdterminal

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

Best Answer

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"