How to increase the serial console width?

So, whenever i connect to the serial console with minicom from another linux system, the width of the terminal gets small. As if it has a fixed number of columns, is it possible to change this? I’m using @frank-w’s kernel/image.

Is agetty the binary responsible for it? I see this line on ps:

/sbin/agetty -o -p -- \u --keep-baud 115200,57600,38400,9600 - vt220

On the service file:

ExecStart=-/sbin/agetty -o '-p -- \\u' --keep-baud 115200,57600,38400,9600 - $TERM

Do i need to change the $TERM variable or something?

rsz() {
    if [[ -t 0 && $# -eq 0 ]];then
        local IFS='[;' escape geometry x y
        echo -ne '\e7\e[r\e[999;999H\e[6n\e8'
        read -t 5 -sd R escape geometry || {
            echo unsupported terminal emulator. >&2
            return 1
        }
        x="${geometry##*;}" y="${geometry%%;*}"
        if [[ ${COLUMNS} -eq "${x}" && ${LINES} -eq "${y}" ]];then
            echo "${TERM} ${x}x${y}"
        elif [[ "$x" -gt 0 && "$y" -gt 0 ]];then
            echo "${COLUMNS}x${LINES} -> ${x}x${y}"
            stty cols ${x} rows ${y}
        else
            echo unsupported terminal emulator. >&2
            return 1
        fi
    else
        echo 'Usage: rsz'
    fi
}
rsz
export TERM=xterm-256color

disclaimer: I am not the author of this and I do not remember exactly whom to attribute this to, it was some answer offered on a stackexchange post.

2 Likes

The serial settings are debian default,i do not change them. If i resize my gnome-terminal the serial console seems also resize,but sometimes chars getting overridden before reaching the full width while typing…i guess this is the issue you mean,right?

@shadow where did you placed this function and call? I guess on the bpi in users .bashrc

I place the ‘resize’ utility from Debian xterm package in my .profile like this (restricting it to interactive usage):

[[ $- =~ i ]] && {
    eval $(resize)
}

This way I get always the correct terminal settings if .profile is executed at all. What is not the case if I exit the terminal emulation over the serial line and reconnect later:

So when I reconnect to my BPI-R3 over the serial line via ‘picocom’ and terminal size settings changed since my last ‘picocom’ usage I simply logout and after re-login due to the above .profile entry settings get automatically re-adjusted to the current values.

Alternatively you can call ‘resize’ manually at any time if you have changed the terminal size.

The above script from ‘shadow’ appears to have the same functionality as xterms binary ‘resize’

Yes i know resize and had used it some time,but mostly i can work wothout it and i have changed my prompt to have more space (1 line information and second line where i type commands). It seems to have similar function without the need to install a xserver binary :slight_smile: afair there was a way to define a event hook (e.g. via trap) for window size change to call it automaticly.

Interesting share.

Didn’t work for ash in my BPI-R4 with OpenWrt. I looked into why and come up with the following modified version. The extra benefits:

  • Works in ash, dash as well as bash
  • Ready for inclusion in ‘.profile’
  • Only with effect logging into serial console
  • No effect in virtual terminals e.g. SSH sessions. Not required for virtual sessions.
rsz() {
    if [[ "$(readlink /proc/self/fd/0)" =~ /dev/tty ]];then
        stty raw
        local escape geometry="0;0" x y
        echo -ne '\e7\e[r\e[999;999H\e[6n\e8'
        IFS='[;' read -t 5 -sd R escape geometry
        x="${geometry##*;}" y="${geometry%%;*}"
        if [[ "$x" -gt 0 && "$y" -gt 0 ]];then
            printf "${COLUMNS}x${LINES} -> ${x}x${y}\n\r"
            stty cols ${x} rows ${y}
        else
            printf "unsupported terminal emulator.\n\r"
        fi
        stty sane
    fi
}
rsz
export TERM=xterm-256color

HTH

1 Like