Troubleshooting a Failed Gentoo Update - Preserved Libraries
- Posted:
2023-07-03
During a recent full @world set update (i.e., emerge --ask --verbose --update --deep --changed-use @world), the package "dev-libs/openssl" was upgraded from 1.1.1 to 3.0.9, along with its two library files, libcrypto and libssl, upgraded from "xxx.so.1.1" to "xxx.so.3". It supposed to be a typical system update, but upon completion, the command "emerge" alerted me that there were certain preserved libraries that required attention. The alert appeared every time I ran the command "emerge" thereafter.
What are preserved libraries?
Preserve-libs is a Portage feature that preserves libraries when sonames change during upgrade or downgrade, only as necessary to satisfy shared library dependencies of installed consumers. Preserved libraries are automatically removed when there are no remaining consumers, which occurs when consumer packages are rebuilt or uninstalled [1].
When listing all files from the newly installed OpenSSL package, the old version of the library files was also included, which was rather interesting:
$ equery files =dev-libs/openssl-3.0.9-r1 ... /usr/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.3 /usr/lib64/libssl.so.1.1 /usr/lib64/libssl.so.3 ...
Additionally, a special file "/var/lib/portage/preserved_libs_registry" keeps track of which files have been preserved and which packages they belong to:
$ cat /var/lib/portage/preserved_libs_registry { "dev-libs/openssl:0": [ "dev-libs/openssl-3.0.9-r1", "1067", [ "/usr/lib64/libcrypto.so.1.1", "/usr/lib64/libssl.so.1.1" ] ] }
It must have been some packages that still existed on my system and were linked against to the old library files - therefore, those libraries were preserved during the system update. To find out which packages were causing the problem and determin which emerge command could be used to solve the issue, use the tool "revdep-rebuild" from gentookit:
# revdep-rebuild --library /usr/lib64/libcrypto.so.1.1
Alternatively, there is a one-shot command that can address the issue:
# emerge --ask --verbose @preserved-rebuild
After some investigation, I found that Python 3.10.10 on my current system had been built against the old OpenSSL libraries, and was skipped during this system update. Executing the command above will rebuild it and upgrade it to version 3.10.12. Once that's done correctly, the package "dev-libs/openssl" will no longer include the old library files, and the file "/var/lib/portage/preserved_libs_registry" will be empty:
$ equery files =dev-libs/openssl-3.0.9-r1 ... /usr/lib64/libcrypto.so.3 /usr/lib64/libssl.so.3 ... $ cat /var/lib/portage/preserved_libs_registry {}
Conclusion
Sometimes, even doing a full @world set update, some packages might be skipped, which can unfortunately lead to the issue of preserved libraries. In my case, there were two major versions of Python on my system - Python 3.10 and Python 3.11 (both can coexist because of Gentoo's slotting feature [2]). During the system update, for some reason, Python 3.10 was skipped and only Python 3.11 was upgraded and rebuit against the new OpenSSL libraries. Normally, the issue of preserved libraries can be resolved automatically when old packages are uninstalled from the system, but in some cases it requires user involvement.
Thanks for reading :)