Cannot execute binary file bash 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.

Читайте также:  Linux device read only

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.

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

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

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

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

Читайте также:  Virtualbox linux no sound

На компьютер с 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

Заключение

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

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

Источник

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.

Источник

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

How can I fix this? I’m using Ubuntu 14.04.2 (amd64) with VMware. I also tried using Ubuntu i386, but the result was the same.

Читайте также:  Linux узнать версию openssl

It’s an ARM executable, i.e. you downloaded the wrong executable format or compiled for the wrong platform. You have to get the right executable or recompile.

9 Answers 9

You’re trying to run an executable compiled for an ARM architecture on an x86-64 architecture, which is much like asking your processor who only speaks English to take directions in Chinese.

If you need to run that executable you have two choices:

  1. Get an x86-64 version of the executable (by any mean; if you’re unable to get an x86-64 version of the executable but you’re able to get its source code, you can try to recompile it on the virtual machine);
  2. Install Ubuntu Server for ARM in place of Ubuntu 14.04.2 (amd64). This requires either a physical machine running on an ARM architecture or a virtualization software that can emulate it.

While the answer seems to be full-fledge, I tried to speak to my processor in English, but it arrogantly ignores me and doesn’t reply anything 🙁

This can also occur if you attempt to run an x86-64 executable on a 32-bit platform.

In one specific instance, I downloaded Visual Studio Code and tried to run it on my Ubuntu installation, but I hadn’t realized that I had installed 32-bit Ubuntu in this VM. I got this error, but after downloading the 32-bit version, it ran without issue.

It is often possible to run an ARM executable image on an amd64 system if you install the binfmt-support , qemu , and qemu-user-static packages:

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

qemu will then perform syscall emulation when you run the executable. This works for most ARM binaries but there are a few that may not run correctly.

After install, was able to execute with /usr/bin/arm-linux-gnueabi-gcc -mfpu=neon -mcpu=cortex-a9 -mfloat-abi=softfp main.c -static

Such error may occur if all of the following are true:

  • Executable is not a file but a link
  • You run run it inside VM
  • File is located in shared folder
  • Your host is Windows.

If you got that file, let’s say, in archive — try to unpack it inside VM, in some directory inside virtual drive, not folder mapped to your host machine hard drive, for example /myNewDir/

That’s pretty helpful. For me, I created a shortcut (link) to that executable file, then executing the shortcut gave me the error.

If more than one java is installed on the system this might happen and not set as default. On Ubuntu14.04 LTS I could get it resolved by executing following and choosing the java I needed.

sudo update-alternatives --config java [sudo] password for user: update-alternatives: warning: /etc/alternatives/java has been changed (manually or by a script); switching to manual updates only There are 2 choices for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode 1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1069 manual mode Press enter to keep the current choice[*], or type selection number: 2 update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java to provide /usr/bin/java (java) in manual mode 

I choose 2 and set openjdk-8 as a default. Which did not show the Exec format error .

Источник

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