How to resize TTY console width?
stty
does not actually re-size the terminal. It merely changes some values recorded in the line discipline. Changing the actual height and width of the terminal display proper is done with mechanisms that vary according to whether the console device is a real terminal, a kernel virtual terminal, or a user-space virtual terminal.
Real terminals
The console can be an honest-to-goodness real terminal, attached to a serial device. In which case, telling the terminal to re-size its display involves emitting a control sequence of some sort, down the wire to the terminal. What this control sequence is varies from terminal type to terminal type. There is no termcap capability that handily provides it, moreover.
Usually, but not always depending from what terminal one actually has at the other end of the serial line, terminals will obey the DEC private control sequences that DEC VT340s and above obey: DECSLPP
/DECSNLS
and DECSCPP
. The nosh toolset's console-resize
(a.k.a. resizecons
) command emits those:
$ resizecons 80x25
Note that most real terminals restrict what combinations of columns and rows will actually be enacted, to a fairly limited pre-defined set of terminal sizes. Classically, DEC VTs only support either 80 or 132 columns, for example.
Real terminals are the case where the line discipline's idea of terminal size has to be explicitly updated after changing the terminal's display size, by running stty
. The line discipline knows nothing about control sequences, and the terminal device itself has no way to influence the line discipline, and indeed has no knowledge that it is talking to an operating system that has such a concept as a line discipline.
User-space virtual terminals
The nosh toolset's user-space virtual terminals obey the same DEC private control sequences, and can be similarly adjusted with the console-resize
command. Like real terminals, they always start off in the same mode until a control sequence changes it. Unlike real terminals, but like the kernel virtual terminals that they are designed to replace, they start off in 80×25 mode rather than the 80×24 mode of many real terminals.
Similarly unlike real terminals but like kernel virtual terminals, you do not need to invoke stty
to update the line discipline after telling the terminal to change its size, because the size change operation updates the line discipline itself.
Unlike both real terminals and kernel virtual terminals, they support a much wider range of sizes that are allowed in the control sequences, from 2×2 to 65535×65535.
This brings us to kernel virtual terminals.
Kernel virtual terminals
These are the ones provided by the terminal emulator that is built into the kernel itself. They are what you might naïvely think to be "the console" until you read the manual and realize that the console (defined as the place to which kernel diagnostic and trace output and output to /dev/console
are sent) can be a real terminal over a serial device (comconsole
), a kernel virtual terminal (vidconsole
), or nothing at all (nullconsole
).
They are not manipulated with control sequences; rather, one opens such a terminal device and performs device-specific ioctl()
requests. Fortunately, there is a tool that wraps some of the more common ioctl()
requests, making them accessible without having to write a program of one's own.
From a login session on the kernel virtual terminal to be changed itself, or with standard input redirected from such a terminal device:
- Obtain the list of available modes:
$ vidcontrol -i mode
- Determine a mode with suitable rows and columns. On one of my machines that happens to be this one, which with a 8×16 font is 160 columns and 64 rows:
283 (0x11b) 0x0000001f G 1280x1024x32 D 8x16 0xa0000 64k 64k 0xf1000000 5120k
- Change to that mode:
$ vidcontrol MODE_283
- Make this resizing persistent, by having the preceding command run at bootstrap:
# sysrc allscreens_flags=MODE_283
Your size choices are constrained by whether you are using the old syscons or the new vt kernel terminal emulator, and by what it knows about the display adapter that is underpinning the emulated display.
Further reading
- "Virtual Consoles and Terminals". FreeBSD Handbook. The FreeBSD Documentation Project. 2018-09-05.
- Jonathan de Boyne Pollard (2018). "Terminals". nosh Guide. Softwares.
- VT510 Video Terminal Programmer Information. EK-VT510-RM. November 1993. DEC.
- VT520/VT525 Video Terminal Programmer Information. EK-VT520-RM. July 1994. DEC.
- Jordan K. Hubbard (2017-12-17).
rc.conf
. FreeBSD File Formats Manual. - Soren Schmidt and Sascha Wildner (2016-01-19).
vidcontrol
. FreeBSD General Commands Manual. - Devin Teske (2016-02-02).
sysrc
. FreeBSD System Manager's Manual. - Daniel C. Sobral (2016-01-20).
loader.conf
. FreeBSD File Formats Manual. - Jonathan de Boyne Pollard (2016).
console-resize
,resizecons
. nosh Guide. Softwares. - https://unix.stackexchange.com/a/284438/5132
Related videos on Youtube
F.M
Updated on September 18, 2022Comments
-
F.M over 1 year
I'm on FreeBSD.
I want to set console width (just console, not ssh or telnet).
I used this command:
stty cols 132
Is this work for just console or worked for all of the connections (console, ssh and telnet)?
-
jsotola over 5 yearswhat is preventing you from trying it out and answering your own question?
-
F.M over 5 yearsi'm not sure it's just for console or not. I don't want to change other terminals. I want to change JUST console connection.
-
Vlastimil Burián over 5 years@F.M So, try that out yourself, why not?
-
jsotola over 5 yearstest it and post an answer .... then you can accept your own answer
-
F.M over 5 yearsI searched and I see a stty term=vt100 cols 132 in linux but in freebsd I can not find this option. I test it in console connection and ssh too, but i doubt on their output
-
F.M over 5 yearsOk, Thanks. I will search more and post the result here.
-