系统与基础设施lists.busybox.net编辑精选
理解 bin、sbin、usr/bin、usr/sbin 的划分
Understanding the bin, sbin, usr/bin , usr/sbin split
2012 — 2022,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是 BusyBox 邮件列表上一篇解释 Unix 目录 /bin、/sbin、/usr/bin、/usr/sbin 划分由来的帖子:这些区分源于当年磁盘空间不足(RK05 磁盘太小,装不下的二进制被挪到 /usr)以及根文件系统需在挂载 /usr 前自足可用等历史原因。帖子多次登上 HN 首页,成为理解 Linux 文件系统层级历史演变的经典参考。
为什么经久不衰:它解释了几乎所有 Linux 用户都困惑过、却很少有人真正搞懂的目录划分的历史根源,且随着 /usr 合并等现代改动,这一背景知识至今仍有现实意义。
HN 评论精选
亲历者证实:sbin 意为静态链接的 bin,/usr 的划分源于磁盘空间不足和 AT&T 的严格规范
作为当年亲历者,读这篇就像《傻瓜大闹科学城》里未来人研究过去文物的场景。在 BSD 与 System V 合并(Sun 的 Lulu 项目)时引入了 /opt 来把'软件包'与'系统'分开;/bin 与 /sbin 的区别在于 sbin 是'静态链接的 bin',里面的程序不依赖任何库就能运行。Linux 启动方式不同是因为 Linux 从根本上就不是 UNIX,两者是不同物种;FreeBSD 才是 UNIX 衍生品。/usr/{lib,bin} 的出现确实是因为 RK05 磁盘空间不足,80 年代 Sun 和 AT&T 的共识是根文件系统放'系统',/usr 放'非系统'的东西。AT&T 对目录用途有详细规范,在根目录新增目录是件大事,所以新目录都出现在 /usr 下;/opt 出现后大家才有了自由创建目录树的余地。
ChuckMcM查看英文原文
Wow. As someone who was there (I know dating my self here) reading this is kind of like that scene in Sleeper where the person from the future is trying to understand artifacts from the past. So during the BSD / System V merge (project Lulu at Sun) the /opt filesystem was introduced as a way to keep 'packages' separate from 'system'. The difference between /bin and /sbin was that sbin was 'static-bin' which is to say everything in it was statically linked and could run without any libraries being available. The fact that Linux starts up differently is because Linux never was UNIX they are two different OSes, pretty much from the ground up. They use similar concepts, processes, file descriptors, Etc, but they are two different species. FreeBSD on the other hand is a derivative of UNIX and last time I checked it started up in a similar way. The lack of space on the RK05s was indeed the reason for the addition of /usr/{lib, bin} and the general consensus at Sun and AT&T in the 80's was that the root file system contained the system, and the /usr file system contained stuff that was not-system. AT&T (the guys that 'owned' UNIX) had some pretty detailed specifications about what lived in what directory and why. It was a "BigDeal" (tm) to add a new directory in the root file system so new directories, when they were proposed, appeared under /usr. And once /opt existed it gave people free reign to create their own trees. Early package managers would build /opt/<package>/{bin/lib/share/man} and the downside was that ones path variable got longer and longer, and there arguments about if there should be more constraints on opt.
引用 FHS 标准:bin/sbin 的划分服务于单用户模式恢复和 /usr 网络共享挂载,仍有实际意义
FHS(文件系统层级标准)是这类问题的权威参考:/bin 存放挂载其他文件系统之前(如单用户模式)必需的二进制,/usr/bin 存放'大多数用户命令'。这样你可以保留一个只含 init 所需程序的最小本地文件系统,而 /usr 可以从网络共享挂载,管理员把软件装到共享的 /usr 上即可对所有机器生效。/sbin 和 /usr/sbin 则是只有管理员才用的命令。大多数系统并不真的需要这种分离,但它确实有道理——历史原因可能不再成立,但不意味着它只是因循守旧。
tmhedberg查看英文原文
The FHS (Filesystem Hierarchy Standard) [1] is the go-to reference for this sort of thing. It explains that `/bin` is for binaries that are essential before other file systems are mounted (e.g. in single user mode), and `/usr/bin` is for "most user commands" (all others). This allows you to keep a minimal local filesystem containing only the binaries needed for init to get the system running, and then `/usr` can be mounted, say, from a network share. This is useful because then network admins can install software to the common `/usr` share and make it immediately available to all machines which mount that share. The `/sbin` and `/usr/sbin` directories are for commands needed only by administrators, which will not normally be used by regular users. Most systems don't really require this separation, but it does make sense. Perhaps the historical reason for doing it is no longer a factor, but that doesn't mean it's perpetuated merely because of tradition. [1] http://www.pathname.com/fhs/pub/fhs-2.3.html
90 年代文档的实用解释:sbin 放 root 程序,根分区路径保证单用户模式可用,/usr 交给包管理器
这个解释我读过几次,追溯到 PDP-11 时代确实显得荒谬。我 90 年代末从杂志光盘第一次接触 Linux,当时的文档解释得更清楚:/sbin、/usr/sbin 是给需要 root 权限的程序用的,单独放可以让权限整齐,也不会出现在 bash 补全里。不带 /usr 的路径从开机起就可用,是第一个挂载的分区,单用户模式下保证可用,也能在那里跑 fsck。带 /usr 的路径由包管理器管理,口口相传的规矩是别手动往那里装东西,要装就装到 /usr/local 或 /opt。
captainmuon查看英文原文
I've read this explanation a couple of times, and if you go all the way back to PDP-11 the split does indeed sound ridiculous. I had my first contact with Linux from some magazine CDs in the late 90s, I think it was Red Hat or SUSE based. The documentation there had a much clearer explaination: /sbin, /usr/sbin is for binaries that need root. You put them in separate directories so their permissions all match up, and so they don't show up when completing in bash. The paths without /usr - /bin and /sbin - are available from the get go. It is the very first partition that is mounted, and what is guaranteed to be available if you do "init 1" or boot in single user mode. You can also do fsck from there (assuming the boot partition is not damaged). I don't know how this integrated with initrd (initramfs wasn't a thing yet). I think there was only one "base system" - either initrd was very basic, or the whole base was in initrd, or something similar. The paths with /usr were managed by the package manager. Word of mouth was: don't install anything manually there. If you do (via make install), keep around the source so you can do make uninstall. But better install to /usr/local or /opt.
合并 sbin/bin 的提案因社区惯性受阻,尽管实测性能反而更好
我曾向 FreeBSD 邮件列表提议合并 /sbin 与 /bin、/usr/sbin 与 /usr/bin。有人担心这会因 PATH 查找变慢拖慢系统,即使我证明恰恰相反(需要扫描的目录更少反而更快),也无法达成共识。真遗憾。
EdSchouten查看英文原文
I once sent out a proposal on the FreeBSD lists to merge /sbin with /bin, and /usr/sbin with /usr/bin. People were concerned that this would slow down the system, due to PATH lookups taking longer. Even when I demonstrated the opposite was true (it being faster due to fewer directories needing to be scanned), I wasn't able to get consensus. What a shame.
历次讨论
同类还值得读
TTY 揭秘(2008)
The TTY demystified (2008)
经典文章深入剖析了 Unix/Linux 中 TTY 子系统的工作原理,包括线路规程、终端驱动、信号与控制字符等机制。
系统与基础设施上首页 11 次 · 2009–2025linusakesson.net编辑精选为什么 GNU grep 这么快
Why GNU grep is Fast
FreeBSD 邮件列表上一篇广为流传的帖子,解释 GNU grep 为什么快:核心在于 Boyer-Moore 字符串搜索算法配合精心优化的内部循环和 I/O,让程序在搜索时“…
系统与基础设施上首页 9 次 · 2010–2022lists.freebsd.orgXplain:为普通人讲解 X11
Xplain – Explaining X11 for the rest of us
《Xplain》是作者(HN 用户 Jasper_)写的一系列 X11 长文,用他在浏览器中重建的 X11 绘图模型做交互演示,讲解 X11 的绘图模型与窗口系统设计。
系统与基础设施上首页 6 次 · 2013–2020magcius.github.io编辑精选旋风教程:为 Linux 创建极小 ELF 可执行文件(1999)
A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux (1999)
breadbox 写于 1999 年的经典教程,主题是如何为 Linux 手工构造并裁剪出体积极小的 ELF 可执行文件。
系统与基础设施上首页 6 次 · 2007–2025muppetlabs.comPostgreSQL 内部原理
The internals of PostgreSQL
《The Internals of PostgreSQL》是一本免费在线书籍,系统讲解 PostgreSQL 的内部实现,包括查询处理、并发控制、WAL、缓冲区管理等核心机制。
系统与基础设施上首页 5 次 · 2017–2025interdb.jp编辑精选