Skip to content

Instantly share code, notes, and snippets.

@japm48
Created January 17, 2016 11:45
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save japm48/f1148b215e8b17f58585 to your computer and use it in GitHub Desktop.
Save japm48/f1148b215e8b17f58585 to your computer and use it in GitHub Desktop.
CoreOS: enable UTF8 with a provisional (ugly) workaround
  1. First, you need a Linux distro with a functional UTF-8 locale (i.e. NOT CoreOS).

    Execute my_gen_locale.sh to generate a valid locale-archive by copying a locale from the system. It will use en_US.UTF-8, but can be changed if deemed necessary (the list of locales can be found in glibc sources: https://sourceware.org/git/?p=glibc.git;a=blob;f=localedata/SUPPORTED ).

  2. Now the /usr partition must be edited to install it.

    Apparently this is quite discouraged by the devs, but I still don't know how to create a new CoreOS image and have managed to remove the "protection" flags in the partition (see https://goo.gl/zHz8l2 , for the source of util.sh).

    DON'T USE THIS IN SOMETHING IMPORTANT AS IT CAN CORRUPT YOUR VM FILESYSTEM.

    It depends on the installation type, but once you manage to mount the disk image (NOT the partition) you just have to execute:

    # source util.sh
    # enable_rw_mount /dev/my_third_partion
    

    And now you will be able to mount and modify the partition.

  3. Copy locale-archive to the machine's /usr/lib/locale/ (i.e. usr_mountpoint/lib/locale/), and chown root usr_mountpoint/lib/locale/

  4. Unmount the partition, turn on the VM and log into it from SSH. Copy localectl_set.sh and execute it. It will configure systemd (localectl) and bash (/etc/profile.d) to default to the new locale. Unfortunately this won't probably work in other shells (like zsh), and the method used by e.g. Debian won't work here because PAM is not supported in CoreOS.

  5. sudo reboot and hopefully you now will no longer fear pressing a non-US key.

#Execute inside CoreOS after installing /usr/lib/locale/locale-archive
sudo localectl set-locale LANG=en_US.utf8
#Extracted from ArchLinux:
cat <<'EOF' | sudo tee /etc/profile.d/locale.sh > /dev/null
#!/bin/sh
if [ -z "$LANG" ]; then
if [ -r /etc/locale.conf ]; then
. /etc/locale.conf
fi
fi
LANG=${LANG:-C}
export LANG
[ -n "$LC_CTYPE" ] && export LC_CTYPE
[ -n "$LC_NUMERIC" ] && export LC_NUMERIC
[ -n "$LC_TIME" ] && export LC_TIME
[ -n "$LC_COLLATE" ] && export LC_COLLATE
[ -n "$LC_MONETARY" ] && export LC_MONETARY
[ -n "$LC_MESSAGES" ] && export LC_MESSAGES
[ -n "$LC_PAPER" ] && export LC_PAPER
[ -n "$LC_NAME" ] && export LC_NAME
[ -n "$LC_ADDRESS" ] && export LC_ADDRESS
[ -n "$LC_TELEPHONE" ] && export LC_TELEPHONE
[ -n "$LC_MEASUREMENT" ] && export LC_MEASUREMENT
[ -n "$LC_IDENTIFICATION" ] && export LC_IDENTIFICATION
EOF
# Inspired by ArchLinux's locale-gen
# See: https://projects.archlinux.org/svntogit/packages.git/tree/trunk?h=packages/glibc
locale=en_US.UTF-8
charset=UTF-8
if [ -n "$POSIXLY_CORRECT" ]; then
unset POSIXLY_CORRECT
fi
cd `dirname $0`
if [ -f $LOCALES/$locale ]; then
input=$locale;
else
input=`echo $locale | sed 's/\([^.]*\)[^@]*\(.*\)/\1\2/'`;
fi;
mkdir -p ./usr/lib/locale/
localedef -i $input -c -f $charset --prefix=$PWD $locale
mv ./usr/lib/locale/locale-archive .
rm -r ./usr
echo "Now copy locale-archive to /usr/lib/locale/"
echo "and chown to root."
# Imported from https://chromium.googlesource.com/chromiumos/platform/crosutils/+/ea621903e927acf77889bcda4fa71636f4af7158/common.sh#458
disable_rw_mount() {
local rootfs="$1"
local offset="${2-0}" # in bytes
local ro_compat_offset=$((0x464 + 3)) # Set 'highest' byte
printf '\377' |
sudo dd of="$rootfs" seek=$((offset + ro_compat_offset)) \
conv=notrunc count=1 bs=1
}
enable_rw_mount() {
local rootfs="$1"
local offset="${2-0}"
local ro_compat_offset=$((0x464 + 3)) # Set 'highest' byte
printf '\000' |
sudo dd of="$rootfs" seek=$((offset + ro_compat_offset)) \
conv=notrunc count=1 bs=1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment