Change colour of text and background on the Linux console

Q How can I change the colour of the text and background on the Linux console in run level 3? I would like to change the colour to black text on a white background. If possible, I would like this change to be evident as soon as the kernel begins to load so all the boot messages are black text on a white background. I have a suspicion that I may need to do some kernel hacking for this and if so which part of the kernel source code would need to be changed?

A Changing the colours of a console can be done in two ways, once it is started. You can echo ANSI codes, provided you can remember what they are, or you can use the setterm command to make the changes. To set black on white, you would use

setterm -background white -foreground white -store

The setterm man page contains full details of the various options and the valid colour values. You can run this command from a startup script, the details are distro-dependent but /etc/rc.local is often a good starting point. If you want to change the colours right from the start, you'll need to edit the kernel source to change the default colours and recompile your kernel. The file to edit is drivers/char/vt.c (it was drivers/char/console.c with older kernels); find the lines starting with

vc->vc_def_color         = 0x07; /* white */

This is at line 2739 in the 2.6.22 sources. The two hex digits represent the background and foreground, so 0x07 is the default white on black, whereas 0x70 would be the reverse setting that you want. Change the values to your preferred defaults and recompile your kernel in the usual way. The numbers for the various colours are

3 ...............cyan
5 ...............purple
6 ...............brown/yellow
7 ...............white

Add 8 to these numbers to get the 'bright' versions, but rendering of bright colours is hardware-dependent and may blink on some systems.

Follow us on or Twitter

Username:   Password:
Create Account | About TuxRadar