Executable is in current directory but can't be run [duplicate] - linux

This question already has answers here:
Executing 32 bit code under Ubundu 64 bit installation error- No such file or directory
(3 answers)
Closed 7 years ago.
I'm having a weird problem where I have an executable in a directory, but when I try to run it, bash says that it doesn't exist:
kiarashsadr#pandoras-box:~/Downloads/Tether/linux$ ls
adb run.sh
kiarashsadr#pandoras-box:~/Downloads/Tether/linux$ ls -l
total 1204
-rwxrwxr-x 1 kiarashsadr kiarashsadr 1226659 Mar 9 2013 adb
-rwxrwxr-x 1 kiarashsadr kiarashsadr 521 Oct 29 2012 run.sh
kiarashsadr#pandoras-box:~/Downloads/Tether/linux$ ./adb
bash: ./adb: No such file or directory
output from file:
kiarashsadr#pandoras-box:~/Downloads/Tether/linux$ file adb
adb: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.8, not stripped
wut??

You're trying to run a 32-bit executable on a 64-bit system. Bash doesn't differentiate between this case and "no such file or directory" case.
More about this topic: Executing 32 bit code under Ubundu 64 bit installation error- No such file or directory
More on how to run 32-bit executables on 64-bit systems: https://askubuntu.com/questions/454253/how-to-run-32-bit-app-in-ubuntu-64-bit

As stated by VOR73X, the reason in this case is that the file is a 32-bit executable on a 64-bit architecture. You can run it, but you need a compatibility layer to do so. If you have it:
mintaka:/home/lserni # file ansi
ansi: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.2.5, not stripped
mintaka:/home/lserni # uname -a
Linux mintaka 4.0.1-1-default #1 SMP Wed Apr 29 15:04:53 UTC 2015 (e3a374a) x86_64 x86_64 x86_64 GNU/Linux
mintaka:/home/lserni # ./ansi
Syntax: ansi [file|-]
...and otherwise you get 'no such file or directory'.
However, there might be other reasons to be unable to run a file that "seems" to be there (or even is).
Missing dynamic libraries would give a distinctive error (at least they do on my system, Linux OpenSuSE 13.2):
./test: error while loading shared libraries: libcap.so.2: cannot open shared object file: No such file or directory
Another possibility...
...is that the file is not named as you think it is. The file you asked for is really not there!
For example (using the same obsolete file as before)
mintaka:/home/lserni # mv ansi 'ansi '
mintaka:/home/lserni # ls -la ansi*
-rwxr-xr-x 1 root root 14268 Sep 17 23:29 ansi
The file seems to be there but its name now ends with a space, so as you would expect...
mintaka:/home/lserni # ./ansi
bash: ./ansi: No such file or directory
Of course if the file is called correctly, escaping the space...
mintaka:/home/lserni # ./ansi\
Syntax: ansi [file|-]
mintaka:/home/lserni #
Other tricks are possible (I did it to myself once by mistake and have seen some worm using this trick to hide from a casual 'ls'). For example UTF8 invisible characters.
Try
ls -la | hexdump -C
to verify that the name is indeed what it ought to be.

Related

What do device (character special) file sizes mean?

Using ls -l normally results in a long listing that includes the file size...
-rw-r--r--# 1 user1 staff 881344 Sep 1 15:35 someFile.png
On macOS 10.13.5, and Ubuntu 20.04, character special (device) file sizes are very different...
crw------- 1 root wheel 31, 0 Aug 30 16:11 autofs
In this case, what does the "31, 0" mean?
what does the "31, 0" mean?
It's the major/minor numbers of character device.
See these:
https://unix.stackexchange.com/questions/97676/how-to-find-the-driver-module-associated-with-a-device-on-linux
https://www.ibm.com/support/knowledgecenter/linuxonibm/com.ibm.linux.z.lgdd/lgdd_c_udev.html
Read carefully the documentation of ls(1) then about inode(7)
31 is a major device number, 0 is a minor device number.
Remember that ls(1) would use stat(2) (you might check using strace(1)...), so read Advanced Linux Programming then syscalls(2)
Sometimes, ls might be some shell alias or function. So read documentation of GNU bash. Try also /bin/ls --help
On GNU Linux, read documentation of coreutils. And it is free software, you could download and study its source code !
On MacOSX, the operating system kernel might have different system calls.
Be however aware of udev (on Linux).

"No such file or directory" error when running a dynamically-linked ARM executable

I am cross-compiling for an ARM embedded Linux platform running Ubuntu 15.04. Previous, statically-linked, versions of this program have run just fine. Recently I needed to link in libproprietary (lib name changed for this question), which is only available as an .so.
libproprietary.so works; I am able to run a different program that depends on it.
$ uname -a
Linux <hostname> 3.10.92-71 #1 SMP PREEMPT Fri Dec 18 00:38:54 BRST 2015 armv7l armv7l armv7l GNU/Linux
The problem:
$ ./myprogram
-bash: ./myprogram: No such file or directory
What I've tried:
$ ldd ./myprogram
libproprietary.so.2 => /usr/lib/libproprietary.so.2 (0xb6bbc000)
librt.so.1 => /lib/arm-linux-gnueabihf/librt.so.1 (0xb6ba6000)
libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xb6b92000)
libusb-1.0.so.0 => /lib/arm-linux-gnueabihf/libusb-1.0.so.0 (0xb6b72000)
libstdc++.so.6 => /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 (0xb6ab8000)
libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb6a43000)
libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6955000)
/usr/lib/ld.so.1 => /lib/ld-linux-armhf.so.3 (0xb6f28000)
libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xb692c000)
libudev.so.1 => /lib/arm-linux-gnueabihf/libudev.so.1 (0xb690f000)
$ file ./myprogram
./myprogram: ELF 32-bit LSB executable, ARM, EABI5 version 1 (GNU/Linux), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=881d76b2ce20f32aef95796b4fee9f01e492a7d2, not stripped
$ file /bin/ls
/bin/ls: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=a687c2baf9963c62c6abd209863d360dd0863686, stripped
$ readelf -l myprogram| grep interpreter
[Requesting program interpreter: /usr/lib/ld.so.1]
$ strace ./myprogram
execve("./myprogram", ["./myprogram"...], [/* 21 vars */]) = -1 ENOENT (No such file or directory)
write(2, "strace: exec: No such file or di"..., 40strace: exec: No such file or directory
) = 40
exit_group(1) = ?
+++ exited with 1 +++
$ ls -l myprogram
-rwxrwxr-x [details snipped]
$ file /usr/lib/libproprietary.so.<version>
/usr/lib/libproprietary.so.<version>: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, BuildID[sha1]=d9b4ba3b9ec03779792984bc8a89ceede5737455, stripped
It appears that the interpreter, /usr/lib/ld.so.1, does not exist. I'm going to guess that it should be similar to what /bin/ls is using:
$ readelf -l /bin/ls | grep interpreter
[Requesting program interpreter: /lib/ld-linux-armhf.so.3]
I don't know how to fix this in my link step however.
ccache arm-linux-gnueabihf-g++ -o myprogram -static -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -Wl,-no-undefined -pthread -Wl,-Bdynamic -lproprietary -Wl,-rpath-link=result/debug/lib -Wl,-rpath=\$ORIGIN/../../../../result/debug/lib variant-dir/debug/core-.o -Lresult/debug/lib -Wl,-Bstatic -l<other libs>
I did try moving -Wl,-Bdynamic -lproprietary after the core-.o word, but that didn't change anything.
It appears that the interpreter, /usr/lib/ld.so.1, does not exist. I'm going to guess that it should be similar to what /bin/ls is using:
Correct. You could change the interpreter by adding -Wl,--dynamic-linker=/lib/ld-linux-armhf.so.3 flag at link time.
However,
Your toolchain may be targeting a different version of libc from the one you actually have installed (in which case the program will likely crash).
If it is targeting correct libc, then your toolchain is mis-configured.

Check Which operating system is installed ( CentOS, Ubuntu, Redhat, ... etc)

I have been given a server with OS installed. I want to check which Operating system is installed in it. I have used uname -a with ouput of
Linux ctl 2.6.32-573.3.1.el6.x86_64 #1 SMP Mon Aug 10 09:44:54 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux
Any suggestions ?
You could use the /etc/os-release file, which contains information on the os using the freedesktop spec.
Printing out just the OS name and version:
awk -F '=' '/PRETTY_NAME/ { print $2 }' /etc/os-release
Using os-release file available in Linux:
cat /etc/os-release
on many OS's, you can get the os via:
lsb_release -d
The el6 in the kernel version could indicate a RedHat (thus Fedora as well), Oracle, Centos, Scientific Linux. Potentially others as well.
At least on some of these systems (others as well) the distribution can be identified from the /etc/issue* files. For example:
> ls -la /etc/issue*
-rw-r--r-- 1 root root 57 Oct 22 2014 /etc/issue
-rw-r--r-- 1 root root 55 Oct 22 2014 /etc/issue.net
> cat /etc/issue
Welcome to openSUSE 13.2 "Harlequin" - Kernel \r (\l).
you can try this command to check all detail related to operating system version:
cat /etc/*elease

how the gcc -llibname and the OS find lib path?

I had symbolic link to the target libs:
~/opt/OpenBLAS/lib $ ls -al
total 0
drwxrwxr-x 2 user user 59 Jul 9 13:03 .
drwxrwxr-x 5 user user 147 Jul 9 12:48 ..
lrwxrwxrwx 1 user user 64 Jul 9 13:03 libopenblas.a -> ../openBLAS_v0.2.9df/lib/libopenblas_df029_sandybridgep-r0.2.9.a
lrwxrwxrwx 1 user user 65 Jul 9 13:03 libopenblas.so -> ../openBLAS_v0.2.9df/lib/libopenblas_df029_sandybridgep-r0.2.9.so
$ echo $LD_LIBRARY_PATH
/home/user/opt/OpenBLAS/lib
Then the gcc has following args:
-L/home/user/opt/OpenBLAS/lib -lopenblas
however, after compiling, run the command it always throws out error:
error while loading shared libraries: libopenblas_df029.so.0: cannot open shared object file: No such file or directory
If I create a symbolic link libopenblas_df029.so.0 under the /home/user/opt/OpenBLAS/lib, it will then work.
Can anyone explain to me why this is happening and how can I change the behaviour?
Does this mean the libopenblas contain some suffix and the OS always append this suffix when trying to find lib file?
I think, your library "libopenblas_df029_sandybridgep-r0.2.9.so" is compiled with "-soname" switch
something like:
gcc -shared -Wl,-soname,libopenblas_df029.so.0 source.c -o libopenblas_df029_sandybridgep-r0.2.9.so
When you link against such library, your executable tries to find library by name "libopenblas_df029.so.0" ( i.e. whatever name you specified in -soname switch )
The best way to find if this is true is to run following command and look for "SONAME"
readelf -d <shared_object> | head -10
Like #Icarus3 said, the linked executable contains the name of the library as it wants to be called (the SONAME).
There should be a symbolic link from that name to the actual shared library. If it is missing, the library is not properly installed -- usually it is a sign that you need to run ldconfig to update the symbolic links and the dynamic linker cache.

How to edit FreeBSD .gz bootfile?

I have virtual image of a FreeBSD system and when I mount it I don't see the /etc/ directory and other files, instead is a big loader.gz on the filesystem, that I believe that is extracted during the boot process. I decompressed the loader.gz with gzip and I got it:
$ file loader
loader: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), dynamically linked (uses shared libs), not stripped
Using grep I'm able to confirm that the files that I need to edit are inside, however I don't know how to edit it. I tried to mount it without success. How can I modify the contents of loader.gz and use it again?
Can you please give me an example?
I have a Linux system and a Mac to install tools and this FreeBSD image.
Please, help me.
The loader program is generally the last stage of the kernel bootstrapping process.
A recent image should have another signature. e.g. for a memory stick image;
> file tmp/FreeBSD-10.0-RELEASE-amd64-memstick.img
tmp/FreeBSD-10.0-RELEASE-amd64-memstick.img: Unix Fast File system
[v1] (little-endian), last mounted on ,
last written at Fri Jan 17 00:24:02 2014,
clean flag 1, number of blocks 681040, number of data blocks 679047,
number of cylinder groups 13, block size 8192, fragment size 1024,
minimum percentage of free blocks 8, rotational delay 0ms,
disk rotational speed 60rps, TIME optimization
Mounting an image on FreeBSD:
# mdconfig -a -t vnode -f tmp/FreeBSD-10.0-RELEASE-amd64-memstick.img -u 1
# mount /dev/md1a /mnt/root/
(Linux has the same capability, I just don't remember what its called.)
This image contains loader in the boot/ directory:
# ls /mnt/root/
.cshrc ERRATA.TXT README.TXT boot/ lib/ proc/ sys#
.profile HARDWARE.HTM RELNOTES.HTM dev/ libexec/ rescue/ tmp/
COPYRIGHT HARDWARE.TXT RELNOTES.TXT docbook.css media/ root/ usr/
ERRATA.HTM README.HTM bin/ etc/ mnt/ sbin/ var/
# ls /mnt/root/boot/
beastie.4th check-password.4th gptzfsboot menu.4th support.4th
boot color.4th kernel/ menu.rc userboot.so
boot0 defaults/ loader* menusets.4th version.4th
boot0sio delay.4th loader.4th modules/ zfs/
boot1 device.hints loader.help pmbr zfsboot
boot2 firmware/ loader.rc pxeboot zfsloader*
brand.4th frames.4th mbr screen.4th
cdboot gptboot menu-commands.4th shortcuts.4th
On my FreeBSD 10 system, loader has another signature;
/boot/loader: FreeBSD/i386 demand paged executable

Resources