User Tools

Site Tools


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

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:
      	echo "$PREREQ"
      case $1 in
      	exit 0
      . /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

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

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

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:
      Description=Load custom VT color palette
      ExecStart=/usr/bin/setvtrgb /etc/custom-vt-colors
  • Start and enable the service:
    • sudo systemctl enable --now custom-vt-colors.service

VT Colorschemes

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






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):


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

Converting Hex Colors to RGB

  • Convert hex values to rgb with each of r,g,b being on a newline:
    #!/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:
    • ff9900 or \#ff9900 or "#ff9900"
    • Escaping or quoting the hex value starting with a # is necessary else bash will think it's a comment.




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