Bug 11777 - systemd ldconfig.service: always re-generates ld.so.cache (?) and fails on read-only rootfs
Summary: systemd ldconfig.service: always re-generates ld.so.cache (?) and fails on re...
Status: RESOLVED WORKSFORME
Alias: None
Product: OE-Core
Classification: Build System, Metadata & Runtime
Component: core (show other bugs)
Version: unspecified
Hardware: x86 Multiple
: Medium normal
Target Milestone: 3.4
Assignee: Richard Purdie
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2017-07-10 19:31 UTC by Patrick Ohly
Modified: 2021-09-28 16:52 UTC (History)
6 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: No (bug/feature does not impact docs)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Ohly 2017-07-10 19:31:35 UTC
When booting into a read-only image with systemd as init system, ldconfig.service fails with:

Jul 10 19:00:39 intel-corei7-64 ldconfig[461]: /sbin/ldconfig: Can't create temporary cache file /etc/ld.so.cache~: Read-only file system
Jul 10 19:00:39 intel-corei7-64 systemd[1]: [[0;1;39mldconfig.service: Main process exited, code=exited, status=1/FAILURE[[0m
Jul 10 19:00:39 intel-corei7-64 systemd[1]: [[0;1;31mFailed to start Rebuild Dynamic Linker Cache.[[0m
Jul 10 19:00:39 intel-corei7-64 systemd[1]: [[0;1;39mldconfig.service: Unit entered failed state.[[0m
Jul 10 19:00:39 intel-corei7-64 systemd[1]: [[0;1;39mldconfig.service: Failed with result 'exit-code'.[[0m

I think (but haven't checked again) that ld.so.cache also gets re-generated unnecessarily when booting into a read/write image.

Avoiding unnecessary re-generation might be the right solution. However, I don't know how one would check the "unnecessary" part. If that can't be done, then the situation might have to stay the same for read/write (always re-generate) and for read-only the service needs to be disabled.

Can be reproduced with refkit-image-installer under qemu. See also bug #11776, which affects the same configuration.
Comment 1 Ross Burton 2017-09-05 13:31:12 UTC
Would this be solved by this which just landed into master:

    initramfs-live-boot: disable systemd-update-done.service on live images
Comment 2 Patrick Ohly 2018-01-17 14:57:10 UTC
(In reply to comment #1)
> Would this be solved by this which just landed into master:
> 
>     initramfs-live-boot: disable systemd-update-done.service on live images

No, that only solves the issue for an initramfs that uses init-live.sh.

It is not solved for a normal read-only rootfs, not does it address the "ld.so.cache also gets re-generated unnecessarily when booting into a read/write image" part.

But probably the technique used in that patch can be generalized also for the other scenarios.
Comment 3 Ross Burton 2018-01-18 20:08:33 UTC
Maxin, can you take this?
Comment 4 Maxin B. John 2018-01-18 21:09:09 UTC
(In reply to comment #3)
> Maxin, can you take this?

Sure.
Comment 5 Juro Bystricky 2018-03-22 09:41:20 UTC
(In reply to comment #0)

> 
> I think (but haven't checked again) that ld.so.cache also gets re-generated
> unnecessarily when booting into a read/write image.
> 

This has been puzzling me for a while, looking at the source code of ldconfig

https://github.com/lattera/glibc/blob/master/elf/ldconfig.c

We can see the the cache file contains directory entries. So I don't understand how you can actually "cross-compile" a cache file, as the directory entries reflect the build host machine. So the way I understand this, a cross-compiled ld.so.cache needs to re-generate right away, as all entries are originally invalid, originating from the build host.
Comment 6 Kai Kang 2019-01-08 03:20:09 UTC
Can't reproduce. ldconfig.service not even to start because start condition is not met.

root@qemux86-64:~# touch /abc
touch: /abc: Read-only file system
root@qemux86-64:~#
root@qemux86-64:~# systemctl status ldconfig| more                                                                                                        
● ldconfig.service - Rebuild Dynamic Linker Cache
   Loaded: loaded (/lib/systemd/system/ldconfig.service; static; vendor preset: enabled)                                                                  
   Active: inactive (dead)
Condition: start condition failed at Tue 2019-01-08 03:05:36 UTC; 5min ago
           ├─ ConditionNeedsUpdate=|/etc was not met
           └─ ConditionFileNotEmpty=|!/etc/ld.so.cache was not met
     Docs: man:ldconfig(8)


Patrick, did you have extra configure?
Comment 7 Rasmus Pedersen 2020-01-20 14:30:34 UTC
(In reply to comment #6)
> Can't reproduce. ldconfig.service not even to start because start condition
> is not met.
> 
> root@qemux86-64:~# touch /abc
> touch: /abc: Read-only file system
> root@qemux86-64:~#
> root@qemux86-64:~# systemctl status ldconfig| more                          
> 
> ● ldconfig.service - Rebuild Dynamic Linker Cache
>    Loaded: loaded (/lib/systemd/system/ldconfig.service; static; vendor
> preset: enabled)                                                            
> 
>    Active: inactive (dead)
> Condition: start condition failed at Tue 2019-01-08 03:05:36 UTC; 5min ago
>            ├─ ConditionNeedsUpdate=|/etc was not met
>            └─ ConditionFileNotEmpty=|!/etc/ld.so.cache was not met
>      Docs: man:ldconfig(8)
> 
> 
> Patrick, did you have extra configure?

Hi

I just ran into this issue.
We get the same error as OP.

We have a bb file adding a symlink like so:
ln -s /var/run/ld.so.cache ${D}${sysconfdir}/ld.so.cache
Comment 8 Richard Purdie 2021-09-28 16:52:34 UTC
I built a systemd image (core-image-sato) and agree this seems to work fine for me:

root@qemux86-64:~# systemctl status ldconfig
○ ldconfig.service - Rebuild Dynamic Linker Cache
     Loaded: loaded (/lib/systemd/system/ldconfig.service; static)
     Active: inactive (dead)
  Condition: start condition failed at Tue 2021-09-28 16:41:57 UTC; 2min 49s ago
             ├─ ConditionNeedsUpdate=|/etc was not met
             └─ ConditionFileNotEmpty=|!/etc/ld.so.cache was not met

with ldconfig -p showing cache entries which seem to match the system.