首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Busybox init没有启动/etc/init.d/rcS

Busybox init没有启动/etc/init.d/rcS
EN

Stack Overflow用户
提问于 2014-11-26 15:58:21
回答 3查看 12.1K关注 0票数 3

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

代码语言:javascript
复制
# /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

你知道会出什么问题吗?

EN

回答 3

Stack Overflow用户

发布于 2018-05-31 18:41:19

初始化

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

例如,如果busybox二进制文件驻留在/bin/busybox中,则需要创建以下符号链接:

代码语言:javascript
复制
ln -s /bin/busybox /init

如果您希望您的初始化驻留在/sbin中,以符合初始化选项卡,还可以在那里创建一个符号链接。请注意,如果您不挂载根目录,并且busybox仅在initramfs中运行,则内核将不会考虑init=设置。

代码语言:javascript
复制
ln -s /bin/busybox /sbin/init

Inittab

此外,您可以尝试不使用inittab。您尝试从inittab运行的内容可能非常适合rcS和任何后代脚本。在same source中,您可以找到示例inittab:

代码语言:javascript
复制
# 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是可执行的:

代码语言:javascript
复制
chmod +x chroot chroot /bin/busybox

并尝试使用:

代码语言:javascript
复制
#!/bin/busybox sh
echo "Hello world!"

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

Busybox符号链接

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

代码语言:javascript
复制
#!/bin/busybox sh
mkdir -pv /sbin
/bin/busybox --install -s
票数 2
EN

Stack Overflow用户

发布于 2019-07-06 19:10:02

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

代码语言:javascript
复制
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

票数 1
EN

Stack Overflow用户

发布于 2014-11-26 16:29:08

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

以下是一些值得尝试的东西:

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

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

echo "This worked“> /tmp/test

您的脚本中可能存在与启动竞争条件相关的内容,导致其退出。我还想知道您的脚本是否启动了syslogd。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27143885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档