Skip to content

Commit

Permalink
contrib/: expand font setting capabilities
Browse files Browse the repository at this point in the history
ZFSBootMenu binary releases use a default font size that's barely
suitable for 2k screens and entirely unsuitable for 4k screens. In an
attempt to fix this, a new script has been added that introduces
automatic console font resizing.

Utilizing the Terminus font, we can pick a range of bold font sizes to
better match screen resolutions. Working backwards from the largest to
the smallest, the hook simply runs `setfont` and then checks if COLUMNS
is at least 100 characters. If it is not, the next font is selected and
it tries again.

Based on documentation, Terminus fonts prefixed with a 'v' have all
mappings/codepages in them; so they should support the maximal number of
languages.

contrib/20-console-autosize.sh is included in all release and recovery
images. The automatic font setting behavior can be disabled via
zbm.autosize=(0|off).

contrib/console-init.sh has been renamed to ensure it precedes this
hook, since 10-console-init.sh calls console_init from Dracut, which is
hard-coded to set a console font. Since console_init also performs setting
a keymap, it should always be executed.

The legacy behavior of setting a font via rd.vconsole.font
overrides/disables zbm.autosize.
  • Loading branch information
zdykstra committed Jan 30, 2023
1 parent 886b833 commit 84da18e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
File renamed without changes.
37 changes: 37 additions & 0 deletions contrib/20-console-autosize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
# vim: softtabstop=2 shiftwidth=2 expandtab

## This early-setup hook attempts to get a physical (non-serial) console
## to at least 100 columns. The Dracut module 'i18n' is required to populate
## /usr/share/consolefonts and to add the 'setfont' binary.
##
## This hook is enabled by default in Release and Recovery builds. To disable,
## add `zbm.autosize=off` to the ZFSBootMenu kernel commandline.
## If rd.vconsole.font is defined, autosizing is skipped to not override
## this font preference.


#shellcheck disable=SC1091
source /lib/zfsbootmenu-kcl.sh || exit 1
source /lib/kmsg-log-lib.sh || exit 1

if [ -z "${control_term}" ] && [ -f /etc/zfsbootmenu.conf ]; then
#shellcheck disable=SC1091
source /etc/zfsbootmenu.conf
fi

[ -c "${control_term}" ] || exit 1

# Ensure that control_term is not a serial console
tty_re='/dev/tty[0-9]'
[[ ${control_term} =~ ${tty_re} ]] || exit 1

if get_zbm_bool 1 zbm.autosize && ! font=$( get_zbm_arg rd.vconsole.font ) ; then
for font in ter-v32b ter-v28b ter-v24b ter-v20b ter-v14b ; do
setfont "${font}" >/dev/null 2>&1
if [ "${COLUMNS}" -ge 100 ]; then
zdebug "set font to ${font}, screen is ${COLUMNS}x${LINES}"
break
fi
done
fi
2 changes: 1 addition & 1 deletion etc/zfsbootmenu/release.conf.d/common.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
zfsbootmenu_teardown+=" /zbm/contrib/xhci-teardown.sh "
zfsbootmenu_early_setup+=" /zbm/contrib/console-init.sh "
zfsbootmenu_early_setup+=" /zbm/contrib/10-console-init.sh /zbm/contrib/20-console-autosize.sh "

install_optional_items+=" /etc/zbm-commit-hash "

Expand Down
2 changes: 1 addition & 1 deletion etc/zfsbootmenu/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ EFI:
Versions: false
Enabled: true
Kernel:
CommandLine: zfsbootmenu loglevel=4 nomodeset
CommandLine: loglevel=4 nomodeset
8 changes: 8 additions & 0 deletions testing/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ fi
if [ -n "${DISPLAY_TYPE}" ]; then
# Use the indicated graphical display
DISPLAY_ARGS=( "-display" "${DISPLAY_TYPE}" )

# Add release hooks, supported only under Dracut
if ((DRACUT)); then
cat <<-EOF >> "${TESTDIR}/dracut.conf.d/testing.conf"
zfsbootmenu_early_setup+=" $( realpath -e ../contrib )/10-console-init.sh "
zfsbootmenu_early_setup+=" $( realpath -e ../contrib )/20-console-autosize.sh "
EOF
fi
else
# Suppress graphical display (implies serial mode)
DISPLAY_ARGS=( "-nographic" )
Expand Down

0 comments on commit 84da18e

Please sign in to comment.