summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2023-03-06 18:27:18 +0100
committerHelmut Grohne <helmut@subdivi.de>2023-03-06 18:27:18 +0100
commit1918b1febae9add1edda2fe1b410617002b8afdc (patch)
treedfa84e5d1393075178a73d3046dee4577b1d1bf0
parent67544c5703998d9f6a67b9f6e7b76b4abf12c72b (diff)
downloaddebvm-1918b1febae9add1edda2fe1b410617002b8afdc.tar.gz
debvm-create: autodetect size of serial consoles
We now extend /etc/profile to invoke setterm -resize when detecting an interactive login on a serial console. This should fix 90% of wrongly sized serial consoles.
-rwxr-xr-xbin/debvm-run3
-rwxr-xr-xshare/customize-autologin.sh16
2 files changed, 17 insertions, 2 deletions
diff --git a/bin/debvm-run b/bin/debvm-run
index 81114e6..e45f350 100755
--- a/bin/debvm-run
+++ b/bin/debvm-run
@@ -67,7 +67,8 @@ F<rootfs.ext4>, resulting in an ephemeral run.
Make sure C<$TERM> is set to a value known inside the VM.
You may need to install B<ncurses-term> for more definitions.
-It also helps to run C<setterm --resize> after boot and when resizing the terminal emulator.
+The serial console will miss events of resizing the terminal emulator.
+You may run C<setterm -resize> in that case.
=item How can I kill debvm-run?
diff --git a/share/customize-autologin.sh b/share/customize-autologin.sh
index 9effa29..da40342 100755
--- a/share/customize-autologin.sh
+++ b/share/customize-autologin.sh
@@ -4,12 +4,26 @@
#
# This is a mmdebstrap customize hook that configures automatic root login on a
# serial console. It also parses the TERM kernel cmdline and passes it as
-# TERM to agetty.
+# TERM to agetty. Since serial consoles do not transmit SIGWINCH, it causes
+# the shell to run setterm -resize on interactive, serial logins.
set -eu
TARGET=$1
+cat >"$TARGET/etc/profile.d/resize_serial_term.sh" <<'EOF'
+if test -n "${TERM-}" && test -n "${PS1-}"; then
+ case "$(tty)" in
+ /dev/tty[0-9]*)
+ ;;
+ /dev/tty*)
+ # Assume that every other tty is serial and should be resized.
+ setterm -resize
+ ;;
+ esac
+fi
+EOF
+
if test "$(dpkg-query --root "$TARGET" -f '${db:Status-Status}' -W systemd-sysv 2>/dev/null)" = installed; then
UNIT=serial-getty@.service