How do I reduce the size of locale-archive?

I have a need to reduce the size of the locale-archive file on some of my RHEL6 systems.

Here is that file on my system:

[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="01736e6e75412c6564772c313136">[email protected]</a> locale]# ls -l
total 96800
-rw-r--r--. 1 root root 99158704 Sep  9 15:22 locale-archive
-rw-r--r--. 1 root root        0 Jun 20  2012 locale-archive.tmpl

So I did this …
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="50223f3f24107d3435267d606067">[email protected]</a> locale]# localedef --list | grep zh_CN
zh_CN
zh_CN.gb18030
zh_CN.gb2312
zh_CN.gbk
zh_CN.utf8

… so I figured I could get rid of zh_CN like so …
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="89fbe6e6fdc9a4edecffa4b9b9be">[email protected]</a> locale]# localedef --delete-from-archive zh_CN

… and I can see zh_CN does not get listed anymore like so …
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d9abb6b6ad99f4bdbcaff4e9e9ee">[email protected]</a> locale]# localedef --list | grep zh_CN
zh_CN.gb18030
zh_CN.gb2312
zh_CN.gbk
zh_CN.utf8

… but the size of the locale-archive does not get smaller …
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="582a37372c18753c3d2e7568686f">[email protected]</a> locale]# ls -l  
total 96800
-rw-r--r--. 1 root root 99158704 Sep  9 17:16 locale-archive
-rw-r--r--. 1 root root        0 Jun 20  2012 locale-archive.tmpl

… is there something else I need to do?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can first remove all unneeded locales by doing:

$localedef --list-archive | grep -v -i ^en | xargs localedef --delete-from-archive

Where ^en can be replaced by the locale you wish to keep

Then

$build-locale-archive

If this gives you an error similar to
$build-locale-archive
/usr/sbin/build-locale-archive: cannot read archive header

Then try this
$mv /usr/lib/locale/locale-archive /usr/lib/locale/locale-archive.tmpl
$build-locale-archive

If that still fails, check your version. According to this page newer versions don’t have the necessary files to rebuild the archive in order to save space. You’ll need to run
yum reinstall glibc-common

In later releases of Red Hat Enterprise Linux, you may use dnf, a similar application.

Method 2

On Amazon Linux

  1. Delete the unused archives from the locale-archive. This command deletes all except the ones beginning with en.
    localedef --delete-from-archive $(localedef --list-archive | grep -v -i ^en | xargs)
  2. Copy the locale-archive (with removed locales) file to be the new locale-archive.tmpl file
    cp /usr/lib/locale/locale-archive /usr/lib/locale/locale-archive.tmpl
  3. Run build-locale-archive
    build-locale-archive

Note: If you run build-locale-archive it zeros out the .tmpl file after each run and when you run it again you will see the error:

build-locale-archive: cannot read archive header

You can get a copy of the locale-archive.tmpl file either by copying the current locale-archive to locale-archive.tmpl or by downloading and unpacking glibc-common. If you use the default locale-archive.tmpl file from the glibc-common RPM and run build-locale-archive against it, it will create a full (~102MB) locale-archive. You need to repeat the above steps to get the smaller size archive.

In the above case deleting all locales except the en_* ones my locale-archive went from 102MB down to 3.4MB


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments