Centos8系統執行二進制文件時,報“bash: ./xxx: no such file or directory”解決


在執行某個二進制文件時報錯誤:bash: ./xxx: no such file or directory,但在該目錄下確實存在該文件,且具有執行權限。有些linux系統(本次場景:CentOS 8.3Fedora 27)的發行版里沒有安裝redhat-lsb這個庫,所以導致執行一些二進制命令時報沒找到文件或目錄。

本文以/sbin/ip命令為例

  1. file命令查看可執行文件
[root@localhost sbin]# file ip
ip: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically 	linked (uses shared libs), for GNU/Linux 2.6.32,BuildID[sha1]=e44a34a2e79a8f0f1a5a3dcf21b62699248db754, stripped

看出是64位LSB二進制可執行文件,沒問題。

  1. ldd命令顯示共享庫的依賴情況
[root@localhost sbin]# ldd ip
	linux-vdso.so.1 =>  (0x00007ffc05f70000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f69b8a9c000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f69b86ce000)
	/lib64/ld-linux-x86-64.so.2 (0x0000557edc118000)

顯示出依賴的so。

  1. readelf命令查看必須的依賴

用這個命令查看readelf -l ip | grep interpreter

[root@localhost sbin]# readelf -l ip

Elf file type is EXEC (Executable file)
Entry point 0x406f0d
There are 9 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  PHDR           0x0000000000000040 0x0000000000400040 0x0000000000400040
                 0x00000000000001f8 0x00000000000001f8  R E    8
  INTERP         0x0000000000000238 0x0000000000400238 0x0000000000400238
                 0x000000000000001c 0x000000000000001c  R      1
      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
  LOAD           0x0000000000000000 0x0000000000400000 0x0000000000400000
                 0x00000000000559ac 0x00000000000559ac  R E    200000
  LOAD           0x0000000000056648 0x0000000000656648 0x0000000000656648
                 0x0000000000004ff8 0x000000000000ae90  RW     200000
  DYNAMIC        0x0000000000056df0 0x0000000000656df0 0x0000000000656df0
                 0x00000000000001e0 0x00000000000001e0  RW     8
  NOTE           0x0000000000000254 0x0000000000400254 0x0000000000400254
                 0x0000000000000044 0x0000000000000044  R      4
  GNU_EH_FRAME   0x000000000004f368 0x000000000044f368 0x000000000044f368
                 0x0000000000000d7c 0x0000000000000d7c  R      4
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     10
  GNU_RELRO      0x0000000000056648 0x0000000000656648 0x0000000000656648
                 0x00000000000009b8 0x00000000000009b8  R      1

 Section to Segment mapping:
  Segment Sections...
   00     
   01     .interp 
   02     .interp .note.ABI-tag .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame 
   03     .init_array .fini_array .jcr .data.rel.ro .dynamic .got .got.plt .data .bss 
   04     .dynamic 
   05     .note.ABI-tag .note.gnu.build-id 
   06     .eh_frame_hdr 
   07     
   08     .init_array .fini_array .jcr .data.rel.ro .dynamic .got 
[root@localhost sbin]# readelf -l ip | grep interpreter
      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]
[root@localhost sbin]#

可以看ld-linux-x86-64.so.2這個依賴包是必須的。我find命令看看庫里是否有該庫文件:

[root@localhost sbin]# find / -name ld-linux-x86-64.so.2
/usr/lib64/ld-linux-x86-64.so.2
[root@localhost sbin]#

我這里只是測試例子,在本次真實場景里是不存在該依賴文件,所以要去安裝相關庫。

  1. redhat-lsb安裝
[root@localhost sbin]# dnf install redhat-lsb

或者

[root@localhost sbin]# yum install redhat-lsb


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM