16

I have a virtualization server to which I connect over ssh. If I now change the size of the window it will automatically propagate to the server. It's most easily seen using stty -a, checking the columns and row values.

I then use virsh console to connect to the serial interface on a KVM based virtual machine. When I now change the size of the window it does not propagate to the virtual server. This is most easily seen by checking stty -a, which is not updated on the virtual machine when I change window size. This means that line breaks does not work correctly in the terminal and any application that relies on window size for formatting (emacs, man, etc) gets messed up unless the window size on the client matches the default size on the server.

A workaround is to manually set the window size to match the client window using stty, but I wonder if there is any way to get this information to propagate and set the window size in the virtual machine automatically.

4 Answers 4

11
+150

You could mostly work around this problem in the shell.

The command:

eval `/usr/bin/resize`

will set the COLUMNS and LINES shell variables appropriately and then export them. So in bash, you could add the following to your .bash_profile (or .profile, depending on which you use)

PROMPT_COMMAND="eval `/usr/bin/resize`"

Or in zsh:

function precmd {
    eval `/usr/bin/resize`
}

So that a resize would be performed right before each prompt was displayed. The effect wouldn't be like that of ssh or telnet where the window changes would be handled immediately as a result, however I think this is probably the best you'll get.

2
  • A little hacky, but still a good solution. Thank you!
    – pehrs
    Dec 29, 2010 at 11:09
  • 1
    See also this answer to do it without xterm's resize command: unix.stackexchange.com/a/283206
    – rsaw
    Dec 30, 2016 at 20:31
4

Telnet and SSH has an out of band channel to configure these settings. Serial interface does not. See: https://www.rfc-editor.org/rfc/rfc1073 and https://www.rfc-editor.org/rfc/rfc4254#page-14

1
  • 3
    I kind of figured out that there was a control channel involved. But the question remains, is there a better workaround for consoles of KVM based virtual machines? (I don't mind reconfiguring the machines)
    – pehrs
    Dec 22, 2010 at 15:16
4

if resize command is not available in your system you can try something like:

stty rows 45 
stty columns 140

but you have to put it your .bash_profile to persist the change and then source it to see the change

0

Just adding to mark's answer, bacause Serverfault does not allow me to comment.

When the target domain is OpenBSD 6.6, resize is located elsewhere and requires the xbase66 set at least.

Additionally, if you are using the default ksh, it is enough to run:

eval `/usr/X11R6/bin/resize`

It is a shame that this is not in Red Hat's KVM Admin Guide.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .