zlacker

Understanding the bin, sbin, usr/bin, usr/sbin split (2010)

submitted by taubek+(OP) on 2022-05-11 06:15:01 | 534 points 227 comments
[view article] [source] [go to bottom]

NOTE: showing posts with links only show all posts
◧◩
4. wkz+E7[view] [source] [discussion] 2022-05-11 07:30:27
>>Waterl+k7
https://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.pdf
◧◩
5. faho+g8[view] [source] [discussion] 2022-05-11 07:35:58
>>Waterl+k7
You probably have a "hier" man page on your system. https://man7.org/linux/man-pages/man7/hier.7.html

Also systemd has a "file-hierarchy" man page for its understanding of the hierarchy, which includes e.g. its use of /run and which directory can be read-only - https://man7.org/linux/man-pages/man7/file-hierarchy.7.html

◧◩
10. drothl+A9[view] [source] [discussion] 2022-05-11 07:48:23
>>Waterl+k7
Many distros, including Debian & Ubuntu, have merged /bin and /usr/bin, with symlinks for backwards compatibility: /bin -> /usr/bin (and similarly for /usr/lib etc).

https://www.freedesktop.org/wiki/Software/systemd/TheCaseFor...

◧◩
19. mlatu+5e[view] [source] [discussion] 2022-05-11 08:24:36
>>Waterl+k7
you are looking for the https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
◧◩◪
24. pabs3+Ke[view] [source] [discussion] 2022-05-11 08:34:27
>>drothl+A9
The Debian/Ubuntu merged-/usr is incomplete, various things are broken by the way this was achieved:

https://wiki.debian.org/Teams/Dpkg/MergedUsr

28. bjourn+6f[view] [source] 2022-05-11 08:38:10
>>taubek+(OP)
Roughly the same reason why dotfiles became a thing on Unix: https://linux-audit.com/linux-history-how-dot-files-became-h... Fortunately more and more software is putting its config in ~/.config/ rather than dumping it all over users' home directories.
◧◩◪
53. hnlmor+um[view] [source] [discussion] 2022-05-11 10:00:22
>>Cthulh+wg
> Hypothetically speaking, would forking FreeBSD or a nix to use a simpler folder structure be feasible?*

Not only feasible but it's been implemented a few times over the years. The most notable being GoboLinux[1][2], which is nearly 20 years old.

[1] https://en.wikipedia.org/wiki/GoboLinux

[2] https://gobolinux.org/

> I was thinking "just symlink /sbin with /bin", but there would probably be conflicts

Given how long /sbin et al have been around, there would always be some edge cases. However it is still possible to do. GoboLinux uses symlinks to achieve LFH[3] compatibility while still having friendly directory names. ArchLinux also just has one bin directory and uses symlinks for compatibility:

  » ls -l / | grep bin                                                                                                                                                                                   
  lrwxrwxrwx   1 root root              7 2021-12-07 02:41 bin -> usr/bin
  lrwxrwxrwx   1 root root              7 2021-12-07 02:41 sbin -> usr/bin

  » ls -l /usr | grep bin                                                                                                                                                                                
  drwxr-xr-x   5 root root 110,592 2022-05-06 09:23 bin
  lrwxrwxrwx   1 root root       3 2021-12-07 02:41 sbin -> bin
[3] https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
◧◩◪
56. em500+Bm[view] [source] [discussion] 2022-05-11 10:01:20
>>Cthulh+wg
Why hypothetical, Gobo Linux[1] has already done it. Or if you want to just hide (rather than replace) the traditional Unix hierarchy from the user, you get macOS (inherited from NeXTSTEP).

The problem is that the actual benefits a pretty nebulous, so it's probably not worth the effort (and drawbacks of using different conventions than most others *nix users).

[1] https://www.gobolinux.org/

◧◩◪◨⬒
58. hnlmor+kn[view] [source] [discussion] 2022-05-11 10:08:57
>>merijn+Yi
This is wrong (and dangerously so too).

On FreeBSD 3rd party packages go into /usr/local and not /usr

You absolutely will get base packages in /usr/bin (eg `env`) so nuking /usr/bin will break your FreeBSD install.

