什么是 BusyBox?

Lobsters Hottest 工具

摘要

一篇解释性文章,详细介绍了 BusyBox 如何在 Alpine Linux 中作为多调用二进制文件发挥作用,通过符号链接和小程序配置为各种命令行工具提供单一可执行文件。

<p><a href="https://lobste.rs/s/msrczi/what_is_busybox">评论</a></p>
查看原文
查看缓存全文

缓存时间: 2026/05/13 00:21

# 什么是 BusyBox? 来源:https://specular.fi/post/what-is-busybox 两只鸭子在狭窄的溪流中游弋,部分被高高的芦苇和黄色的秋叶遮蔽。在你意识到之前,这一刻将成为回忆。我偶然发现了 BusyBox (https://busybox.net/),但直到我注意到 Alpine 默认安装了 wget 后,我才开始调查它的来源。除了 wget 的版本显示为“BusyBox Wget”。 那是什么? ``` docker run --rm -it alpine sh / # which wget /usr/bin/wget / # ls -lah /usr/bin/wget lrwxrwxrwx 1 root root 12 Apr 15 04:51 /usr/bin/wget -> /bin/busybox ``` 运行 `ls -la /usr/bin` 后,我惊呆了:几乎 130+ 个可执行文件都来自同一个二进制文件! 这就解释了“多调用二进制文件(multicall binary)”这个名字。但是……如何工作呢?BusyBox 是如何运作的? 单个二进制文件如何知道要运行哪个可执行文件?嗯,我猜对了: ``` applet_name = argv[0]; if (applet_name[0] == '-') applet_name++; applet_name = bb_basename(applet_name); ``` 所以,显式调用也能工作: ``` / # busybox ls -1 bin dev etc home / # busybox meheh meheh: applet not found ``` 因此,要运行 wget,我们通过名称找到它并运行它: ``` int applet = find_applet_by_name(name); // ... run_applet_no_and_exit(applet, name, argv); // ... xfunc_error_retval = applet_main[applet_no](argc, argv); ``` 每个小程序(applet)都有自己的 C 文件,wget 对应的是 `wget.c`。每个小程序似乎还在代码注释中定义了某种“配置”: ``` //config:config WGET //config: bool "wget (41 kb)" //config: default y //config: help //config: wget is a utility for non-interactive download of files from HTTP //config: and FTP servers. //applet:IF_WGET(APPLET(wget, BB_DIR_USR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_WGET) += wget.o ``` 最终,我们调用了 wget 的主函数: ``` int wget_main(int argc UNUSED_PARAM, char **argv) ``` 其他有趣的部分:BusyBox 还支持硬链接。 ``` busybox --install -s ``` `-s` 创建符号链接。 你还可以列出它编译了哪些命令: ``` / # busybox --list | wc -l 304 ``` 因此,Alpine 更像是一个基于 BusyBox 的二进制文件的接口。每个二进制文件似乎都是实际完整版本的精简版。我仍然想知道这些是重新实现还是只是实用程序原始源代码的缩减版。

相似文章

在脚本的 shebang 行中使用 LLM

Simon Willison's Blog

Simon Willison 演示了如何在脚本的 shebang 行中使用 llm CLI 工具,从而直接从可执行文件执行 LLM 提示词与工具调用。

用 x86_64 汇编写成的 Linux 桌面

Lobsters Hottest

一位开发者借助 Claude Code,用纯 x86_64 汇编重建了完整的 Linux 桌面栈——从 shell、终端、窗口管理器到各种工具,实现微秒级启动,并延长数小时续航。

BNA Code

Product Hunt

BNA Code是一个CLI代理,旨在直接从终端构建全栈移动应用。