Cannot execute binary files linux

How can I resolve the error «cannot execute binary file»?

PATH is an environment variable which contains a list of folders which the shell searches for programs. ls for example, usually refers to /bin/ls , and your shell finds it by going through the folders listed in PATH one-by-one until it finds it, or if it doesn’t find it in any of them, it gives up. I suppose a better starting point would be, what is the output of echo $PATH ? (edit: the export command is a way to define an environment variable in bash.)

Ah. I warned you not to shut the system down 😛 Can you get console access to it (physical monitor+keyboard attached)? Try booting the system in single-user mode (might be labelled as recovery mode) and see if you can get to a root shell.

@David you won’t see any output after typing export PATH=/bin:/user/bin:/sbin:/usr/sbin . It’s a silent command.

7 Answers 7

Usually that error message means Linux doesn’t recognize the file as a shell script or as an executable file.

Typically the cause is running an executable on the wrong architecture — if you try to run x86 executables on an ARM CPU, this message comes up.

Did /usr/bin/id get overwritten, possibly?

«if you try to run x86 executables on an ARM CPU, this message comes up.» That was EXACTLY what caused it. Thanks everyone for your inputs!

How can we solve this? I am sure i get the same issue, but this answer does not really tell me a solution : /

To resolve, you need to use an ARM binary and not an x86 binary. If the source is available, you can recompile/rebuild under an ARM system. If the source is not available, check with the vendor for an ARM binary. The official JRE from Sun, for example, has both x86 and «embedded» or ARM versions. You have to use the ARM version.

Try to run it using ./executablefilename instead of using sh executablefilename. It’s not a shell script after all.

I had this problem when trying to run kiwix-serve on my raspberry pi. My overall solution I believe was to adjust the file permissions (it was not set to executable by anyone by default) and then ran it as ./kiwix-serve

The problem is running a binary for a different processor architecture. You can use objdump (from binutils) to check architecture of binaries. You can use uname to check architecture of a machine.

e.g. I encountered this error «cannot execute binary file» when installing FF.Communicator — a firefox plugin for chrome (so I can run pages that use java applets).

$ ./FF.Communicator bash: ./FF.Communicator: cannot execute binary file $ uname -mpio i686 i686 i386 GNU/Linux $ objdump -a ./FF.Communicator ./FF.Communicator: file format elf64-x86-64 ./FF.Communicator 
$ objdump -a /bin/ls /bin/ls: file format elf32-i386 

Using these tools you can check architectures of machines and binaries — not just intel architectures but any processor.

Читайте также:  Intel network drivers linux

For Mac OSX users, you can find out the architecture info of a specific file using the «file» command:

I’m making some wild guesses here, but it looks like the following is happening:

  1. You log in over SSH, triggering bash to run your ~/.profile or ~/.bashrc to set up your environment for you (this is normal).
  2. At some point it tries to execute /bin/id to get your uid, which fails, causing integer expression error, and terminating the script before it can set up your $PATH .
  3. Because your $PATH is not set, bash is only able to run commands with the full path specified.

Use export PATH=/bin:/usr/bin:/sbin:/usr/sbin to fix the $PATH issue until you can fix the root cause of /bin/id failing.

This means that you are trying to execute a binary file using your bash script which is not intended to be run as you trying it to be. It is already a binary file and you are trying your $SHELL to parse and run it.

