How to preserve custom locales across glibc-* updates?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux
    • 5.x
    • 6.x
    • 7.x
    • 8.x
    • 9.x
  • glibc
  • glibc-common

Issue

  • How to preserve custom locales across glibc-* updates?

  • Why does customized locale info disappear after updating glibc-*?

  • How to preserve custom locales after glibc-common re-install?

  • After updating glibc and dependent packages, some locale info is missing from the output of # locale -a.

       # localedef -f WINDOWS-31J -i ja_JP ja_JP.SJIS
    
       # locale -a | grep ja
       ja_JP
       ja_JP.eucjp
       ja_JP.sjis   <===  here it is.
       ja_JP.ujis
       ja_JP.utf8
       japanese
       japanese.euc
    
       # yum update glibc -y
       (..SNIP..)
    
       # locale -a | grep ja
       ja_JP
       ja_JP.eucjp
       ja_JP.ujis
       ja_JP.utf8
       japanese
       japanese.euc
    
         /*  ja_JP.sjis is missing  */
    

    Why does this happen? And should I define it again?

Resolution

  • Use the --no-archive option to add custom locales. This would create a subdirectory under in /usr/lib/locale for the new locales instead of adding it to the locale-archive /usr/lib/locale/locale-archive.

    --no-archive
               Do  not use the locale archive file, instead create outputpath as a subdirectory in the same directory as the locale archive file, and create separate output files for locale categories in it.
    
  • Example : To add a new locale tr_TR@SAP, below command should be used.

       # localedef --no-archive -f ISO-8859-9 -i tr_TR@SAP tr_TR@SAP
    
       # ls /usr/lib/locale/
       locale-archive  locale-archive.tmpl  tr_TR@SAP  <--==== 
    
       # ls /usr/lib/locale/tr_TR\@SAP/
       LC_ADDRESS  LC_COLLATE  LC_CTYPE  LC_IDENTIFICATION  LC_MEASUREMENT  LC_MESSAGES  LC_MONETARY  LC_NAME  LC_NUMERIC  LC_PAPER  LC_TELEPHONE  LC_TIME
    
       # locale -a | grep -i SAP
       tr_TR@SAP
    
  • How does this help?

    • An update or reinstall of glibc-common will not destroy the folder /usr/lib/locale/tr_TR@SAP. Therefore, the custom user locale will not be lost.
    • The build-locale-archive called in the %post install of next update of glibc-common will merge the folder into the locale-archive but will not delete the folder.
    • The locale-archive file will also contain the custom user locale tr_TR@SAP.
         # yum update glibc glibc-common
         Setting up Update Process
         (...)
    
         Complete!
    
         # locale -a | grep -i SAP
         tr_TR.iso88599@SAP
         tr_TR@SAP
    
         # ls /usr/lib/locale/
         locale-archive  locale-archive.tmpl  tr_TR@SAP
    
         # localedef --list-archive | grep -i SAP
         tr_TR.iso88599@SAP
         tr_TR@SAP
    
  • The locale folder needs to be kept on system to get it merged into locale-archive every time glibc-common is updated or reinstalled.

Root Cause

  • If installed without using --no-archive option, then the new locale is added to the archive /usr/lib/locale/locale-archive.
  • The next update of glibc-common will call /usr/sbin/build-locale-archive in the %post install script which will delete the existing locale-archive and create a new one from the /usr/lib/locale/locale-archive.tmpl file contained in the glibc-common rpm. Therefore, the custom user locale is lost after glibc-common update.

Diagnostic Steps

  • Add the custom locales using localedef command.

       # localedef -f ISO-8859-9 -i tr_TR@SAP tr_TR@SAP
    
       # locale -a | grep -i SAP
       tr_TR.iso88599@SAP
       tr_TR@SAP
    
       # localedef --list-archive | grep -i SAP
       tr_TR.iso88599@SAP
       tr_TR@SAP
    
  • Update glibc packages on system.

    # yum update glibc glibc-common nscd
    
  • Check for the locales after after update.

       # locale -a | grep -i SAP
       #
    
       # localedef --list-archive | grep -i SAP
       #
    
SBR
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.