【问题标题】:Busybox init does not start /etc/init.d/rcSBusybox init 不启动 /etc/init.d/rcS
【发布时间】:2015-01-24 11:17:01
【问题描述】:

我正在尝试使用 buildroot 构建嵌入式系统。一切似乎都奏效了。所有模块均启动,系统稳定。问题是 /etc/init.d/rcS 在系统初始化期间没有启动。如果我手动运行它一切正常。我的 inittab 文件中有它。

# /etc/inittab
#
# Copyright (C) 2001 Erik Andersen <andersen@codepoet.org>
#
# Note: BusyBox init doesn't support runlevels.  The runlevels field is
# completely ignored by BusyBox init. If you want runlevels, use
# sysvinit.
#
# Format for each entry: <id>:<runlevels>:<action>:<process>
#
# id        == tty to run on, or empty for /dev/console
# runlevels == ignored
# action    == one of sysinit, respawn, askfirst, wait, and once
# process   == program to run

# Startup the system
null::sysinit:/bin/mount -t proc proc /proc
null::sysinit:/bin/mount -o remount,rw /
null::sysinit:/bin/mkdir -p /dev/pts
null::sysinit:/bin/mkdir -p /dev/shm
null::sysinit:/bin/mount -a
null::sysinit:/bin/hostname -F /etc/hostname
# now run any rc scripts
::sysinit:/etc/init.d/rcS

# Put a getty on the serial port
ttyFIQ0::respawn:/sbin/getty -L -n ttyFIQ0 115200 vt100 # GENERIC_SERIAL

# Stuff to do for the 3-finger salute
::ctrlaltdel:/sbin/reboot

# Stuff to do before rebooting
null::shutdown:/etc/init.d/rcK
null::shutdown:/bin/umount -a -r
null::shutdown:/sbin/swapoff -a

知道可能出了什么问题吗?

【问题讨论】:

    标签: linux busybox buildroot


    【解决方案1】:
    1. /bin/init 需要在您的文件系统上。
    2. /bin/sh 需要在您的文件系统上。
    3. /etc/init.d/rcS 需要是可执行文件,并以 #!/bin/sh 作为第一行。

    【讨论】:

      【解决方案2】:

      初始化

      你确定你在哪里调用 Busybox init?内核命令行是什么?如果没有向内核提供init= 选项,内核将在/init 处寻找可执行文件。

      例如,如果您的 busybox 二进制文件位于 /bin/busybox,您需要创建以下符号链接:

      ln -s /bin/busybox /init
      

      如果您希望您的 init 驻留在 /sbin 中,以遵守 inittab,也可以在那里创建一个符号链接。请注意,如果您不挂载 root 并且您的 busybox 仅在 initramfs 中运行,内核将不会尊重 init= 设置。

      ln -s /bin/busybox /sbin/init
      

      初始化选项卡

      另外,您可以尝试不使用 inittab。您尝试从 inittab 运行的东西可能非常适合 rcS 和任何后代脚本。从 same source 你找到了你的示例 inittab:

      # Note: BusyBox init works just fine without an inittab. If no inittab is
      # found, it has the following default behavior:
      #         ::sysinit:/etc/init.d/rcS
      #         ::askfirst:/bin/sh
      #         ::ctrlaltdel:/sbin/reboot
      #         ::shutdown:/sbin/swapoff -a
      #         ::shutdown:/bin/umount -a -r
      #         ::restart:/sbin/init
      #         tty2::askfirst:/bin/sh
      #         tty3::askfirst:/bin/sh
      #         tty4::askfirst:/bin/sh
      

      rcS

      确保/etc/init.d/rcS 是可执行的:

      chmod +x chroot chroot /bin/busybox
      

      并尝试:

      #!/bin/busybox sh
      echo "Hello world!"
      

      请注意,这句话可能会隐藏在内核日志消息之间,因此您可能需要通过 quiet 内核命令行选项来查看它是否出现。

      Busybox 符号链接

      符号链接是否安装到文件系统中?如果不是,那不是灾难。确保/etc/init.d/rcS 以:

      开头
      #!/bin/busybox sh
      mkdir -pv /sbin
      /bin/busybox --install -s
      

      【讨论】:

        【解决方案3】:

        除了脚本本身可执行并具有正确的 shebang 行之外,还需要在启用 CONFIG_BINFMT_SCRIPT 选项的情况下编译内核。

        CONFIG_BINFMT_SCRIPT:
        
        Say Y here if you want to execute interpreted scripts starting with
        #! followed by the path to an interpreter.
        
        You can build this support as a module; however, until that module
        gets loaded, you cannot run scripts.  Thus, if you want to load this
        module from an initramfs, the portion of the initramfs before loading
        this module must consist of compiled binaries only.
        
        Most systems will not boot if you say M or N here.  If unsure, say Y.
        

        如果没有此选项,您可能会收到错误消息can't run '/etc/init.d/rcS': Exec format error

        【讨论】:

          【解决方案4】:

          从给出的信息来看,一切看起来都是正确的。

          一些尝试:

          检查您的 rcS 脚本的所有权。

          注释掉 rcS 中的所有内容,并添加一些非常简单的内容:

          echo "这行得通" > /tmp/test

          您的脚本中可能存在与导致其退出的启动竞争条件相关的内容。也很好奇您的脚本是否正在启动 syslogd。

          【讨论】:

          • 发布您的 rcS 脚本可能会有所帮助。
          • 另外 - 尝试在 getty 之后将 inittab 中的 rcS 行进一步向下移动。
          猜你喜欢
          • 1970-01-01
          • 2015-07-26
          • 1970-01-01
          • 2011-12-19
          • 2014-09-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-02-16
          相关资源
          最近更新 更多