*nix Filesystem Structure

Started by
10 comments, last by anonuser 18 years, 9 months ago
There's no "Operating Systems" forum and this seems to be a better fit than the lounge, so... Why, in *nix Land, is there:
/lib
/usr/lib
/usr/local/lib
/bin
/usr/bin
/usr/local/bin
/usr/include
/usr/local/include
What's with the three different levels? Is this NFS exploitation, /usr/lib mounted to server stuff, while /usr/local/lib is... local stuff? Just something that's bugged me. /usr is where the majority of your installed programs are going to end up, right? /me was born a DOS boy and will die a win(however far they stretch the architectures) man probably.
Advertisement
I believe this is mostly a side-effect of all the different POSIX flavors out there today. Even within a single OS like Linux, different distributions will tend to favor different variants on the basic filesystem. Since the actual hierarchy (and preferred use of it) is not standardized, people's personal subjective preferences end up creating a lot of variation and confusion.

For instance, /lib is for libraries that may be shared between many apps system-wide, while /usr/lib is for libraries shared between many user-space applications (at least that's how I understand it - no promises). An analogous thing happens with /bin for app binaries (/bin tends to be for system-wide utilities and shell commands while /usr/bin is more used by heavy-duty apps). The distinction between /usr and /usr/local seems to be almost entirely arbitrary from what my limited experience can tell me.


Also, for future reference, we do have an Everything Unix forum, wayyy down towards the dark, mysterious bottom half of the forum list [wink]

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Well, there is a "everything *nix" forum. [smile]

And to answer your question, everything that is essential to running the system is in the base (/bin and /lib), everything that is managed by the package manager and is "extra" user stuff like X windows, SDL, gtk, etc. goes in /usr/bin and /usr/lib and everything that you do yourself and is not managed by the package manager (make install a game) goes in /usr/local.

It is three different levels and there is sometimes mix-up between /usr and /usr/local.
So when I get my latest Linux server up and running in the next few weeks (distro as of yet undefined) apps I download to install, if not automatically taken care of, would go into /usr/local and /usr/local/bin, but development libraries would probably be better in /usr/lib and /usr/include and stuff like that?

Previous Linux servers have been experimental at best; actually all of my Linux systems to date have been experimental workstations more than servers, but this one is going to be a dedicated box. I hear Slackware is a good server distribution.
Just in case you haven't found it:

File System Hierarchy
Quote:Original post by Omaha
There's no "Operating Systems" forum and this seems to be a better fit than the lounge, so...

Why, in *nix Land, is there:

/lib/usr/lib/usr/local/lib/bin/usr/bin/usr/local/bin/usr/include/usr/local/include


What's with the three different levels? Is this NFS exploitation, /usr/lib mounted to server stuff, while /usr/local/lib is... local stuff?


It's designed to ALLOW (not necessitate) mounting on multiple partitions, in part - originally the /usr/local vs /usr bit was NFS based. However, these days /usr/local is usually used for non-package-manager installed files, whereas /usr is used for package-manager-installed files:

Quote:TLDP: Linux Filesystem Hierarchy
/usr/local

The original idea behind '/usr/local' was to have a separate ('local') '/usr' directory on every machine besides '/usr', which might be just mounted read-only from somewhere else. It copies the structure of '/usr'. These days, '/usr/local' is widely regarded as a good place in which to keep self-compiled or third-party programs. The /usr/local hierarchy is for use by the system administrator when installing software locally. It needs to be safe from being overwritten when the system software is updated. It may be used for programs and data that are shareable amongst a group of hosts, but not found in /usr. Locally installed software must be placed within /usr/local rather than /usr unless it is being installed to replace or upgrade software in /usr.


/bin, /lib, /etc, and other root level directories are mainly for system cricital things like ls, mount, their config files, their shared libraries, etc (/etc seems to bend this rule, as apache and mysql among other programs put their configs here).

/usr/* equivilants are less critical userland things, like apache, yacc, make, gcc, etc, installed by the PACKAGE MANAGER (e.g. installed by APT or RPM).

/usr/local/* is just like /usr/*, only for non package managed files. If you create a basic bash install script, it should install to /usr/local/*.

Quote:Just something that's bugged me. /usr is where the majority of your installed programs are going to end up, right?


Right.

For more information see The Linux Documentation Project: Linux Filesystem Hierarchy
Righto, righto, think I'm getting it clear now.

I remember hearing that bit about stuff directly off the root being the "essentials" but apparently forgot. Whoops.
Typically the stuff in /bin, /lib etc, is stuff required to boot into single-user mode.

In single user mode, it's possible (although unlikely on a modern system) that /usr won't be mounted - the system should still be able to boot to a shell, and do enough that the administrator can run some diagnostics and/or fix the problem.

The other rationale, is that on networked systems, /usr is shared between several machines (/usr/share between ones of different architecture, but more rarely).

/usr is likely to contain a lot more files than /bin,/lib, /etc, put together. Therefore, there is some perceived advantage in putting it on a shared storage medium (save local disc space, make updating easier).

These arguments are now mostly obsolete, with the advent of cheaper storage (i.e. ludicrously cheap storage).

Also, package managers tend to like to tweak everything locally.

But it still applies in principle at least.

/usr/local could be nfs mounted even on a modern system - and shared between many machines. This would mean that "local" software would only need to be installed once.

Mark
don't forget about chroot jailing
Quote:Original post by markr
In single user mode, it's possible (although unlikely on a modern system) that /usr won't be mounted - the system should still be able to boot to a shell, and do enough that the administrator can run some diagnostics and/or fix the problem.


In fact, on modern *BSD systems when you boot single-user the only devices mounted are '/' and the swap partition, and '/' is mounted read-only.

This topic is closed to new replies.

Advertisement