Home Classroom Linux Basics Linux Basics Part 4

Linux Basics Part 4


File System Hierarchy – Structure

Let me first apologize for the unavailability of the Linux article in last diGIT issue. On the bright side that could have given you plenty of time to get yourself comfortable with moving around a Linux file systems. Before we wander to different ares, let us wait a minute and revisit the file system.

By now, you already know how to move around in a Linux/Unix file system fairy easily. However you might be wondering about unfamiliar names and a different directory structure than you might have seen before. So let us venture in and have a more educated look.

If you remember correctly the Root directory included many other directories with interesting names like bin, var, usr, tmp, etc. Did you wonder if they were the result of creative naming or if it had a rationale behind it? The answer is that there is a rationale for why the directories are named in the particular manner.



A brief history of file system hierarchy in Linux

Traditionally Unix file systems had a hierarchically structured directory structure. As we discussed in the last issue, everything starts from the single called the Root of the file system (note as “/”). With time many variation of Unix systems were designed and implemented, including Linux. Since historically Unix lacked a common official standard, the structure of the directory organization usually had own touches of the individual distributions. This fragmentation was widened with the advancement of the technology. For example when the earlier Unix/Linux systems were designed, removable media optical (Eg: CD, DVD) or magnetic (Eg: hard disks, floppy diskettes) weren’t around as much as they are today. So naturally people went in different ways to organize things.

To overcome these problems on the then new found Linux, a release of a tentative standard was made in 1994. From that point onward it has been developing. As of this writing, the file system hierarchy standard (known as FHS) is at version 2.3 which was release in 2004. This standard document is not a set of golden rules, but rather a convention. As Linux is as customizable as you want to, there is no one to stop you from using whatever convention for the directory structure. However most of the major Linux distributions tend to adhere to FHS, at least for a certain level


FHS Organization

We are not going to discuss FHS in detail here. If you are interested in learning more about this standards and related information you could always visit the web site at: http://www.pathname.com/fhs/

So let us now take a more detailed look at a typical directory structure. Here we can discuss what are these directories actually meant for generally.

The root directory (/) is the root of the hierarchy. The bin and sbin directories are to hold the command binary files. The bin directory is the place to find the essential command binary files such as ls, cp, mv, rm and cat. As you might have already guessed, what we call a command binary is which is the executable file for the particular command. While bin holds the essential command binaries, the sbin directory holds systems command binaries which usually requires Superuser (administrator/root user) privileges to execute. This directory may typically hold commands such as mount, init, route, mkfs and modprobe.

The directory named “dev” is the place where a Linux systems holds the files representing devices. It includes files representing hardware (Eg: hda1, sda, ttyS0 and sr0) and also holds special device files required by the system (Eg: null, zero, random and urandom). While the special systems related device files tend to be the same in every systems, the hardware related device files differ from system to system based on the available hardware. For example a systems with only IDE disks will have devices starting with hd in their names (Eg: hda1, hdb1, hdc4) while systems with S-ATA or SCSI disks will have devices with names starting from sd (Eg: sda1, sdb3, sdc2).

The directory “/home” is the place where a normal user would spend most of the time. Usually in a Linux system a regular user will be allocated a home directory under “home”. This means, if your computer has many user accounts they each will have a home directory under “home”. For example my home directory is “/home/gaveen” while a user account named student may have her home directory located under “/home/student”.

While rest of the users have their home directories located under “/home” the super user (root) does not have a home directory there. The home directory of the user “root” is isolated from other home directories in “/root”. You can see that appearing in our directory listing in the example 1.

In the same listing you might have noticed a directory named “boot”. This is a very important directory in a Linux file system. The “boot” directory holds the files necessary for the boot process of the system. This usually hold the boot loader files, the operating system kernel and several more files. Because of the critical nature of this directory for the boot process, it is usually gives a separate disk partition.

The “tmp” directory which is pronounced “temp” is the place where a Linux systems holds temporary data. The content of this directory is cleaned periodically or during reboot (depending on the configuration). So it is not advisable to put anything important or anything you need to be persistent there.

The “var” directory holds data that is variable (changing). For example “var” is the place where log files, temporary e mail stores, printer spools are kept. If you have database management systems running, “var” is usually the place to hold that data too.

The “mnt” (pronounced “mount”) is a place which is kept to mount file systems temporarily. Do not worry about the new term “mount”. It is a little more advanced concept which we will be discussing shortly in this Linux article series. Few years ago “/mnt” was used to mount removable media such as floppy disks, CDs and DVDs. However the Linux vendors gradually started using “mnt” for what it was originally meant. They adhered to the FHS and started using the “/media” directory to mount removable media including CD. DVD, USB flash drives, etc.

“proc” directory is a special directory as it is not a physical space consuming directory. The “/proc” is a virtual space where the status of the systems is represented in text files. Thus one can change the state of many system components by editing the text files in “/proc”.

The last directory we are going to describe is the one probably consuming the most disk space in your Linux installation. It is “/usr” which is pronounced as “user”. This is the place where user programs go. Which means this is the place where the bulk of the things from your OpenOffice.org, Firefox, etc. is stored. So if you plan to install a lot of software in your Linux system, make sure that there is enough space in the “/usr”.

As you can see Linux file system organization is a bit different than that of Microsoft Windows. However there is no denying that things are quite organized. This is the basic introduction to what the directories does. If you wish to learn more about to FHS and the directory organization, the Wikipedia article http://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard has much to offer.


Mounting a file system

In the previous section we have come across the term “mount” but there was no explanation given at that point. It might not be something you are already familiar with if you are from the Windows world. However if you have any previous knowledge about Unix systems there is a chance that you have heard about this.