in a very simple example, if you try to run `w’ command like

$ bash w /usr/bin/w: /usr/bin/w: cannot execute binary file 

similarly you might be hitting the same method or as it looks from your code snippet.

While , for the remaining for your commands, Al these halt, shutdown , reboot etc commands are the root owned commands and need super-user prilveges to run and perform the required operation. normal users can’t run them another explanation is that these commands are placed at /sbin/ and /usr/sbin , which might not be in your $PATH variable ( which is used to validate commands in your custody )

Источник

Решение проблемы с ошибкой «bash: не удаётся запустить бинарный файл: Ошибка формата выполняемого файла»

В операционной системе Linux при запуске скаченного файла, либо при запуске самостоятельно скомпилированного файла вы можете столкнуться с ошибкой:

bash: /путь/до/файла: не удаётся запустить бинарный файл: Ошибка формата выполняемого файла

Если у вас англоязычная локаль, то ошибка будет примерно такой:

bash: ./program: cannot execute binary file: Exec format error

В самой ошибке вместо /путь/до/файла и ./program будет указан путь до файла программы, который вы хотите запустить.

Причинами данной ошибки могут быть:

  • попытка запустить 64-битный файл на 32-битной системе
  • файл скомпилирован для другой архитектуры (например, для ARM, а вы пытаетесь запустить его на ПК)
  • вы пытаетесь выполнить не исполнимый файл, а ссылку
  • файл размещён в совместной (shared) папке

Чтобы получить информацию о файле, который вы пытаетесь запустить, можно использовать утилиту file, после которой укажите путь до файла:

program: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=03ada11d91d298913990bfc074ccc3a380d26b69, with debug_info, not stripped

Здесь мы видим, что файл предназначен для 64-битной системы, об этом говорит запись 64-bit, для процессора с архитектурой x86-64.

program: ELF-32-bit LSB executable, ARM, EABI4 version 1 (SYSV), dynamically linked(uses share libs), for GNU/LINUX 2.6.16, not stripped

Этот файл для 32-битных систем, для процессора с архитектурой ARM EABI4.

Читайте также:  Лицензионное соглашение linux mint

Если вы не знаете, какой битности ваша система, то выполните команду:

Для 64-битных систем будет выведено x86_64, а для 32-битных – x86.

О разрядности дистрибутивов Linux и о программ

На компьютер с 32-битным процессором вы можете установить только 32-битную операционную систему и в ней запускать только 32-битные программы.

На компьютер с 64-битным процессором вы можете установить как 64-битную ОС, так и 32-битный Linux. В случае, если вы установили 64-битный дистрибутив Linux, то в нём вы можете запускать и 64-битные программы и 32-битные. А если вы установили 32-битный дистрибутив, то в нём возможно запускать только 32-битные программы.

Итак, если у вас 32-битная система, а файл для 64-битной системы или даже для ARM архитектуры, то у вас следующие варианты:

  • скачать файл подходящей для вас битности и архитектуры
  • если вы самостоятельно компилировали файл из исходного кода, то заново скомпилируйте для процессора вашей архитектуры

Запуск ARM файлов в Linux

Часто можно запустить исполнимые образы ARM на amd64 системах если установить пакеты binfmt-support, qemu, и qemu-user-static:

sudo apt install binfmt-support qemu qemu-user-static

Заключение

Итак, ошибка формата выполняемого файла с невозможностью запустить бинарный файл возникает из-за несоответствия программы операционной системе или архитектуре процессора. Эта проблема не должна возникать, если вы установили программу из исходных репозиториев (кроме случаев неправильной настройки источников репозитория). При возникновении этой проблемы поищите файл, подходящий для вашей архитектуры или скомпилируйте файл из исходных кодов под архитектуру вашей операционной системы.

Связанные статьи:

Источник

Bash: ./filename : Cannot execute binary file

Please type file um.exe or file um (whichever is the name of your binary file). However, likely the generated binaries are for one reason or other Windows binaries. Also, if the program is public, you can post the link to the sources. Or just post the makefile here.

7 Answers 7

As you can see from the output of file um that you posted in a comment, your binary is a 64-bit binary.

32 bit systems cannot run 64 bit binaries, it only works the other way around.

This is the most common reason I’ve seen for this problem, using file will identify this quite quickly.

@JohnMerlino Either provide Hardware with the correct instruction set and a OS which enable it (AMD64 Hardware and OS for AMD64 Programs). or simulate/emulate/virtualize it (Virtual Box/JVM/. ) or get a version for your instruction set. You can not run Software for other Instruction set as native Programs.

Another solution for people who are having this problem except the part about unmatched bits is that running the file without the command «bash».

Just use chmod +x ‘path to the file’ and then run ‘the path to the file’ in terminal.This is how I solved my problem.

For Googlers:

  • 32-bit or 64-bit? Check with file yourbinary
  • Permission to execute? Do chmod +x yourbinary
  • Path correct? Do ./yourbinary
Читайте также:  Невозможно получить доступ linux

Try making the file executable

But if this is a exe file compiled for Windows, you probably need to install Wine.

Another possible source of this error: trying to run a Linux binary executable on a Mac, or vice versa.

For instance, trying to run the true binary from my Mac on an Ubuntu box that I SCPed it to:

$ ./mactrue -bash: ./mactrue: cannot execute binary file: Exec format error 

If you’ve downloaded a binary and executing it fails with this error, check if you’ve downloaded the version for the wrong OS.

For me, copying the binary into Applications on my Mac then into my Path messed it up on my Mac. I’m pretty sure the Applications folder turned the binary into an Alias instead of an actual binary.

-bash: /usr/local/bin/terraform: cannot execute binary file mike$ file /usr/local/bin/terraform /usr/local/bin/terraform: MacOS Alias file 

I unzipped the binary from my Downloads again and just mv ed it to my Path and it worked fine.

mike$ file /usr/local/bin/terraform /usr/local/bin/terraform: Mach-O 64-bit executable x86_64 

Источник

Cannot execute binary file error

According to su ‘s documentation ( info coreutils ‘su invocation’ ), it will by default execute a shell, and the arguments to su are passed as arguments to the shell.

The implication is simply this: su is doing in essence: /bin/sh *arguments_to_su* but it does it as another user (the «effective user id»). that’s all. So

su - jetty sh ./runprogram.sh 
(become the user jetty via login or su) /bin/sh sh ./runprogram.sh 

. and the shell will report an error, because the first /bin/sh , called by su , is trying to run the program sh as a shell script, with ./runprogram.sh as its argument. But sh itself is not a shell script, it is a binary (whose job it is is to run shell scripts).

if you were to simply do this:

Then the su command will call /bin/sh with the program ./runprogram.sh as its argument, and jetty as the effective user id, and all should be well. . SHOULD be well, because since you are doing an su — you are making the shell a login shell and changing to the user’s home directory. If runprogram.sh is not in the home directory, you will get an error.

This is why, also, you cannot run for example run a cp command by simply:

. because, again, after su changes effective user id to jetty it will try this:

. and cp is not a shell script. But the -c option works in this case; because you are telling su that you want to run /bin/sh with the -c option to the shell:

su - jetty -c "cp file1 file2" 

does the job. Note that you must quote the command, because the entire string is passed to the shell and (I believe) any following arguments are ignored.

Finally, the previous poster’s answer doesn’t work for me on Linux, it requires the entire command string to be quoted.

Источник

Оцените статью
Adblock
detector