You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Buildroot通用包无法安装至/etc/init.d目录问题求助

Buildroot: S99gateway Init Script Missing from /etc/init.d on Target Device

Problem Description

I'm building an embedded Linux image with Buildroot for an embedded system, and I'm trying to integrate custom software by installing init scripts to the /etc/init.d/ directory (I know scripts starting with S run automatically on SysVinit).

I've written a Makefile snippet that Buildroot recognizes to copy JAR files and related scripts. After building, the JAR files and start_heimdall script are correctly placed in their expected directories, and I can see the S99gateway script in the local TARGET_DIR/etc/init.d/ folder. However, when I flash the image to the embedded device and SSH in, the S99gateway script is gone from /etc/init.d/, so my application won't start.

Here's the relevant Makefile code:

define MY_GATEWAY_INSTALL_TARGET_CMDS
$(INSTALL) -d $(TARGET_DIR)/$(DST_FOLDER); \
$(INSTALL) -D -m 0644 $(@D)/*.jar $(TARGET_DIR)/$(DST_FOLDER); \
\
$(INSTALL) -D -m 0700 /work/package/mycompany/my-gateway/artifacts/start_heimdall $(TARGET_DIR)/$(DST_FOLDER); \
ln -snrf $(TARGET_DIR)/$(DST_FOLDER)/start_heimdall $(TARGET_DIR)/usr/bin/start_heimdall; \
\
$(INSTALL) -D -m 0755 /work/package/mycompany/my-gateway/artifacts/S99gateway $(TARGET_DIR)/$(DST_FOLDER); \
$(INSTALL) -D -m 0755 /work/package/mycompany/my-gateway/artifacts/S99gateway $(TARGET_DIR)/etc/init.d/S99gateway; \
\
if [[ "$(BR2_HSDP_GATEWAY_INCLUDE_VERSION_FILE)" == "y" ]]; then \
echo $(HEIMDALL_VERSION) > $(TARGET_DIR)/my_gw_version; \
fi
endef

I'm wondering: Is the /etc/init.d/ directory protected in some way? Could the internal logic of the script affect the installation process?


Answer

Let's break down the most likely causes and fixes for this issue:

1. Buildroot's Init System Handling (Most Likely Culprit)

When using SysVinit (the default for many Buildroot setups), simply copying a script to /etc/init.d/ isn't enough to guarantee it stays in the final image. Buildroot may clean up unregistered scripts during the root filesystem packaging phase, especially if it doesn't see corresponding symlinks in the rc*.d directories.

Fix: Register the script with update-rc.d to create the necessary runlevel symlinks. Buildroot will recognize these symlinks and ensure the script is included in the final image. Modify your Makefile snippet's S99gateway section like this:

# Copy the script to /etc/init.d/
$(INSTALL) -D -m 0755 /work/package/mycompany/my-gateway/artifacts/S99gateway $(TARGET_DIR)/etc/init.d/S99gateway;
# Register the script to run in default runlevels (2,3,4,5)
$(TARGET_DIR)/sbin/update-rc.d S99gateway defaults;

This tells Buildroot that this script is part of the system's startup sequence, so it won't be excluded during packaging.

2. Root Filesystem Packaging Exclusions

Buildroot uses configuration options like BR2_ROOTFS_OVERLAY or BR2_ROOTFS_POST_BUILD_SCRIPT to customize the root filesystem. If a post-build script or overlay is cleaning up /etc/init.d/ or removing unrecognized scripts, that could be why your S99gateway disappears.

Check:

  • Review any custom post-build scripts you've added to ensure they aren't deleting files from /etc/init.d/.
  • Verify your root filesystem overlay (if used) doesn't overwrite or clean the /etc/init.d/ directory.

3. Script Content Issues

While script logic won't make the file disappear entirely, invalid syntax or incorrect shebangs could cause issues during Buildroot's post-processing (though this is less likely since the file exists in TARGET_DIR).

Check:

  • Ensure the script starts with a valid shebang for your embedded system, e.g., #!/bin/sh (avoid #!/bin/bash unless you've explicitly included bash in your Buildroot config).
  • Make sure the script doesn't contain any invalid characters or syntax that might trigger unexpected behavior during packaging.

4. Filesystem Mounting or OverlayFS

If your target system uses OverlayFS or a temporary root filesystem during boot, it might be overlaying the /etc/init.d/ directory you built into the image.

Check:

  • Look at your Buildroot config's BR2_TARGET_ROOTFS_* options to see if OverlayFS is enabled.
  • Check the device's boot logs to see how the root filesystem is being mounted.

5. Verify the Image Before Flashing

To narrow down whether the issue is in the build or the device, mount the generated root filesystem image locally and check if S99gateway is present:

# Create a temporary mount point
mkdir -p /tmp/rootfs
# Mount the image (replace with your actual image path/type)
mount output/images/rootfs.ext4 /tmp/rootfs
# Check for the script
ls /tmp/rootfs/etc/init.d/
# Unmount when done
umount /tmp/rootfs

If the script is missing from the mounted image, the problem is in the Buildroot build process. If it's present, the issue is with how the device is booting or mounting the filesystem.


内容的提问来源于stack exchange,提问作者Rick Slinkman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 19:47:32