User Tools

Site Tools


linux:ricing:virtual_terminal_color

Virtual Terminal Color

The following notes apply to virtual terminals such as /dev/tty1, /dev/tty2, etc.

You use these terminals when you log in without a display manager (eg. LightDM) or when you use a command such as <ctrl> + <alt> + <F2>.

These settings will not apply to a terminal emulator such as urxvt, st or xterm etc. They will need to to be configured separately.


Applying a VT Colorscheme at boot

The following instructions were created on Debian 10 (buster).

They should work on Ubuntu and other Debian based distributions as well.

Setting Up

  • If it's not already installed, install kbd:
    • sudo apt install kbd

<HTML> <hr style=“border: 0;height: 0;border-top: 1px solid rgba(0, 0, 0, 0.1);border-bottom: 1px solid rgba(255, 255, 255, 0.3);”> </HTML>

Modify initramfs

Add the setvtrgb executable to the initramfs so that it's available during boot.

  • Create a shell script in the hooks directory:
    • sudoedit /etc/initramfs-tools/hooks/setvtrgb_hook:
      setvtrgb_hook
      #!/bin/sh
      PREREQ=""
      prereqs()
      {
      	echo "$PREREQ"
      }
       
      case $1 in
      prereqs)
      	prereqs
      	exit 0
      	;;
      esac
       
      . /usr/share/initramfs-tools/hook-functions
       
      copy_exec /usr/bin/setvtrgb /bin
  • Set the script to be executable:
    • sudo chmod +x /etc/initramfs-tools/hooks/setvtrgb_hook

<HTML> <hr style=“border: 0;height: 0;border-top: 1px solid rgba(0, 0, 0, 0.1);border-bottom: 1px solid rgba(255, 255, 255, 0.3);”> </HTML>

Choose a colorscheme

Test the colorscheme by running the script then clearing the terminal. This way you can see which one you like ahead of time.

  • Copy one of the Colorschemes from below (or create your own) to:
    • /etc/initramfs-tools/scripts/init-top/
      • I chose the init-top directory because it gets called as early as possible into the boot process.
      • Refer to man initramfs-tools BOOT SCRIPTS section and change it to suit your needs.
  • Set the script to be executable:
    • sudo chmod +x /etc/initramfs-tools/scripts/init-top/my_colorscheme

<HTML> <hr style=“border: 0;height: 0;border-top: 1px solid rgba(0, 0, 0, 0.1);border-bottom: 1px solid rgba(255, 255, 255, 0.3);”> </HTML>

Update initramfs

After completing the above steps, we will generate the new initramfs

  • Update the initramfs:
    • sudo update-initramfs -u
  • Verify that setvtrgb was added:
    • lsinitramfs -l /boot/initrd.img-4.19.0-9-amd64 | grep setvtrgb
    • make sure to modify the above command to point to your initrd
  • Reboot

<HTML> <hr style=“overflow: visible;padding: 0;border: none;border-top: medium double #b5b5b5;color: #b5b5b5;text-align: center;”> </HTML>

Applying a VT Colorscheme after boot

If you use Plymouth, a display manager or frankly just don't care if the boot process terminal has custom colors, you can create a systemd service to load the colors after login.

  • Copy or create a colorscheme somewhere such as /etc/custom-vt-colors.
  • Create a systemd service:
    • sudoedit /etc/systemd/system/custom-vt-colors.service:
      custom-vt-colors.service
      [Unit]
      Description=Load custom VT color palette
       
      [Service]
      Type=oneshot
      ExecStart=/usr/bin/setvtrgb /etc/custom-vt-colors
       
      [Install]
      WantedBy=multi-user.target
  • Start and enable the service:
    • sudo systemctl enable --now custom-vt-colors.service


<HTML> <hr style=“overflow: visible;padding: 0;border: none;border-top: medium double #b5b5b5;color: #b5b5b5;text-align: center;”> </HTML>

VT Colorschemes

For the colorschemes below (except default), I imported the Xresources of each colorscheme to https://terminal.sexy to convert the hex values to rgb quickly. Then I created the files using those rgb values.

Default

Dracula

Gruvbox

Nord

Solarized

<HTML> <hr style=“border: 0;height: 0;border-top: 1px solid rgba(0, 0, 0, 0.1);border-bottom: 1px solid rgba(255, 255, 255, 0.3);”> </HTML>

VT Colorscheme Format

setvtrgb requires the input to be formatted properly for it to work.

Similar to Xresources, there are definable 16 colors ranging from color0 through color15. However, the colors need split into 3 lines with Red being the top line, Green being the middle line and Blue being the bottom line. It should look like this (substituting the RGB values of course):

Red0,Red1,Red2,Red3,Red4,Red5,Red6,Red7,Red8,Red9,Red10,Red11,Red12,Red13,Rew14,Red15
Green0,Green1,Green2,Green3,Green4,Green5,Green6,Green7,Green8,Green9,Green10,Green11,Green12,Green13,Rew14,Green15
Blue0,Blue1,Blue2,Blue3,Blue4,Blue5,Blue6,Blue7,Blue8,Blue9,Blue10,Blue11,Blue12,Blue13,Rew14,Blue15


For a working example and/or to make a backup of the current settings:

  • Save/view current vt colors in a setvtrgb usable format:
    • cat /sys/module/vt/parameters/default_{red,grn,blu} > ~/consolecolors

<HTML> <hr style=“border: 0;height: 0;border-top: 1px solid rgba(0, 0, 0, 0.1);border-bottom: 1px solid rgba(255, 255, 255, 0.3);”> </HTML>

Converting Hex Colors to RGB

  • Convert hex values to rgb with each of r,g,b being on a newline:
    hexrgb.sh
    #!/usr/bin/env bash
     
    # Take input hex number, convert to uppercase, strip #
    hexinput=$(echo $1 | tr '[:lower:]' '[:upper:]' | sed 's/#//g' )
     
    # Print RGB output with each on it's own line
    printf "%d\n%d\n%d\n" 0x${hexinput:0:2} 0x${hexinput:2:2} 0x${hexinput:4:2}
  • Run it:
    • hexrgb.sh ff9900 or hexrgb.sh \#ff9900 or hexrgb.sh "#ff9900"
    • Escaping or quoting the hex value starting with a # is necessary else bash will think it's a comment.


<HTML> <hr style=“overflow: visible;padding: 0;border: none;border-top: medium double #b5b5b5;color: #b5b5b5;text-align: center;”> </HTML>

References

Colors

General

linux/ricing/virtual_terminal_color.txt · Last modified: 2020/07/17 15:46 by chuck