Load and Test a Linux Console Font with setfont

A garbled console font at 2am is a bad time to learn setfont, so test it properly first. You will load a font into a Linux virtual console, confirm the command and font are the ones you meant, and keep a way back if the result is unreadable. The examples use setfont from kbd 2.6.4, installed here as Ubuntu package version 2.6.4-2ubuntu2. Allow about ten minutes for a one-off change, plus time to choose a font that suits your display.

This is about the Linux text console, such as a virtual terminal reached with Ctrl+Alt+F3. It does not touch a terminal emulator inside a graphical desktop. Loading a font changes the display state of the selected console, so keep another terminal or a second virtual terminal available before you start.

1. Check the installed command

Start with read-only checks. These do not need elevated privileges:

$ command -v setfont
/usr/bin/setfont
$ setfont -V
setfont from kbd 2.6.4

The version matters because kbd releases can add font and kernel support. This guide describes the installed command and its setfont(8) manual page. Do not assume an option from a different distribution behaves the same way here.

Checkpoint: if command -v finds nothing, install the kbd package through your normal system-management process before continuing. Do not copy a replacement binary into /usr/bin.

2. Find a real font file

When no path is given, setfont looks in the default console-font directory, normally /usr/share/consolefonts. Listing that directory is safe:

$ find /usr/share/consolefonts -maxdepth 1 -type f -name '*.psf*' | head
/usr/share/consolefonts/Hebrew-Terminus18x10.psf.gz
/usr/share/consolefonts/CyrKoi-TerminusBold14.psf.gz
/usr/share/consolefonts/Lat15-Terminus16.psf.gz

Inspect the exact candidate before loading it:

$ FONT='/usr/share/consolefonts/Lat15-Terminus16.psf.gz'
$ test -r "$FONT" && printf 'readable: %s\n' "$FONT"
readable: /usr/share/consolefonts/Lat15-Terminus16.psf.gz

Replace the example value with a file that exists on your machine, and keep the variable quoted in later commands. A typo here is easier to diagnose before the console has changed.

3. Save the current font before changing the console

Saving the old font is the sensible recovery step. The -o option writes the previous font to a file. Choose a private, writable location and a new filename:

$ BACKUP="$HOME/console-font-before-setfont.fnt"
$ setfont -o "$BACKUP" "$FONT"
$ ls -lh "$BACKUP"
-rw------- 1 ... ... ... /home/you/console-font-before-setfont.fnt

The exact size and ownership display are host-specific. What matters is a non-empty backup file and a successful exit status. The command changes the current console, so run it from the console you intend to alter. To target another virtual terminal instead, use -C and identify that console explicitly.

Warning: shell redirection is not used for the backup. Do not point -o at a valuable existing file unless you have deliberately chosen to replace it. The old font is binary data, not a text configuration file.

4. Load the font on the current console

If the backup command succeeded, the font is already loaded by the previous step. For a direct load after that point, use:

$ setfont "$FONT"
$ printf 'setfont exit status: %s\n' "$?"
setfont exit status: 0

There is normally no success message: the visual result is the changed character shape on the console. A zero exit status means setfont completed the requested operation. It does not prove the font is comfortable, that every character has a glyph, or that a mapping is correct.

Do not use sudo automatically. Loading the current console usually works as the user who owns the session. Setting a different console with -C may require root permissions:

# setfont -C /dev/tty3 -o /root/tty3-font-before.fnt "$FONT"

This elevated example changes /dev/tty3, not necessarily the terminal from which you typed it. Check the target carefully before pressing Enter. If a font makes the target unreadable, switch to another virtual terminal and restore the saved file there.

5. Restore the previous font

The saved file loads back as a normal font file:

$ setfont "$BACKUP"
$ printf 'restore exit status: %s\n' "$?"
restore exit status: 0

This restores the bitmap that was saved. If the original font also depended on a separate console map or Unicode map, save and restore those separately with -om and -ou, or save the font and Unicode map together with -O:

$ setfont -O "$HOME/console-state-before.fnt" "$FONT"
$ setfont "$HOME/console-state-before.fnt"

Use -O when preserving the font's embedded Unicode map matters, and -o when the bitmap alone is sufficient. Treat these files as machine-specific console state, and do not edit them in a text editor.

6. Handle mappings and character sets

Most modern PSF fonts include their own Unicode map. If text appears as the wrong symbols, the font may need an explicit Unicode table with -u, or an appropriate console map with -m. The manual documents an ISO 8859-2 map by name, for example:

$ setfont -m 8859-2 -u none "$FONT"

Do not paste that example merely because it exists. -u none disables loading a Unicode map, which is appropriate only when you have a reason to use a direct or separately selected mapping. For an ordinary Unicode console and a font that already contains a map, omit both options:

$ setfont "$FONT"

If a font has no Unicode mapping, supply the matching table with -u. If the source program uses an eight-bit character set, choose the corresponding console map with -m. A mismatch can leave accented letters or line-drawing characters wrong even though setfont exits successfully.

7. Diagnose a failed or unusable load

For a file error, check the path and permissions without changing the console:

$ test -f "$FONT" && echo 'font file exists'
font file exists
$ test -r "$FONT" && echo 'font file is readable'
font file is readable

If setfont reports an invalid format, confirm the file is a console font rather than an unrelated archive or desktop font. The manual describes PSF and older raw and code-page formats. Code-page files can contain several font heights, so they may need a height option such as -8, -14 or -16; do not guess which one fits.

If the console is readable but missing characters display badly, revisit the font's Unicode table and the selected map. Here is the fact worth remembering: if a font has more than 256 glyphs, the manual warns that the console may lose half its colour levels, because the hardware intensity bit gets used to select glyphs instead. A technically successful load can still be a poor choice for a colour-dependent console.

If you targeted the wrong virtual terminal, use Ctrl+Alt+F1 through F12 as appropriate for your host, then restore the intended console with -C. The available terminal numbers and key combinations vary, so do not treat a particular function key as universal.

Done means