Using Powerline fonts in the Linux text console

09 Nov 2016

The Powerline addon for vim is a really nice little handy piece of work. However, if you do any of your work in the Linux text console (the non-GUI hardware text console, not a terminal window), Powerline becomes problematic because it uses special symbols to display its nice interface, and these aren’t commonly available in console fonts.

You can, however, install the Terminus set of bitmap fonts with the Powerline symbols included. They’re in Powerline’s fonts repo on Github, under Terminus/PSF.

The tricky (or at least non-intuitive) part is getting them installed and functional. I’m going to tell you how to do it in Debian Jessie, and I believe this should also work in any recent version of Ubuntu. I can’t guarantee anything about any non-Debian-derived distros.

Copy the files

git clone https://github.com/powerline/fonts powerline-fonts
cd powerline-fonts
cp -r Terminus/PSF/*.psf.gz /usr/share/consolefonts

Edit system files to activate the fonts

/etc/default/console-setup

I’ll show you what my /etc/default/console-setup file looked like before I installed the fonts, and then afterward.

Before

# CONFIGURATION FILE FOR SETUPCON

# Consult the console-setup(5) manual page.

ACTIVE_CONSOLES="/dev/tty[1-6]"

CHARMAP="UTF-8"

CODESET="Lat15"
FONTFACE="TerminusBold"
FONTSIZE="14x28"

VIDEOMODE=

After

# CONFIGURATION FILE FOR SETUPCON

# Consult the console-setup(5) manual page.

ACTIVE_CONSOLES="/dev/tty[1-6]"

CHARMAP="UTF-8"

VIDEOMODE=
FONT="ter-powerline-v32b.psf.gz"

So basically you remove the CODESET, FONTFACE, and FONTSIZE lines, and add in a FONT line that tells it which file to load. If you hadn’t guessed this already, the numbers in the filenames indicate the pixel size of the font, and the n or b means normal or bold. Use whatever you like. Note that if you’re using the default 640x480 or 800x600 console, the larger sizes will probably be way too big, unless you’re trying to relive your glory days with a Commodore VIC-20. OK, I just seriously dated myself by saying that. Oh well.

/etc/default/grub

You might need to change your /etc/default/grub file to tell the kernel to use a resolution that allows for the font size you want to use. There are two ways of doing this: the old and the new.

The old way is to use the vga= parameter on the kernel command line. You need to use a specific numbered mode id (see the table in this Wikipedia article under the heading Linux video mode numbers,) and note that your hardware may not support all modes. In addition, this method is deprecated, so at some point it might stop working.

But for now, to use this, look for the line in /etc/default/grub that begins with GRUB_CMDLINE_LINUX. At the end of the quoted text in that line, add the vga= parameter and whichever number corresponds to the resolution and bit depth you want.

Again, standard modes are more likely to work (i.e., 640x480, 800x600, 1024x768, etc.)

The new way is to change or add two parameters to the /etc/default/grub file:

  • Add or uncomment GRUB_GFXMODE and set it to widthxheightxbitdepth. That is, for example, GRUB_GFXMODE=1024x768x16. (256-color mode is bitdepth 8, of course, 256 being the 8th power of 2.)
  • Add or uncomment GRUB_GFXPAYLOAD_LINUX=keep.

Update grub

Don’t forget to run update-grub after changing the /etc/default/grub file, otherwise your changes will have no effect.

Test and reboot

Once you’ve copied the files and edited the configuration files, you can test out the setup (if you’re in the text console already) by running the setupcon utility. It may not work if you had to change the grub graphics parameters, so in that case you’ll have to reboot.

When you reboot, the boot process will read the console-setup file and load your preferred font. And there you go. Hopefully you didn’t screw it up, because I’m not sure how you’d recover if the console font becomes unreadable, except for using ssh to get in and change it back.

Have fun.