There's a good write up here: https://unix.stackexchange.com/questions/332764/role-of-the-...

◧◩
74. trasz+Qq[view] [source] [discussion] 2022-05-11 10:38:57
>>baby+rq
Take a look at "man hier": https://www.freebsd.org/cgi/man.cgi?hier
101. TheCyc+ey[view] [source] 2022-05-11 11:50:27
>>taubek+(OP)
https://fedoraproject.org/wiki/Features/UsrMove (2012) and the linked systems article https://www.freedesktop.org/wiki/Software/systemd/TheCaseFor... include some motivation for changing the status quo, and moving all the duplicate root paths into /usr.
◧◩◪◨
103. tombl+My[view] [source] [discussion] 2022-05-11 11:52:50
>>em500+Bm
I'm pretty sure Gobo Linux functions partially like macOS does, hiding system directories, by removing them from readdir with a custom kernel module[0].

[0]: https://gobolinux.org/doc/articles/gobohide.html

104. codedo+bz[view] [source] 2022-05-11 11:55:25
>>taubek+(OP)
The fact that there are several directories with binaries is not a problem by itself. The problem is that many applications use hardcoded paths instead of searching for these binaries using PATH.

It means that if someone decides to get away from this legacy structure and move OS into something like /system/debian-11.1.2/ all those programs would break.

Examples: [1], [2]. I assume that developers have hardcoded those paths because /sbin is often not included into PATH.

[1] https://github.com/blueman-project/blueman/blob/fcef83a01c80...

[2] https://github.com/blueman-project/blueman/blob/fcef83a01c80...

◧◩◪◨⬒
109. rascul+DB[view] [source] [discussion] 2022-05-11 12:09:34
>>pmoria+vv
I can recall any Linux distro or Unix variant setup in the way you describe. In addition, the Filesystem Hierarchy Standard disagrees with you.

https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html

You may be thinking of the /bin and /usr/bin difference, though.

110. kuhari+IB[view] [source] 2022-05-11 12:10:29
>>taubek+(OP)
Past comments: https://news.ycombinator.com/item?id=3519952, https://news.ycombinator.com/item?id=11647304, https://news.ycombinator.com/item?id=22614731
◧◩◪◨
116. hpb42+AE[view] [source] [discussion] 2022-05-11 12:27:30
>>moffka+Gv
There is "man hier" and also "man file-hierarchy": https://www.man7.org/linux/man-pages/man7/file-hierarchy.7.h...
◧◩◪◨⬒
117. nerdpo+NE[view] [source] [discussion] 2022-05-11 12:28:44
>>pmoria+vv
https://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.html

> Utilities used for system administration (and other root-only commands) are stored in /sbin, /usr/sbin, and /usr/local/sbin. /sbin contains binaries essential for booting, restoring, recovering, and/or repairing the system in addition to the binaries in /bin.

◧◩◪
118. indror+TF[view] [source] [discussion] 2022-05-11 12:34:51
>>alecmg+Ca
Fun fact this is the second time Microsoft have pulled this. The first time was for legacy 16 bit Windows applications running on Windows NT. Since most people have moved to 64bit processors, it has been shuttered.

https://en.wikipedia.org/wiki/Windows_on_Windows

◧◩◪
120. gjadi+SG[view] [source] [discussion] 2022-05-11 12:39:52
>>pseudo+im
It is specified this way on OpenBSD: https://man.openbsd.org/man7/hier.7

> /bin/ User utilities fundamental to both single and multi-user environments. These programs are statically compiled and therefore do not depend on any system libraries to run.

> /sbin/ System programs and administration utilities fundamental to both single and multi-user environments. These programs are statically compiled and therefore do not depend on any system libraries to run.

◧◩◪◨⬒
121. rascul+WI[view] [source] [discussion] 2022-05-11 12:49:27
>>mekste+nA
The fix is for the user to use a smaller $PATH when possible. Any method of checking that the command exists and is executable before trying to execute it leads to TOCTOU race conditions.

https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use

