1

The colors in the Ubuntu terminal is "wrong". Is it possible to make it use the correct VGA colors. For comparison, here is a screenshot showing two VMs: one Xubuntu 16.04 (upper), and one Windows 98 (lower). I expected to see some options in console-setup, but that only covers the font, and character encoding.

Console comparison

2

The linux virtual console is based on VT102 and ECMA-48 terminal controls. The console_codes and console_ioctl manpages give more information. You can see the current colors in use with:

$ cat /sys/module/vt/parameters/default_{red,grn,blu}
0,170,0,170,0,170,0,170,85,255,85,255,85,255,85,255   # .../default_red
0,0,170,85,0,0,170,170,85,85,255,255,85,85,255,255    # .../default_grn
0,0,0,0,170,170,170,170,85,85,85,85,255,255,255,255   # .../default_blu

These give the RGB values for the main terminal colors (8 normal, 8 bright), in a comma-separated format (from the setvtrgb manpage):

# default_red:  color0_R,color1_R,...,color15_R
# default_grn:  color0_G,color1_G,...,color15_G
# default_blu:  color0_B,color1_B,...,color15_B

+--------+--------+---------+
| Normal | Bright | Color   |
+--------+--------+---------+
|      0 |      8 | Black   |  
|      1 |      9 | Red     |  
|      2 |     10 | Green   |
|      3 |     11 | Yellow  |
|      4 |     12 | Blue    |
|      5 |     13 | Magenta |
|      6 |     14 | Cyan    |
|      7 |     15 | White   |  
+---------------------------+

To change them, first we need to save these values to a file:

$ cat /sys/module/vt/parameters/default_{red,grn,blu} > ~/myconsolecolors

Now tweak the colors using a basic text editor, and load the changes with setvtrgb. Ubuntu installs the tool at /sbin/setvtrgb with the kbd package.

$ setvtrgb ~/myconsolecolors

Once that's all working to your satisfaction, you need to run it at system boot. I'd copy your custom color file to somewhere handy in /etc/:

$ sudo cp ~/myconsolecolors /etc/custom-vt-colors

Then create a systemd unit to run it:

$ sudo nano /etc/systemd/system/custom-vt-colors.service

[Unit]
Description=Load custom VT color palette

[Service]
Type=oneshot
ExecStart=/sbin/setvtrgb /etc/custom-vt-colors

[Install]
WantedBy=multi-user.target

Finally, enable and start the service:

$ sudo systemctl enable custom-vt-colors.service
$ sudo systemctl start custom-vt-colors.service
2
  • discovering RGB values for the 16-color palette used by the OP's MS-DOS screenshot is left as an exercise for the reader. because reasons. – quixotic Mar 6 '17 at 19:09
  • 1
    I love the brown hack. – user877329 Mar 7 '17 at 7:30
2

@quixotic's answer is very thorough and spot-on, and I thank quixotic greatly!

However, I discovered that in Ubuntu Mate 19.04, it gets overridden. Essentially, there is already a service that loads a file by setvtrgb, and loads it very late.

What I did was follow the link from /etc/vtrgb to /etc/console-setup/vtrgb. Edit or replace /etc/console-setup/vtrgb, keeping the same name, and all should work correctly, as described by quixotic.

(Note: setvtrgb.service, which loads the linked-file from /etc/vtrgb, is located in /lib/systemd/system/.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.