Linux 内核 init,/bin/sh 存在但无法执行(错误 -8)

Linux 内核 init,/bin/sh 存在但无法执行(错误 -8)

Bug:Linux 内核启动,加载 initramfs/CPIO 映像,但 init 进程失败并出现错误 -8 (NOEXEC)

[    3.499638] Run /init as init process
[    3.506228] Failed to execute /init (error -8)
[    3.510820] Run /sbin/init as init process
[    3.517222] Run /etc/init as init process
[    3.523164] Run /bin/init as init process
[    3.530061] Run /bin/sh as init process
[    3.536048] Starting init: /bin/sh exists but couldn't execute it (error -8)
[    3.543643] Kernel panic - not syncing: No working init found.  Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance.

使用的硬件和软件:

  • STM32F429-探索板
  • 自定义内核和设备树配置
  • 从头开始自定义构建脚本(没有 buildroot、没有 yocto、没有 uclinux)
  • 使用静态链接的busybox

我尝试过的:

  • 我没有在外部生成 CPIO 映像,而是尝试指定 rootfs/ 目录INITRAMFS_SOURCE=../rootfs/并让 linux makefile 构建 initramfs 本身。我也尝试使用spec.txt(下面是cat spec.txt)
  • 使用参数“noexec=off”启动~rdinit=/bin/sh console=ttySTM0,115200n8 earlyprintk noexec=off
  • 检查 busybox ELF 可执行文件是否具有正确的体系结构并且它是静态链接的。
$ readelf -A rootfs/bin/busybox 
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "7-M"
  Tag_CPU_arch: v7
  Tag_CPU_arch_profile: Microcontroller
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-2
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_rounding: Needed
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int
  Tag_CPU_unaligned_access: v6

$ readelf -A linux/vmlinux
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "7-M"
  Tag_CPU_arch: v7
  Tag_CPU_arch_profile: Microcontroller
  Tag_THUMB_ISA_use: Thumb-2
  Tag_FP_arch: VFPv2
  Tag_ABI_PCS_wchar_t: 2
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_enum_size: int

$ cat spec.txt 
dir /dev 755 0 0
nod /dev/console 644 0 0 c 5 1
dir /bin 755 1000 1000
slink /bin/sh busybox 777 0 0
slink /bin/mknod busybox 777 0 0
file /bin/busybox ../rootfs/bin/busybox 755 0 0
dir /proc 755 0 0
dir /sys 755 0 0
dir /mnt 755 0 0
file /init ../rootfs/init 755 0 0```

内核完整启动日志: https://pastebin.com/raw/kG78ksKJ

内核.config: https://pastebin.com/raw/2Dk4w99h

忙碌盒.config: https://pastebin.com/raw/KzuFdKFr

相关内容