◧◩◪
122. faho+kJ[view] [source] [discussion] 2022-05-11 12:51:33
>>sph+Xg
There is no specific reason for a program that uses the XDG dirs on other unices to not use them on macOS, other than some idea that it's "alien".

You can have ~/.config/. Nothing in macOS prevents you from having it. And so, some programs do. The worst thing that happens is that, instead of having one directoy ~/.foo you now have one directory ~/.config/foo and nothing else in ~/.config. But as soon as you add the second thing that uses ~/.config, you now have two directories in there instead of a second dotdirectory in ~.

It's just that for a bunch of them the XDG path is only used if it exists - e.g. emacs predates the spec, so it uses ~/.emacs.d (and a few others) first.

Cargo doesn't use the XDG paths at all, apparently - https://github.com/rust-lang/cargo/issues/1734. However it also needs a directory for binaries (~/.cargo/bin) and ~/.local/bin isn't actually in the spec at the moment (https://gitlab.freedesktop.org/xdg/xdg-specs/-/issues/14).

◧◩◪◨
124. faho+sK[view] [source] [discussion] 2022-05-11 12:57:50
>>pabs3+Ke
Note: This is the dpkg maintainer arguing an apparently fairly unpopular position of linking the specific files inside of /bin instead of /bin directly, in opposition to what appears to be the majority of linux distros.

He's even added a warning to dpkg and a "usrunmess" tool to switch a system to his preferred way of doing things.

It's not clear to me where the breakage lies and I've not seen any actual reports of it.

For more context see https://lwn.net/Articles/890219/

◧◩◪◨⬒
129. colejo+zM[view] [source] [discussion] 2022-05-11 13:09:42
>>indror+WD
But what if I need to read on how to use apropos? Then I need to do `man apropos` and I'm stuck in a cycle! /s

https://www.man7.org/linux/man-pages/man1/apropos.1.html

◧◩
136. cassep+9S[view] [source] [discussion] 2022-05-11 13:38:01
>>szasta+8P
You should really check out GoboLinux then : https://gobolinux.org/
◧◩◪
140. jmclnx+tU[view] [source] [discussion] 2022-05-11 13:48:41
>>Cthulh+wg
Also FreeBSD (and other BSDs) usually mount /usr on its own partition. I think that causes issues in Linux these days. So yes, merging in the BSDs may be a big change.

FWIW, Slackware keeps the separate, following the Linux Standard Base.

https://en.wikipedia.org/wiki/Linux_Standard_Base

◧◩◪◨
151. deadbu+O21[view] [source] [discussion] 2022-05-11 14:25:37
>>faho+kJ
It's a real shitshow.

https://wiki.archlinux.org/title/XDG_Base_Directory

◧◩◪
162. jeroen+7e1[view] [source] [discussion] 2022-05-11 15:10:39
>>sph+Xg
I can understand devs not using the right circumstances if their platform of choice doesn't come with an easy way to determine the right directory to put stuff in, let alone create it if necessary.

What I really want is an API that does "create/open/delete a file/directory for the relevant configuration/cache/resources store", be it user configured or platform default. What I get is an external package that gives me a list of potential storage locations (of which I'll probably just pick the first) that may or may not be actual directories on the system which I may or may not have access to touch files in.

Some devs are kindly reminded that there's a spec for these things but often it's too late as data is already in specific paths that users may have come to know. That way you end up with paths that get set by environment variables where you have to tell each and every program where to put their crap.

Other programs don't care enough to implement the standards (like Firefox; the bug report about XDG is old enough to vote [1] and it's still not implemented fully). Kubernetes has an open issue for its client that only ever gets bumped.

Even worse are devs that are reminded of standards like XDG and then decide to give everyone the middle finger. Snap is one of them, not only is the data directory hard-coded, it's hard-coded lowercase unlike every other standard directory on Canonical's distribution itself! Snap's biggest competitor, Flatpak, decided not following the standard is not a problem [3]. At least it's special snowflake folder starts with a period so that it's hidden by default, I suppose. Even Bash doesn't support XDG [4] because not everyone uses Linux (and apparently no effort should be made to support OS specific standards?) with the suggestion closed as won't fix.

Many tools that do support XDG only care about their own standards, of course; Windows has had SHGetKnowlFolderPath since Vista, replacing SHGetFolderLocation which dates back to Windows 2000. Still, developers like to push POSIX standards into Windows, creating .dotfiles and not even bothering to at least mark them as hidden.

There's a big list on the Arch wiki[7] listing programs and their compatibilities with XDG.

[1]: https://bugzilla.mozilla.org/show_bug.cgi?id=259356

[2]: https://github.com/kubernetes/kubernetes/issues/56402

[3]: https://github.com/flatpak/flatpak/issues/1651

[4]: https://savannah.gnu.org/support/?108134

[5]: https://docs.microsoft.com/en-us/windows/win32/api/shlobj_co...

[6]: https://docs.microsoft.com/en-us/windows/win32/api/shlobj_co...

[7]: https://wiki.archlinux.org/title/XDG_Base_Directory#Hardcode...

◧◩◪
163. mmphos+Jf1[view] [source] [discussion] 2022-05-11 15:16:57
>>sph+Xg
https://developer.apple.com/library/archive/documentation/Fi...
◧◩
168. jmbwel+ci1[view] [source] [discussion] 2022-05-11 15:25:08
>>szasta+8P
macOS also does a more strict but tidier hierarchy, grouped into "domains" … /System/* is "stuff from Apple" (including /System/Library, etc.), / is for "stuff on the local machine" (/Applications, /Library, etc.), and then each user can have their own hierarchy in their user directory (~/Applications, ~/Library, etc.).

Of course, the "stuff from BSD" winds up in /bin and /usr/bin anyway, so it's still a mess.

https://developer.apple.com/library/archive/documentation/Fi...

◧◩◪◨⬒
186. shagie+mJ1[view] [source] [discussion] 2022-05-11 17:22:45
>>bityar+yD
I'll also note /usr/games/dm ( https://github.com/vattam/BSDGames/tree/master/dm ) which allowed sysadmins to restrict when programs in /usr/games could be run. Setting up that structure in /usr/bin would be more work to maintain.
◧◩◪◨
190. behnam+0T1[view] [source] [discussion] 2022-05-11 18:05:57
>>DavidV+701
More still, why do some apps install in other directories such as AppData?

https://stackoverflow.com/questions/12427245/installing-in-p...

◧◩◪
220. survir+x84[view] [source] [discussion] 2022-05-12 11:16:06
>>li2uR3+JR
I just got done building an omni-channeling recording system, with a soc running ubuntu-server & alsa handling recording from several usb dacs connected to microphones. I feel your pain. Sound on linux is a nightmare. But now that I have an understanding of it, here are some helpful things I learned.

- Make sure alsa-utils is installed

- Auto-configure hardware devices: alsactl init

- View hardware for playback (use arecord for opposite): aplay -L | grep “^hw:”

^ Use that to make sure your hw is being detected

- Lower level list of sound cards, if having issues: cat /proc/asound/cards

- Base alsa conf: /usr/share/alsa/alsa.conf

^ go there to dive deeper into what alsa is actually doing. It will also show you the priority for config files, so you can go through that and check which ones are in use and modify accordingly. alsactl init should handle most configuration though.

- you will want to mess with this: /etc/modprobe.d/alsa-base.conf …and get it working for your hardware. This is a resource to understand that file better: https://alsa.opensrc.org/MultipleCards

You can google configuration files and find one that works for you. Most issues for normal use will revolve around which card gets set to index 0 / default, so if you know your card you want as default, I’d recommend finding your device id (i think cat /proc/asound/cards will give you vendor/product ids you can use) then making a config using that id to set it as the default card, independent of indexing.

Turned into a lot, stopping here. Sound really shouldn’t be this hard for end users or devs, but it is what it is right now. Anyway, it’s fresh on my mind so at the very least, I might be able to point you in the right direction.

Good luck!

- Someone with no more hair left to pull out

227. jlundb+o19[view] [source] 2022-05-13 18:36:46
>>taubek+(OP)
For those who liked this text and want to read more from the author, have a look at his busybox replacement toybox:

http://landley.net/toybox/

[go to top]