Skip to content

Commit 84da18e

Browse files
committed
contrib/: expand font setting capabilities
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.
1 parent 886b833 commit 84da18e

File tree

5 files changed

+47
-2
lines changed

5 files changed

+47
-2
lines changed

contrib/20-console-autosize.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
# vim: softtabstop=2 shiftwidth=2 expandtab
3+
4+
## This early-setup hook attempts to get a physical (non-serial) console
5+
## to at least 100 columns. The Dracut module 'i18n' is required to populate
6+
## /usr/share/consolefonts and to add the 'setfont' binary.
7+
##
8+
## This hook is enabled by default in Release and Recovery builds. To disable,
9+
## add `zbm.autosize=off` to the ZFSBootMenu kernel commandline.
10+
## If rd.vconsole.font is defined, autosizing is skipped to not override
11+
## this font preference.
12+
13+
14+
#shellcheck disable=SC1091
15+
source /lib/zfsbootmenu-kcl.sh || exit 1
16+
source /lib/kmsg-log-lib.sh || exit 1
17+
18+
if [ -z "${control_term}" ] && [ -f /etc/zfsbootmenu.conf ]; then
19+
#shellcheck disable=SC1091
20+
source /etc/zfsbootmenu.conf
21+
fi
22+
23+
[ -c "${control_term}" ] || exit 1
24+
25+
# Ensure that control_term is not a serial console
26+
tty_re='/dev/tty[0-9]'
27+
[[ ${control_term} =~ ${tty_re} ]] || exit 1
28+
29+
if get_zbm_bool 1 zbm.autosize && ! font=$( get_zbm_arg rd.vconsole.font ) ; then
30+
for font in ter-v32b ter-v28b ter-v24b ter-v20b ter-v14b ; do
31+
setfont "${font}" >/dev/null 2>&1
32+
if [ "${COLUMNS}" -ge 100 ]; then
33+
zdebug "set font to ${font}, screen is ${COLUMNS}x${LINES}"
34+
break
35+
fi
36+
done
37+
fi

etc/zfsbootmenu/release.conf.d/common.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
zfsbootmenu_teardown+=" /zbm/contrib/xhci-teardown.sh "
2-
zfsbootmenu_early_setup+=" /zbm/contrib/console-init.sh "
2+
zfsbootmenu_early_setup+=" /zbm/contrib/10-console-init.sh /zbm/contrib/20-console-autosize.sh "
33

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

etc/zfsbootmenu/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ EFI:
1111
Versions: false
1212
Enabled: true
1313
Kernel:
14-
CommandLine: zfsbootmenu loglevel=4 nomodeset
14+
CommandLine: loglevel=4 nomodeset

testing/run.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ fi
234234
if [ -n "${DISPLAY_TYPE}" ]; then
235235
# Use the indicated graphical display
236236
DISPLAY_ARGS=( "-display" "${DISPLAY_TYPE}" )
237+
238+
# Add release hooks, supported only under Dracut
239+
if ((DRACUT)); then
240+
cat <<-EOF >> "${TESTDIR}/dracut.conf.d/testing.conf"
241+
zfsbootmenu_early_setup+=" $( realpath -e ../contrib )/10-console-init.sh "
242+
zfsbootmenu_early_setup+=" $( realpath -e ../contrib )/20-console-autosize.sh "
243+
EOF
244+
fi
237245
else
238246
# Suppress graphical display (implies serial mode)
239247
DISPLAY_ARGS=( "-nographic" )

0 commit comments

Comments
 (0)