我正在使用 busybox 从 buildroot 构建自定义 initramfs,以用于自动 fdisk 分区。如何/在哪里放置脚本文件,以便 busybox 启动并自动执行它。
最佳答案
How to make a script run in buildroot as a boot script after init
您不能将一个脚本文件用于这两种目的。您需要一个在目标上执行的脚本,以及主机上的一种方法来修改目标的原型(prototype)文件系统。
将脚本和文件安装到 Buildroot 生成的目标文件系统中的典型方法是指定“构建后脚本”。该脚本在根文件系统被 tar
或 ubinize
d 之前执行。
来自 Buildroot user manual 的4.1 自定义生成的目标文件系统部分:
In the Buildroot configuration, you can specify the path to a post-build script, that gets called after Buildroot builds all the selected software, but before the rootfs packages are assembled. The destination root filesystem folder is given as the first argument to this script, and this script can then be used to copy programs, static data or any other needed file to your target filesystem.
Buildroot board 目录下的开发板子目录(例如 board/beaglebone)是存储 post-build.sh 文件以及用于复制的原始文件。
post-build.sh 文件的示例是 here 。使用 echo
命令逐行创建目标的两个脚本文件。只需复制二进制文件即可。
另请参阅 this presentation 的第 24-25 页.
关于linux - 如何使脚本在 init 后作为启动脚本在 buildroot 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31303041/