Upload files to "/"
This commit is contained in:
166
proxmox_lxc_locale_fix_readme.md
Normal file
166
proxmox_lxc_locale_fix_readme.md
Normal file
@@ -0,0 +1,166 @@
|
||||
# Fix `setlocale: LC_ALL: cannot change locale (en_US.UTF-8)` in Proxmox LXC
|
||||
|
||||
## Context
|
||||
|
||||
During the execution of **Ultimate Updater** on a Proxmox VE host,
|
||||
several LXC containers produced the warning:
|
||||
|
||||
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
|
||||
|
||||
This happens when:
|
||||
|
||||
- `LANG=en_US.UTF-8` or `LC_ALL=en_US.UTF-8` is configured
|
||||
- but the locale **has not been generated** inside the container.
|
||||
|
||||
Typical symptoms:
|
||||
|
||||
locale -a
|
||||
C
|
||||
C.utf8
|
||||
POSIX
|
||||
|
||||
The container tries to use `en_US.UTF-8` but it does not exist yet.
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
# Affected Containers
|
||||
|
||||
The following LXC containers were detected in logs:
|
||||
|
||||
VMID Name
|
||||
---------- --------------
|
||||
21211434 ollama-lxc
|
||||
21302002 wireshark
|
||||
21808501 subsai
|
||||
22101900 cast-relay
|
||||
22202000 dev-vscodium
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
# Solution
|
||||
|
||||
The solution is to:
|
||||
|
||||
1. Install locale packages
|
||||
2. Generate the `en_US.UTF-8` locale
|
||||
3. Set system environment variables
|
||||
4. Apply the fix across all containers automatically
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
# Automated Fix Script (Run on Proxmox Host)
|
||||
|
||||
``` bash
|
||||
for CT in 21211434 21302002 21808501 22101900 22202000; do
|
||||
echo "===== CT $CT ====="
|
||||
|
||||
WAS_RUNNING=0
|
||||
if [ "$(pct status "$CT" | awk '{print $2}')" = "running" ]; then
|
||||
WAS_RUNNING=1
|
||||
else
|
||||
pct start "$CT"
|
||||
sleep 3
|
||||
fi
|
||||
|
||||
pct exec "$CT" -- bash -lc 'apt update && apt install -y locales'
|
||||
|
||||
pct exec "$CT" -- bash -lc '
|
||||
grep -q "^en_US.UTF-8 UTF-8" /etc/locale.gen ||
|
||||
sed -i "s/^# *en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" /etc/locale.gen ||
|
||||
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
|
||||
'
|
||||
|
||||
pct exec "$CT" -- bash -lc 'locale-gen en_US.UTF-8'
|
||||
|
||||
pct exec "$CT" -- bash -lc '
|
||||
update-locale LANG=en_US.UTF-8 LANGUAGE=en_US LC_ALL=en_US.UTF-8
|
||||
'
|
||||
|
||||
pct exec "$CT" -- bash -lc '
|
||||
printf "LANG=en_US.UTF-8\nLANGUAGE=en_US\nLC_ALL=en_US.UTF-8\n" > /etc/environment
|
||||
'
|
||||
|
||||
pct exec "$CT" -- bash -lc 'locale'
|
||||
|
||||
if [ "$WAS_RUNNING" -eq 0 ]; then
|
||||
pct stop "$CT"
|
||||
fi
|
||||
done
|
||||
```
|
||||
|
||||
Behavior of the script:
|
||||
|
||||
- If the container **is already running**, it remains running.
|
||||
- If the container **was stopped**, it is temporarily started, fixed,
|
||||
then stopped again.
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
# Verification Script
|
||||
|
||||
After applying the fix:
|
||||
|
||||
``` bash
|
||||
for CT in 21211434 21302002 21808501 22101900 22202000; do
|
||||
echo "===== CT $CT ====="
|
||||
|
||||
WAS_RUNNING=0
|
||||
if [ "$(pct status "$CT" | awk '{print $2}')" = "running" ]; then
|
||||
WAS_RUNNING=1
|
||||
else
|
||||
pct start "$CT"
|
||||
sleep 3
|
||||
fi
|
||||
|
||||
pct exec "$CT" -- bash -lc 'locale; echo; locale -a | grep -i en_US'
|
||||
|
||||
if [ "$WAS_RUNNING" -eq 0 ]; then
|
||||
pct stop "$CT"
|
||||
fi
|
||||
done
|
||||
```
|
||||
|
||||
Expected output:
|
||||
|
||||
LANG=en_US.UTF-8
|
||||
LC_ALL=en_US.UTF-8
|
||||
...
|
||||
en_US.utf8
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
# Log Verification
|
||||
|
||||
To confirm that **Ultimate Updater** no longer reports the warning:
|
||||
|
||||
``` bash
|
||||
grep -in "setlocale" /var/log/ultimate-updater.log
|
||||
```
|
||||
|
||||
The warning should no longer appear for these containers.
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
# Notes
|
||||
|
||||
- The warning may still appear **during the fix execution**, because
|
||||
the old environment is still loaded.
|
||||
- After `locale-gen` and `update-locale`, the system configuration is
|
||||
correct.
|
||||
- The fix is **persistent** and survives container reboot.
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
||||
# Result
|
||||
|
||||
All containers now correctly use:
|
||||
|
||||
LANG=en_US.UTF-8
|
||||
LC_ALL=en_US.UTF-8
|
||||
|
||||
Locale list:
|
||||
|
||||
locale -a
|
||||
en_US.utf8
|
||||
|
||||
The Proxmox update process runs without locale warnings.
|
||||
Reference in New Issue
Block a user