Switch a Linux Virtual Console to UTF-8 with unicode_start
Log into a bare Linux virtual console and type an accented character, and it comes out garbled: unicode_start switches that console into UTF-8 mode. It changes the console and its keyboard together, and this guide uses the version from kbd 2.6.4-2ubuntu2, installed on this machine.
The route
Jump straight to the step you need, or tick off Done means at the end.
- Time: about ten minutes.
- You need: a local virtual console such as
/dev/tty1,/dev/tty2or/dev/console, the kbd package, and permission to change that console. - Will not touch: a terminal emulator, SSH session or pseudo-terminal. The script deliberately skips all of those.
Checkpoint
The first command below is read-only. The second changes the current console, so run it only from the virtual console you actually mean to change.
1. Confirm the installed command
Check the executable and package version before relying on examples. These commands do not change console state:
$ command -v unicode_start
/usr/bin/unicode_start
$ dpkg-query -W -f='${Package} ${Version}\n' kbd
kbd 2.6.4-2ubuntu2
The installed interface is unicode_start [font [unicode map]]. It has no switch for choosing a console: it operates on the console attached to standard input, and it refuses non-console devices outright.
2. Check which console you are actually using
Run this ordinary diagnostic before changing anything:
$ tty
/dev/tty2
Your device number will differ. A path beginning with /dev/pts/, or output such as not a tty, means you are not in the target virtual console. Do not try to force the operation through an SSH or terminal-emulator session. Switch to a real Linux virtual console first, commonly with Ctrl+Alt+F2, subject to your desktop and hardware.
On this machine, running the command from a non-console context produces this harmless result:
$ unicode_start
unicode_start skipped on not a tty
$ printf 'exit status: %s\n' "$?"
exit status: 0
Status 0 here only means the script skipped an unsuitable terminal. It does not mean the console is now in Unicode mode.
3. Enable UTF-8 mode on the virtual console
From the intended virtual console, run:
$ unicode_start
No success message is printed, which is normal. The command sets the keyboard driver to UTF-8 mode, changes the console output driver to expect UTF-8, enables the terminal's UTF-8 input setting, and leaves the current font alone when no font argument is supplied.
Use the least privilege that works: some of those operations need access to the console device. Root gets an extra step too. Tip: when run as root, unicode_start saves the current keymap under $HOME/.kbd/.keymap_sv before reloading a Unicode-capable copy, and that saved file is exactly what unicode_stop restores later. A non-root user can still change their own console's Unicode mode, just without the global keymap reload.
Checkpoint
Test a non-ASCII character rather than trusting a blank prompt:
$ printf '%s\n' 'café £ 日本'
café £ 日本
The exact glyphs depend on the console font. Garbled output can mean the font lacks a Unicode map, not that keyboard mode failed.
4. Load a font only when the current one is unsuitable
Pass a font file as the first argument when the console needs a different font:
$ unicode_start /path/to/console-font.psf
That path is a placeholder: replace it with a font that actually exists on your system, never an invented file name. The font should carry a built-in Unicode map. If it does not, supply the map as a second argument:
$ unicode_start /path/to/console-font.psf /path/to/unicode-map
This reloads the font with setfont. It does not install a font or make the change permanent across boots. To find local font files, check the directories your distribution ships them in, then verify the chosen path before running the command.
5. Verify the keyboard and output modes
Ask kbd_mode to report the keyboard mode, on the same virtual console:
$ kbd_mode
UTF-8
Then print representative UTF-8 data again. This checks the path from the shell to the console, but it cannot prove every application or font will render every character correctly.
Two failure messages point back to step 2, not forward. If /proc is not mounted, unicode_start cannot determine the console type and exits with an error. If it says the terminal is not a VT, you are still on the wrong terminal. Neither is fixed by adding sudo while staying in an SSH or pseudo-terminal session.
6. Return to the earlier mode
Unicode mode is per virtual console, and nothing undoes it automatically when you close a shell. When you need to restore the traditional ASCII keyboard and console settings, run the companion command on that same console:
$ unicode_stop
$ kbd_mode
ASCII
Recovery
For a root-run unicode_start, unicode_stop also reloads the saved keymap from $HOME/.kbd/.keymap_sv when that file is readable. If no backup was created, the keyboard mapping cannot be reconstructed by this command, so do not delete that file until you have finished testing.
After stopping Unicode mode, run a small ASCII test and switch back with unicode_start if the console still needs UTF-8 work. The font change itself may remain, because unicode_stop resets modes and restores the saved keymap, not necessarily the previous font.
Done means
- Confirmed a real console. You checked that the session is an actual virtual console, not a pseudo-terminal.
- Ran the switch.
unicode_startcompleted on the intended console. - Verified it.
kbd_modereportsUTF-8and representative text displays correctly. - Handled fonts carefully. You used a verified font and Unicode map path only when the current font needed replacing.
- Know the way back. You know to run
unicode_stopon the same console to leave Unicode mode.