Linux File System (Directory Structure)


In this post I will be talking about how different external media or different partitions of a hard disk can be accessed in Linux and also about the various directories you’ll find in  a typical Linux Installation and the types of files each of these directories contain.

The first thing you’ll need to know is that the entire file system in Linux comprises of a single main directory called the root(/) directory and every other directory is a sub-directory of the root directory. Linux does not represent different partitions as different drive letters as in Windows. The partitions are  “mounted” as different sub-directories under the root file system. The default mounting directory is the /mnt or the /media directory in most Linux distributions. The partitions can also be mounted to other directories under the root  other than the /mnt or /media directories, by manual configuration.

Don’t worry if you did not understand what “mounting” means. For now it suffices to understand that “mounting a partition to a folder” means simply to make the contents of the partition accessible by showing them in a specified folder.

So different partitions on the same hard disk or  various devices like USB sticks, External Hard Disks and CDs would be mounted to normal directories under the root directory, from where their files can be accessed or manipulated.

For example by mounting a CD to a subdirectory like /home/User1/Desktop/CD all the contents of the CD can be accessed through that directory.

So how does this system of mounting partitions and external media as sub-directories under the root directory make any sense?

Isn’t the Windows’ way of showing them as different devices and drives simple and easy? All the immovable files like the system files , installed program files , user home folders are all on the Windows’  partition (usually the C:\ drive) and all the other data which can be moved around without any problems, in the other partitions.

Simple and sweet right? Well it does seem simple but does that make the system flexible? Well not quite. Let’s see why.

Windows is very rigid with regards to the location of its files and the installed programs.They have to be on the same partition and the names and locations of the directories cannot be changed  without running into problems and the risk of system instability.

On a Windows system can you even fathom the thought of  having the “Program Files” folder on one hard disk, the Windows folder on another partition on a different hard disk while having the system32 folder on a network file system. It seems impossible doesn’t it? Well it is, on a Windows system. But not on Linux.

The mounting process  in Linux applies not only to external drives and other storage media but even to the system partitions that are essential to the running of Linux. They can be mounted from a different partition or from a different hard disk or even from a remote location on the network altogether.

Since partitions can be mounted as sub-directories, we can mount the directories required for the running of the system, from different partitions on the same hard disk or from different devices, or even from a network location, provided that all the partitions are mounted to the correct locations. The underlying kernel will not see the difference, since everything will seem like a single file system and it is oblivious to the fact that the different folders have been fetched from different locations.

 

FileSystemMountingLinux

 

So that’s the kind of advantage the Linux’s system of mounting file systems, has.Makes more sense now right?

Ok, enough about mounting.Wondering what “/usr”,”/etc”,”/home” in the above picture mean? We are going right to that topic now.

Let’s see what the different sub-directories of the root directory are and what types of files they contain.

Note: We will talk about the commands required to mount a device or partition in a different post.

The root directory is denoted by the forward slash “/”. The different sub directories under the root directory are as follows:

 

Directories

 

Some of the contents of the directories can be seen in the following tree structure