Mounting is the concept of making a file system usable for the operating system. The term comes with a historical background where users had to physically mount a magnetic tape or a disk drive before using it. Even nowadays we have a similar thing going. An example would be using USB flash drives where you physically mount the device to the computer. What we call “mounting” happens after that. The device is read by the operating system and the file systems of the device is then mounted on the file systems of the running system. After that you are able to access the contents of the flash drive.

This is true to any file systems we can have. For example we can have disk partitions with a file systems which is not mounted by default. Consider the Windows system partition (usually identified as drive C: in the Windows world) is a multi-boot systems. It is there in the hard disk space but it is usually not accessible from the Linux system. If we want to access the Windows file systems we have to mount it.

As we know there is a place in the Linux file systems hierarchy to mount other file systems temporarily. If you are thinking of “/mnt” you are correct. In the scenario we are discussing, we can mount our Windows file system under “/mnt”. After this is completed successfully we can access the content of the Windows file system under “/mnt”. If there was a folder named “Windows” in your Windows file system, now it can be accessed as “/mnt/Windows”.

Let us take a little different scenario. Let us say that I have a hard disk with an old Linux installation which have four (4) disk partitions containing different Linux file systems.



Then suddenly I want to copy the photos from an old trip which is stored in my old hard disk, under the directory “home”. So I find and wipe the dust out from the old hard disk and plug it into my working computer. It is available as the device “sdb” inside the “/dev” of my working system. And now I am ready to copy the files. What would you suggest me to do? Here is what I did.

I needed to mount the file systems in the partition 3, which has a directory named “home” in it. To do this I had to have administrator privileges. Depending on the Linux distribution and version you are using the, the need to have administrator privileges may or may not be there. But as a general security practice, the ability to use the “mount” command (the command which is used to mount a file system) usually requires administrative privileges. So I used a command named “su” to switch to root user temporarily.

Note: We are not going to discuss “su” command in detail today, nor introduce it as a new command. The “su” command will be discussed in detail in a future article. For todays work enter the following command. While you are switched to the root user please only issue the commands in this following mounting section./p>

This is how to issue to su command to switch to root user. When asked for password enter the root/administrator password of the system.

[gaveen@ravana ~]$ su -




[root@ravana ~]#


Now that I was working temporarily as the use root, I went on to mount the file system.


New Command: mount

[root@ravana ~]# mount /dev/sdb3 /mnt


[root@ravana ~]# cd /mnt


[root@ravana ~]# ls




Let us try to understand what the above command does. In this command we tell “mount” command to use the device “/dev/sdb3″ and mount it on “/mnt”. I told you that the hard disk was using “/dev/sdb”. So it is perfectly natural for your to think “where did that sdb3 thing came from?”.

As the hard disk was “sdb”, the path to the device was “/dev/sdb”. But we specifically needed the Partition 3. That is where the “3″ in “sdb3″ come into play.

If the mounting is successful, usually you don’t get an output message. After I mounted the file system in the partition 3 of my old hard disk on “/mnt”, I could easily copy the files I needed. After the mount this is how my directory structure looked like.


Using “mount” command without any parameters and options will give you an output of already mounted file systems. Let us see an example.

Eg 2:

[root@ravana ~]# mount


/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)


proc on /proc type proc (rw)


/dev/mapper/VolGroup00-LogVol02 on /home type ext3 (rw)


/dev/sda1 on /boot type ext3 (rw)


/dev/sdb3 on /mnt type ext3 (rw)
The actual output you would see in your system should differ from the above example. However the pattern will remain the same.

In the above output we can see that our mounting operation was successful, because there is a line saying “/dev/sdb3 on /mnt type ext3 (rw)” (last line). Do not worry about the other details available in the output. We just wanted to make sure that the mounting was successful.

I hope now you have a fair understanding about the concept named “mounting”. Once you mount a file systems you will need to unmount them too. This is how you do it.


New Command: umount

The command “umount” does the opposite of mounting, that is unmounting. To do so first make sure you have all terminals, windows, dialog boxes opened from the file system you want to unmount (in this case: “/mnt”). Make sure you have no open files or there is no running operations from that file systems. If any of the above are still there, the unmounting would fail. Once you are ready to do the unmount operation there is the command to use.

[root@ravana ~]# umount /mnt


What we did was to tell the command “umount” to unmount the file system mounted under “/mnt”. Once you have unmounted you can run the “mount” command again and make sure it is not in the mounted file systems list


Next Issue

Congratulations for learning the more advanced concept of mounting. If you are not following this off the magazine, do not worry. It was provided here because I wanted you to understand what I meant by the term mount. It is a term you will often get to see in Linux guides, tutorials and other references. So I hope it will be useful for you in the future.

In the last two issues we have been talking about Linux file system hierarchy and organization and also the mount and umount commands. This is a lot digest for a new Linux user. So read well and let me know you feedback and any questions you have about the Linux article series so far. You can use the feedback form provided in the magazine for this purpose.

In the next issue we can move to the command line again and learn a few tricks and tips which would come handy (and also to impress your friends) when you work in command line.



Gaveen is a Linux System Administrator with several years of industry experience and is a strong FOSS promoter. He is pending graduation from University of Wolverhampton and also holds a certification from Red Hat. He also conducts Linux trainings with Red Hat training partners. Being highly enthusiastic about computing, he supports a keen interest in Ruby programming too. When not distracted by his wide range of interests including reading, music, cricket, etc.,he regularly blogs at Gaveen's Blog


Leave a Reply