1

I am building a small embedded system for a x86_64 target, with a Linux kernel and an initramfs which contains a dynamically linked busybox.

I tried to install the needed libraries (libm.so.6, libc.so.6) into /lib and the linker ld-linux-x86-64.so.2 into /lib64( because the busybox binary request it at this place).

lib
├── libc.so.6
└── libm.so.6
lib64
└── ld-linux-x86-64.so.2

but it failed to link:

/sbin/init: error while loading shared libraries: libm.so.6: cannot open shared object file: No such file or directory

I managed to make it work by moving everything in /lib64:

lib64
├── ld-linux-x86-64.so.2
├── libc.so.6
└── libm.so.6

or by creating a symlink between /lib and /lib64

lib
├── ld-linux-x86-64.so.2
├── libc.so.6
└── libm.so.6
lib64 -> lib

But I still don't understand why the first configuration do not work. Why the linker is not able to find libraries in /lib ?

EDIT: To make it working properly (Thanks to yaegashi):

  • Go into your initramfs root directory.
  • Create a file /etc/ld.so.conf with the library path you need.

    echo /lib > etc/ld.so.conf

  • Generate your ld.so.cache file.

    ldconfig -r .

  • Re generate your initramfs. It's done
2

Read the manual of ld.so (the dynamic linker/loader). The actual search paths are mainly determined by /etc/ld.so.cache (which is compiled from /etc/ld.so.conf by ldconfig) or built-in paths in your ld.so binary. So check your platform configurations and how you built your glibc.

You can watch detailed activities of ld.so by running any binary with LD_DEBUG=libs set in the environment variable.

$ LD_DEBUG=libs ls
     17441: find library=libselinux.so.1 [0]; searching
     17441:  search cache=/etc/ld.so.cache
     17441:   trying file=/lib/x86_64-linux-gnu/libselinux.so.1
     17441: 
     17441: find library=libacl.so.1 [0]; searching
     17441:  search cache=/etc/ld.so.cache
     17441:   trying file=/lib/x86_64-linux-gnu/libacl.so.1
     17441: 
     17441: find library=libc.so.6 [0]; searching
     17441:  search cache=/etc/ld.so.cache
     17441:   trying file=/lib/x86_64-linux-gnu/libc.so.6
     ...
  • 1
    The ld.so.cache made it working and is the clean solution I expected. See my edit for the file creation steps. – jml Jun 1 '15 at 9:36
0

As a quick fix, add lib to the shell environment variable LD_LIBRARY_PATH via .bashrc,

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib

and then,

source /home/user/.bashrc
  • 1
    Inapplicable to OP's situation. Do you ever run /sbin/init from a user shell? – yaegashi May 31 '15 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.