Friday, August 27, 2004

Linux Filesystem

A filesystem is a method for storing and organizing computer files and the data they contain to make it easy to find and access them. Filesystems may use a storage device such as a hard disk or CD-ROM and involve maintaining the physical location of the files, or they may be virtual and exist only as an access method for virtual data or for data over a network (e.g. NFS).


Like UNIX, Linux chooses to have a single hierarchial directory structure, everthing starts from the root directory represented by / and then expands into the subdirectories. Some or all of the following directories, or symbolic
links to directories, are required in /.
/the root directory
/bin
Essential command binaries - /bin directory contains several useful commands that are of use to both the system administrator as well as non-privileged users. It usually contains the shells like bash, csh, etc.... and commonly used commands like cp, mv, rm, cat, ls
/bootStatic files of the boot loader contains files required for booting process
/dev
It is a very interesting directory that highlights one important aspect of the Linux filesystem - everything is a file or a directory. hda1, hda2 etc.... - which represent the various partitions cdrom & fd0 - CDROM & floppy drive This may seem strange but it will make sense if you compare the characteristics of files to that of your hardware. Both can be read from and written to. Take /dev/dsp, for instance. This file represents your speaker device. Any data written to this file will be re-directed to your speaker. If you try 'cat /boot/vmlinuz > /dev/dsp' (on a properly configured system) you should hear some sound on the speaker. That's the sound of your kernel! A file sent to /dev/lp0 gets printed. Sending data to and reading from /dev/ttyS0 will allow you to communicate with a device attached there - for instance, your modem.
/etcHost-specific system configuration
This is the nerve center of your system, it contains all system related configuration files in here or in its sub-directories. A "configuration file" is defined as a local file used to control the operation of a program

/initrdinitrd is mainly designed to allow system startup to occur in two phases, where the kernel comes up with a minimum set of compiled-in drivers, and where additional modules are loaded from initrd
/lib
The /lib directory contains kernel modules and those shared library images (the C programming code library) needed to boot the system and run the commands in the root filesystem, ie. by binaries in /bin and /sbin. Libraries are readily identifiable through their filename extension of *.so. Windows equivalent to a shared library would be a DLL (dynamically linked library) file. They are essential for basic system functionality.

/lost+found
Linux should always go through a proper shutdown. Sometimes your system might crash or a power failure might take the machine down. Either way, at the next boot, a lengthy filesystem check (the speed of this check is dependent on the type of filesystem that you actually use. ie. ext3 is faster than ext2 because it is a journalled filesystem) using fsck will be done. Fsck will go through the system and try to recover any corrupt files that it finds. The result of this recovery operation will be placed in this directory. The files recovered are not likely to be complete or make much sense but there always is a chance that something worthwhile is recovered.

/media
Mount point for removeable media This directory contains subdirectories which are used as mount points for removeable media such as floppy disks, cdroms and zip disks
/mnt
Mount point for mounting a filesystem temporarily This is a generic mount point under which you mount your filesystems or devices. Mounting is the process by which you make a filesystem available to the system. After mounting your files will be accessible under the mount-point. This directory usually contains mount points or sub-directories where you mount your floppy and your CD.Standard mount points would include /mnt/cdrom and /mnt/floppy.
/opt
Add-on application software packages This directory is reserved for all the software and add-on packages that are not part of the default installation. For example, StarOffice, Kylix, Mozilla and WordPerfect packages are normally found here.
/proc
is very special in that it is also a virtual filesystem. It's sometimes referred to as a process information pseudo-file system. It doesn't contain 'real' files but runtime system information (e.g. system memory, devices mounted, hardware configuration, etc). For this reason it can be regarded as a control and information centre for the kernel.

/sbin
Essential system binaries /sbin should contain only binaries essential for booting, restoring, recovering, and/or repairing the system in addition to the binaries in /bin. Normally, these directories are never part of normal user's $PATHs but only of roots. Some of the commands are shutdown, fastboot, etc.
/srvData for services provided by this system
/tmpTemporary files
This directory contains mostly files that are required temporarily. Many programs use this to create lock files and for temporary storage of data. 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.

/usrSecondary hierarchy - /usr usually contains by far the largest share of data on a system. Hence, this is one of the most important directories in the system as it contains all the user binaries, their documentation, libraries, header files, etc.... X and its supporting libraries can be found here. User programs like telnet, ftp, etc.... are also placed here.
/varVariable data -
Contains variable data like system logging files, mail and printer spool directories, and transient and temporary files. Some portions of /var are not shareable between different systems. For instance, /var/log, /var/lock, and /var/run. Other portions may be shared, notably /var/mail, /var/cache/man, /var/cache/fonts, and /var/spool/news.

/homeUser home directories (optional)
Linux is a multi-user environment so each user is also assigned a specific directory that is accessible only to them and the system administrator. These are the user home directories, which can be found under '/home/$USER' (~/). It is your playground: everything is 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 switch. If there is a conflict between personal and system wide configuration files, the settings in the personal file will prevail.

/rootHome directory for the root user (optional)

While using different flavors of Linux (also called various distributions). Some distributions put mount directories for external media into the / directory,others 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 into /usr.

If you, say, install a KDE RPM from the SuSE Linux distribution on your Mandrake system, the binary will be put into /opt/kde2/bin. And thus it won't work, because Mandrake expects it to be in /usr/bin.

These problems will not arise once you get accustomed to the specific flavor and start liking it. Once you get a chance to know other flavors you will start knowing the difference. All the leading Linux distributors have joined the Linux Standard Base (LSB) project, which is attempting to create a common standard for Linux distributions. This isn't easy, since changing the file system hierarchy means a lot of work for distributors so it will take time but once a standard has been created then there will be no more hassels in understanding the Linux Filesystem.

Still hungry for more information on Linux Filesystem ? Click here to find out more.