/
|—bin          The bin folder contains binaries(Executable files) that are used by the system as well as the users
|   |—bash
|   |– cat
|   |– chgrp
|   |– chmod
|   |– chown
|   |– cp
|   |– date
|   |– dd
|   |– df
|   |– dir
|   |– dmesg
|   |– grep
|   |– gzip
|   |– hostname
|   |– ip
|   |– kill
|   |– less
|   |– ln
|   |– login
|   |– ls
|   |– mkdir
|   |– more
|   |– mount
|   |– mv
|   |– ping
|   |– ps
|   |– pwd
|   |– rm
|   |– su
|   |– sync
|   |– tar
|   |– touch
|   |– uname
|   |– uncompress
|   `– which
|—boot    (The boot folder contains the bootstrap loader like LILO or GRUB and the Linux Kernel)
|   |– grub
|   |– initrd.img-2.6.31-20-generic
|   `– vmlinuz-2.6.31-20-generic          (This is the Linux Kernel)
|—dev           (The dev folder contains files representing the various hardware on the system and as well as
|   |—disk                                the different virtual consoles)
|   |– loop0
|   |– loop1
|   |– loop2
|   |– port
|   |– ppp
|   |– psaux
|   |– ram0
|   |– ram1
|   |– sda
|   |– sda1
|   |– tty
|   |– tty0
|   |– tty1
|   |– ttyS0
|   `– usbmon0
|
|—etc
|   |– X11
|   |– apache2
|   |– apt
|   |– cron.d
|   |– grub.d
|   |– hostname
|   |– hosts
|   |– inetd.conf
|   |– init
|   |– init.d
|   |– rc0.d
|   |– rc1.d
|   |– skel
|   |– sound
|   `– sysctl.conf
|– home
|   `– User1
|
|– lib
|   |– lsb
|   |– modules
|   |– security
|   `– terminfo
|
|– lib32
|   |– i486
|   `– i586
|
|– lib64
|– lost+found
|– media
|   |– New Volume
|   `– cdrom
|
|– mnt
|– opt
|   |– cxoffice
|   |– google
|   `– openoffice.org
|
|– proc
|   |– 1
|   |– 17052
|   |– 2685
|   |– 28
|   |– 5
|   |– 70
|   |– 9
|   |– acpi
|   |– cpuinfo
|   |– devices
|   |– driver
|   `– fs
|
|– root
|– sbin
|   |– alsa
|   |– dumpe2fs
|   |– fdisk
|   |– halt -> reboot
|   |– ifconfig
|   |– ifdown
|   |– ifup
|   |– init
|   |– iwconfig
|   |– iwevent
|   |– mke2fs
|   |– mkfs
|   |– partprobe
|   `– reboot
|
|– sys
|   |– block
|   |– bus
|   |– kernel
|   |– module
|   `– power
|– tmp
|
|– usr
|   |– bin
|   |– games
|   |– include
|   |– lib
|   |– local
|   |– man
|   |– info
|   |– sbin
|   |– share
|   `– src
|– var
    |– backups
|– cache
|– log
|– mail
|– spool
|– tmp
`—www

 

 

As you can see above, the

 

The /usr/sbin directory contains non-vital system utilities that are used after booting (i.e., starting the system) by the system administrator.

This is in contrast to the /sbin directory, whose contents include vital system utilities that are necessary before the /usr directory has been mounted (i.e., attached logically to the main filesystem).

/bin is a standard subdirectory of the root directory in Unix-like operating systems that contains the executable (i.e., ready to run) programs that must be available in order to attain minimal functionality for the purposes of booting (i.e., starting) and repairing a system.

 

/bin /sbin – required for booting    /usr/sbin –not reuired for booting

The /sbin and /usr/sbin directories are in the path (The standard location where the operating system searches for binaries to run commands) of the root user only but not for ordinary users since they are not meant for normal users without privileges.

 

 

 

/dev

. Look through this directory and you should see hda1, hda2 etc,
which represent the various partitions on the first master drive of the
system. /dev/cdrom and /dev/fd0 represent your CDROM drive and your 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. So any data written to this file will be re-directed to
your speaker. Try ‘cat /etc/lilo.conf > /dev/dsp’ and you should hear some
sound on the speaker. That’s the sound of your lilo.conf file! Similarly,
sending data to and reading from /dev/ttyS0 ( COM 1 ) will allow you to
communicate with a device attached there – your modem.

 

 

 

 

/etc

/etc – This directory contains all the configuration files for your system.
Your lilo.conf file lies in this directory as does hosts, resolv.conf and
fstab. Under this directory will be X11 sub-directory which contains the
configuration files for X. More importantly, the /etc/rc.d directory
contains the system startup scripts. This is a good directory to backup
often. It will definitely save you a lot of re-configuration later if you
re-install or lose your current installation.


Leave a Reply

Your email address will not be published. Required fields are marked *