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)?

  • 2
    what is preventing you from trying it out and answering your own question? – jsotola Oct 6 '18 at 5:57
  • i'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. – F.M Oct 6 '18 at 6:07
  • 1
    @F.M So, try that out yourself, why not? – Vlastimil Oct 6 '18 at 6:09
  • test it and post an answer .... then you can accept your own answer – jsotola Oct 6 '18 at 6:15
  • I 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 Oct 6 '18 at 6:18

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:

  1. Obtain the list of available modes:

    $ vidcontrol -i mode
  2. 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
  3. Change to that mode:

    $ vidcontrol MODE_283
  4. 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.