Answer
If the binary returns "not found" or does not work after confirming the executable bit is set with chmod +x <filename>
, then you will need to create a symlink pointing to the system's interpreter. The file
tool will show the expected interpreter and architecture of a binary, readelf
is a lot more verbose and is used to discover the expected "sonames" of shared libraries. These utilities do not have to be used on the target system and is convenient to use on a common x86 Linux machine. These utilities can be installed on Ubuntu with sudo apt install binutils
.
Example output from the file command:
sterling_supplicant-arm-7.0.0.139/usr/sbin$ file wpa_supplicant
wpa_supplicant: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 3.0.0, stripped
Example output from the readelf command:
sterling_supplicant-arm-7.0.0.139/usr/sbin$ readelf -ld wpa_supplicant Elf file type is EXEC (Executable file)
Entry point 0xba28
There are 10 program headers, starting at offset 52 Program Headers:
...
<edited>
...
[Requesting program interpreter: /lib/ld-linux.so.3]
...
<edited>
...
Dynamic section at offset 0x176ee8 contains 30 entries:
Tag Type Name/Value
0x00000001 (NEEDED) Shared library: [librt.so.1]
0x00000001 (NEEDED) Shared library: [libnl-3.so.200]
0x00000001 (NEEDED) Shared library: [libnl-genl-3.so.200]
0x00000001 (NEEDED) Shared library: [libdl.so.2]
0x00000001 (NEEDED) Shared library: [libdbus-1.so.3]
0x00000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x00000001 (NEEDED) Shared library: [libc.so.6]
...
<edited>
...
To use this binary, we will have to confirm this symlink exists or create a new symlink pointing to the interpreter on the target filesystem:
cd /lib/
ls -l ld-*
-rwxr-xr-x 1 root root 158772 Dec 2 2019 /lib/ld-2.26.so
ln -sf ld-2.26.so ld-linux.so.3
ls -l ld-*
-rwxr-xr-x 1 root root 158772 Dec 2 2019 /lib/ld-2.26.so
lrwxrwxrwx 1 root root 10 Dec 21 18:55 /lib/ld-linux.so.3 -> ld-2.26.so
If the binary now reports that a library is not found when executed, repeat the steps shown above for creating a library symlink/soname pointing to it's real name. This may require you to use the find command to discover the location of the library. Example for libnl-genl-3:
find / -name 'libnl-genl-3*' -exec ls -l {} 2>/dev/null \;
-rwxr-xr-x 1 root root 18524 Feb 14 23:42 /usr/lib/libnl-genl-3.so.200.26.0
cd /usr/lib/
ln -sf libnl-genl-3.so.200.26.0 libnl-genl-3.so.200
ls -l libnl-genl-3*
-rwxr-xr-x 1 root root 18524 Feb 14 23:42 /usr/lib/libnl-genl-3.so.200.26.0
lrwxrwxrwx 1 root root 24 Feb 14 23:37 /usr/lib/libnl-genl-3.so.200 -> libnl-genl-3.so.200.26.0
If the library does not exist, you will have to include that package in your build. For instance if the above example libnl was missing, include the libnl package when building your filesystem.