The difference between bin, sbin, usr/bin, usr/sbin

On November 30, 2010, David Collier wrote:

I noticed that in busybox, the links are spread across these four directories.
Is there any simple rule to determine which link belongs in which directory?
For example, kill is in /bin, while killall is in /usr/bin… I don’t see any logic in such a division.

You probably know that Ken Thompson and Dennis Ritchie created Unix on the PDP-7 in 1969. Well, around 1971, they upgraded to the PDP-11 with a couple of RK05 drives (1.5 megabytes each).

When the operating system grew and no longer fit on the first disk (where the root FS was located), they moved part of it to the second disk, where the home directories were located (hence the mount point was called /usr — from 'user'). They duplicated all the necessary OS directories there (/bin, /sbin, /lib, /tmp…) and stored files on the new disk because the old one ran out of space. Then they got a third disk, mounted it in the /home directory, and transferred the users' home directories there so the OS could occupy all the remaining space on the two disks, which amounted to a whole three megabytes (wow!).

Of course, they had to introduce a rule that 'when the operating system boots, it must be able to mount the second disk in the /usr directory, so don’t place programs like mount on the second disk in /usr, otherwise we’ll have a chicken-and-egg problem.' It was that straightforward. And this applied to Unix V6 35 years ago.

The separation of /bin and /usr/bin (and all similar directories) is a consequence of those events, a detail of implementation from the 70s that has been copied by bureaucrats for decades. They never asked the question why, they just did it that way. This separation ceased to make sense even before Linux was created, for several reasons:

  1. At boot time, initrd or initramfs is used, which takes care of issues like 'this file is needed earlier than that one.' Thus, we already have a temporary filesystem that is used to boot everything else.
  2. Shared libraries (which were added to Unix by the folks at Berkeley) do not allow you to independently change the contents of /lib and /usr/lib. These two parts must correspond to each other, or they will not work. This did not happen in 1974, as they had some independence back then due to static linking.
  3. Cheap hard drives broke the 100 megabyte barrier somewhere around 1990, and about the same time, programs for resizing partitions emerged (partition magic 3.0 was released in 1997).

Naturally, since there is a division, some people came up with rules that justify it. For instance, the root partition is needed for various common OS items, while /usr is meant for your local files. Or / contains what is provided by AT&T, while /usr contains what your distribution, IBM AIX, or Dec Ultrix, or SGI Irix added, and /usr/local holds files specific to your system. Then someone decided that /usr/local is not the right place to install new software, so let’s add /opt! I wouldn’t be surprised if /opt/local appears too...

Over 30 years, due to such a division, various interesting rules specific to different distributions have appeared and disappeared. For example, "/tmp is cleared at reboot, while /usr/tmp is not." (And in Ubuntu there is no /usr/tmp at all, while in Gentoo /usr/tmp is a symbolic link to /var/tmp, which now follows that rule, and it is not cleared at reboot. Yes, all of this was before tmpfs. There are also cases when the root filesystem is read-only, and then nothing should be written to /usr; writing should be done in /var. Or in / mostly you cannot write, except in /etc, which was sometimes attempted to be moved to /var...)

Bureaucrats like the Linux Foundation (which absorbed the Free Standards Group ages ago during expansion) happily document and complicate these rules, without even attempting to understand why they came about. They have no clue that Ken and Dennis simply moved part of the OS to their home directory because the RK05 disk on the PDP-11 was too small.

I am almost certain that busybox simply places files as it has historically developed. There is no real reason to keep doing it this way. Personally, I just make /bin, /sbin, and /lib symlinks to their corresponding directories in /usr. After all, people who work with embedded software try to understand and simplify...

Source: habr.com

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster