File System

Revision / Modified: Apr. 20, 2002
Author: Tom Berger

Original documents:
http://www.mandrakeuser.org/docs/basics/bfiles.html http://www.mandrakeuser.org/docs/basics/bfiles2.html http://www.mandrakeuser.org/docs/basics/bfiles3.html http://www.mandrakeuser.org/docs/basics/bfiles4.html

General Characteristics

Operation systems of the Unix family feature a file system order that is

Hierarchy here means that the directory tree is indeed one tree. Directories follow a designed order starting from the root directory ('/') instead of having so-called 'drives'.
Within MS Windows, you may put your files (almost) anywhere: on 'C', 'D', 'E' etc. Hierarchical structures are managed by the programs themselves ('program directories') and not by the operating system.
Unix (and therefore Linux) on the other hand sorts directories ascending from the root directory '/' according to their importance for the boot process. And here it is the operating system that determines into which directories programs have to put their files into. Directories are not program- but function-specific.

If you install a program in MS Windows, it usually stores most of its files in its own directory structure. A help file for instance may be in 'program name\' or in 'program_name\help' or in 'program name\hoopy\frog\turnip'.
In Linux, programs put their documentation into '/usr/share/doc/program_name', man pages into '/usr/share/man/man[1-9]', info pages into '/usr/share/info'.That is they are merged with the system hierarchy.

Reasons And Consequences

One reason for this arrangement is that a centralized file system hierarchy is much easier to administer. For instance changes on one machine can be easily transferred to the clients on the network.

A consequence of this structure is the concept of partition mounts which usually confuses new users. All GNU/Linux partitions on your hard drive are mounted to ('hooked into') mount directories (aka 'mount points'). And you access them via these directories ('/' or '/usr' or '/mnt/cdrom' etc). This assures a seamless integration into the system, regardless if the mount is a local partition or one on the network server. And the mount names stay the same, if there are partitions or external media mounted to them or not. In contrast to Windows, where an additional local 'drive letter' changes all the 'drive letters' behind it and networked partitions are handled as extra 'drives'.

Another reason is that Linux caches a lot of disk accesses using system memory while it is running to accelerate these accesses.
It is therefore vitally important that these buffers are 'flushed' (i.e. get their content written to disk), before the system closes down. Else files are left in an 'undetermined state'. And that's a very bad thing for files to be left in.
Flushing is achieved by 'unmounting' the partitions during proper system shutdown. Don't switch your system off while it is running! You may get away with it quite often, since the Linux file system is very robust, but you may also wreak havoc upon important files. Just hit <CTRL ALT DEL> or use the proper commands (e.g. init 6) / buttons. This will shut down the system in a decent way and reboot it. And thus guarantee the integrity of your files.

Current Problems

So far, I've told you how it should be. Now about how it is in the real world ;-).

As you will see on the following pages, the implementation of this concept on Linux isn't perfect. Some people would even say it's far from perfect.
Linux has always attracted individualists. And these people tend to have their own opinion about a great many things, like for instance into which directories certain files should be put into. With the arrival of different distributions, these different opinions became manifest. Some distributions put mount directories for external media into the 'root' directory, others - like Mandrake Linux - into '/mnt'. Red Hat based distributions feature the '/etc/sysconfig' sub-hierarchy for configuration files concerning input and network devices. Other distributions do not have this directory at all and put the appropriate files elsewhere or even use completely different mechanisms to do the same thing. Some distributions put KDE into '/opt/', others - like Mandrake Linux - into '/usr'

But even within a given file system hierarchy, there are inconsistencies. The graphical subsystem, XFree86, has its own directory hierarchy, for example. The hierarchy has not so much been designed as 'grown'. So there are weeds.

This isn't much of a problem as long as you compile programs yourself: you can then adapt their configure scripts or Makefiles to your system's configuration. But it's different if you install pre-compiled packages like RPMs. Often these are not adaptable from one file system hierarchy to another. What's worse: some RPMs might even create their own hierarchy. If you, say, install a KDE RPM from the SuSE Linux distribution on your ML system, the binary will be put into '/opt/kde2/bin'. And thus it won't work, because ML expects it to be in '/usr/bin'.

There are of course ways to circumvent this problem (discussed in the article on RPM), but the current situation clearly is unsatisfying. Therefore all the leading GNU/Linux distributors have joined the Linux Standard Base project, which is currently trying to create a common standard for GNU/Linux distributions. As you might imagine, this isn't easy, because changing the file system hierarchy means a lot of work for distributors. And so every distributor tries to push a standard which will allow him to keep as much of his own hierarchy as possible ...

The LSB will also encompass the proposals made by the File system Hierarchy Standard project (FHS, former FSSTND). Starting with 7.2, Mandrake Linux has taken some pains to reorganize its file system hierarchy for greater FHS and LSB compliance. These changes will be discussed on the next pages, too.

The Root Directory

The Linux file system starts with '/', the root directory. All other directories are 'children' of this directory. The partition which the root file system resides on is mounted first during boot and the system won't boot if it doesn't find it.

In Mandrake Linux, '/' contains these sub-directories:

/bin
'/bin' contains essential system programs that must be available even if only the partition containing '/' is mounted. This may be necessary if you have to repair other partitions. It also contains programs which the boot script '/etc/rc.d/rc.sysinit' relies on.
/boot
Home of the kernel, the System.map, GRUB's configuration files, and other important boot files.
/dev
'/dev' contains the device files. Unix handles all In/Out operations via files (e.g. a file sent to '/dev/lp0' gets printed). Evidently these are needed during boot for hardware initialization.
/etc
All important system-wide configuration files are in here or in one of its sub-directories.
/home
Here are the users' home directories located. In pre-ML 7.2 releases, it also contained the serving directory of the Apache web server ('/home/httpd').
/lib
Essential libs needed for basic system functionality. Kernel modules ('drivers') are in the subdirectory '/lib/modules/$(uname -r)'.
/lost&found
If a file system check discovers any 'loose' file fragments, it puts them in here. Each partition has its own 'lost&found' directory.
If you find files in there, try to move them back to their original location. If you find something like broken symbolic link to file, you have to reinstall the file(s) from the corresponding RPM, since your file system got damaged so badly that the files were mutilated beyond recognition.
/mnt
By convention '/mnt' contains the directories external media and non-system partitions are mounted to, like '/mnt/floppy' or '/mnt/cdrom'.
/proc
'/proc' is a bogus file system. It doesn't contain 'real' files but runtime system information (e.g. system memory, devices mounted, hardware used etc.). You can read most of these files with 'less' (More on processes).
/root
This is the home directory of the System Administrator, 'root'. This may be somewhat confusing ('root on root') but in former days, '/' was root's home directory (hence the name of the Administrator account). To keep things tidier and safer, 'root' got his own home directory.
Why not in '/home'? Because '/home' is often located on a different partition or even on another system and would thus be inaccessible to 'root' when - for some reason - only '/' is mounted.
/sbin
Unix discriminates between 'normal' executables and those used for system maintenance or administrative tasks. The latter reside either here or - the less important ones - in '/usr/sbin'. For security reasons, these directories are not part of users' PATHs, only of 'root's.
/tmp
This directory contains, um, well, temporary files ;-). Do not remove files from this directory unless you know exactly what you are doing! Many of these files are important for currently running programs and deleting them may result in a system crash. Usually it won't contain more than a few KB anyway.
/usr
'/usr' usually the largest chunk of data on a system. It contains all files that might be shared by the users of a system during normal operation, like executables, documentation, libraries or the X system.
/var
Contains variable data like system logging files, mail and printer spool directories. Why not put it into '/usr'? Because there might be circumstances when you want to mount '/usr' as read-only, e.g. if it is on a CD or on another computer (amazing what one can do with Linux, isn't it? ;-)). '/var' contains variable data, i.e. files and directories the system must be able to write to during operation, whereas '/usr' should only contain static data.

Some of these directories can be put onto separate partitions or systems, e.g. for easier backups, due to network topology or security concerns. Other directories have to be on the root partition, because they are vital for the boot process.
'Mountable' directories are: '/home', '/mnt', '/tmp', '/usr' and '/var'. Essential for booting are: '/bin', '/boot', '/dev', '/etc', '/lib', '/proc' and '/sbin'.

/etc

'/etc' is the nerve center of your system, it contains all system related configuration files.

Some important subdirectories:

/etc/X11/
This directory contains all the configuration files for the X Window System, like 'XF86Config(-4)', the X server's configuration file, 'fs/config', which controls the X font server, or 'xdm/' and 'xinit/' which contain important initialization files.
/etc/cron[...]/
These directories contain scripts to be executed on a regular basis by the cron daemon.
/etc/menu-methods/
That's the place where the desktop menu system can be configured centrally.
/etc/pam.d/
This directory is the home of the configuration files for the Pluggable Authentication Modules.
/etc/postfix/
'/etc/postfix/' holds your 'postfix' configuration files.
/etc/ppp/
That's the place where your dial-up configuration files go to.
/etc/rc.d/
This contains all the files necessary to control system services and configure runlevels.
/etc/security/
This is the nerve center of MSEC, LM's own security level system.
/etc/skel/
Files in this directory are automatically put into every new user's home directory.
/etc/sysconfig/
This directory contains configuration files for the boot process, like 'clock', which sets the time-zone, or 'keyboard' which controls the keyboard map. The subdirectory 'network-scripts/' holds - among others - configuration files for network interfaces ('ifcfg-*').
/etc/xinet.d/
Services controlled via xinetd put their configuration file here.

Some network configuration files in /etc

Some system configuration files in /etc

And many, many more. I suggest that you should browse this directory, it will teach you a lot about your Linux system and how you can customize it!

/home

'/home/$USER' (aka '~/') is your playground: everything's at your command, you can write files, delete them, install programs etc.
Your home directory contains your personal configuration files, the so-called dot files (their name is preceded by a dot). Personal configuration files are usually 'hidden', if you want to see them, you either have to turn on the appropriate option in your file manager or run 'ls' with the '-a' option. If there is a conflict between personal and system-wide configuration files, the settings in the personal file will prevail.
'/home' can get quite large (mine is about 400 MB) and can be used for storing downloads, compiling, installing and running programs, your mail, your collection of image or sound files etc.

/var

'/var' holds 'variable' data like spool directories for mail and news, data bank data and log files.

/usr

"In the original Unix implementations, /usr was where the home directories of the users were placed (that is to say, /usr/someone was then the directory now known as /home/someone ).[...] In current Unices, /usr is where user-land programs and data (as opposed to 'system land' programs and data) hang out. The name hasn't changed, but it's meaning has narrowed and lengthened from "everything user related" to "user usable programs and data"."
(Lew Pitcher on /.)

The '/usr' directory contains the vast majority of files on every Linux box. All the programs go there, their documentation, their libraries, their header files etc.
At a first glance, the listing of this directory is really frightening. It is very easy to get lost in here.

/usr/X11R6

Another large subdirectory-structure begins here, containing libraries, executables, docs, fonts and much more concerning the X Window System.
Its inclusion here is somewhat inconsistent and so is the difference between '/usr' and '/usr/X11R6' directories. One would assume that programs that run on X only have their files in the '/usr/X11R6' hierarchy, while the others use '/usr'. Regrettably, it isn't so. KDE and GNOME put their files in the '/usr' hierarchy, whereas the window manager Window Maker uses '/usr/X11R6'.
Documentation files for X11R6 are not in '/usr/X11R6/doc', but primarily in '/usr/X11R6/lib/X11/doc' (one might not have guessed that, hum? ;-)).
This mess is due to the fact that in contrast to other operating systems, the graphical desktop isn't an integral part of the system. Linux is still primarily used on servers, where graphical systems don't make sense.

/usr/bin

This directory contains the vast majority of binaries (executables) on your system.

/usr/doc

In older releases, this was the central documentation directory. Current releases use '/usr/share/doc'.

/usr/etc

Theoretically, that's another directory for configuration files. Practically, I've yet to see a reason to use it.

/usr/games

Once upon a time, this directory contained network games files. It's rarely used nowadays.

/usr/i586-mandrake-linux/

Used to store some compiler related files.

/usr/include

The directory for 'header files', needed for compiling source code.

/usr/info

In older releases, this directory contained the files of the info documentation system. Now they are in '/usr/share/info'.

/usr/lib

This directory contains program libraries. Libraries are collections of frequently used program routines.

/usr/libexec

I would lie if I'd say I'd know what this directory is good for.

/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 to keep self-compiled or third-party programs in.

/usr/man

In older releases, this directory contained the man pages. Has been moved to '/usr/share/man'.

/usr/sbin

This directory contains programs for administering a system, meant to be run by 'root'. Like '/sbin', it's not part of a user's $PATH.

/usr/share

This directory contains 'shareable', architecture-independent files (docs, icons, fonts etc).

"Note, however, that '/usr/share' is generally not intended to be shared by different operating systems or by different releases of the same operating system.
Any program or package which contains or requires data that doesn't need to be modified should store that data in '/usr/share' (or '/usr/local/share', if installed locally). It is recommended that a subdirectory be used in /usr/share for this purpose."

(From the File system Hierarchy Standard)

/usr/src

The 'linux' sub-directory holds the Linux kernel sources, header-files and documentation. 'RPM/' provides a substructure for building RPMs from SRPMs.

/usr/tmp

Hey, look, another directory for temporary files! ;-) It's just a link to 'var/tmp/', though.

Well, I hope this was exhaustive enough for you. It sure was for me ;-).


Legal: This text is covered by the GNU Free Documentation License. Standard disclaimers of warranty apply. Copyright LSTB (Tom Berger) and Mandrakesoft 1999-2002.