Skip to content

Commit 3f88041

Browse files
dcasotaclaude
andcommitted
installer: move the locale.conf write to PRE_PKGS_INSTALL
dracut's 20i18n module reads /etc/locale.conf when it builds an initrd, and the initramfs rpm installs a file trigger that runs mkinitrd at the END of the package transaction started by _install_packages(). m_locale ran at POST_INSTALL, so the file was written after that trigger had already fired. dracut therefore aborted i18n setup with "i18n_vars not set! Please set up i18n_vars in configuration file." and fell back to embedding every keymap. Move the write into the PRE_PKGS_INSTALL phase, where it lands before the transaction. _initialize_system() runs immediately before that phase, so the file appears at very nearly the same point in the sequence. localedef cannot move with it. It runs inside the chroot, and at PRE_PKGS_INSTALL the target holds only an initialised rpm database and the `filesystem` rpm - glibc, which provides /usr/bin/localedef, is not installed until _install_packages(). So locale setup is split along the line the phases already draw: m_locale.py PRE_PKGS_INSTALL writes /etc/locale.conf m_localedef.py POST_INSTALL runs localedef A separate module rather than a two-phase one because install_phase is a scalar compared with !=; making a single module span two phases would mean changing the dispatcher. Signed-off-by: Daniel Casota <dcasota@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JW73JTCUGRcaNTUEQcAMtf
1 parent f614b59 commit 3f88041

2 files changed

Lines changed: 45 additions & 15 deletions

File tree

photon_installer/modules/m_locale.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@
77

88
import commons
99

10-
install_phase = commons.POST_INSTALL
10+
# PRE_PKGS_INSTALL, not POST_INSTALL: dracut's 20i18n module reads
11+
# /etc/locale.conf when it builds an initrd, and the initramfs rpm installs a
12+
# file trigger that runs mkinitrd at the END of the package transaction started
13+
# by _install_packages(). A file written after that transaction is written too
14+
# late. Without it dracut aborts i18n setup with
15+
# "i18n_vars not set! Please set up i18n_vars in configuration file."
16+
# and falls back to embedding every keymap.
17+
#
18+
# _initialize_system() runs immediately before this phase, so the file lands at
19+
# very nearly the same point in the sequence as it would have from there, but
20+
# in the module that owns locale rather than in the installer body.
21+
install_phase = commons.PRE_PKGS_INSTALL
1122
enabled = True
1223

1324

1425
def execute(installer):
1526
# Set locale
16-
with open(
17-
os.path.join(installer.photon_root, "etc/locale.conf"), "w"
18-
) as locale_conf:
27+
locale_conf_path = os.path.join(installer.photon_root, "etc/locale.conf")
28+
os.makedirs(os.path.dirname(locale_conf_path), exist_ok=True)
29+
with open(locale_conf_path, "w") as locale_conf:
1930
locale_conf.write("LANG=en_US.UTF-8\n")
20-
21-
"""
22-
locale-gen.sh needs /usr/share/locale/locale.alias which is shipped
23-
with glibc-lang rpm, in some photon installations glibc-lang rpm is
24-
not installed by default. Call localedef directly here to define
25-
locale environment.
26-
"""
27-
installer.cmd.run_in_chroot(
28-
installer.photon_root,
29-
"/usr/bin/localedef -c -i en_US -f UTF-8 en_US.UTF-8",
30-
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# /*
2+
# * Copyright © 2020 VMware, Inc.
3+
# * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-only
4+
# */
5+
6+
import commons
7+
8+
# The other half of locale setup, and the half that cannot move earlier.
9+
#
10+
# m_locale writes /etc/locale.conf at PRE_PKGS_INSTALL because dracut needs it
11+
# before the package transaction ends. localedef cannot follow it there: it runs
12+
# inside the chroot, and at PRE_PKGS_INSTALL the target holds only an
13+
# initialised rpm database and the `filesystem` rpm - glibc, which provides
14+
# /usr/bin/localedef, is not installed until _install_packages(). So this stays
15+
# at POST_INSTALL.
16+
install_phase = commons.POST_INSTALL
17+
enabled = True
18+
19+
20+
def execute(installer):
21+
"""
22+
locale-gen.sh needs /usr/share/locale/locale.alias which is shipped
23+
with glibc-lang rpm, in some photon installations glibc-lang rpm is
24+
not installed by default. Call localedef directly here to define
25+
locale environment.
26+
"""
27+
installer.cmd.run_in_chroot(
28+
installer.photon_root,
29+
"/usr/bin/localedef -c -i en_US -f UTF-8 en_US.UTF-8",
30+
)

0 commit comments

Comments
 (0)