The first step towards understanding operating systems is to know about the way harddisks are organised - stuff like partitions, filesystems, etc. This is also useful in order to understand how partitions are to be created during installation, and how Linux is able to co-exist with other operating systems.
On a computer, data is managed in terms of files and directories on the external storage devices such as hard disks, CD-ROM's, floppy disks and others. Files are nothing but a special way of storing data on the external storage device in fashion that facilitates easy retrieval and updating. Similarly, directories are structures that can be thought of as logical "containers" for files; one or more files can be placed "inside" a directory. This allows a hierarchical management of files so that it becomes easier to keep track of them as more and more files are added to the system.
Understanding how Linux stores and manipulates files involves a little more knowledge about how files are organized inside the directories and how these are stored in the hard disk. The next few sections deal with these concepts and also provide some insight into disk partitioning which is an important step in Linux installation.
The file-system is the way an operating system manages all the files to be stored on the external storage - binaries, images, etc. Linux uses an advanced version of the Extended File-system from Unix, called ext2. This system uses data-structures called inodes to store information about files. All such inodes are placed together in bigger structures called inode tables. The inode tables are located at a well-known place on the storage device, so that the system can refer to them whenever it needs to access a file. The files are stored in the form of data blocks on the disk, which are accessed using pointers provided by the inodes.
The inodes also contain information that is used by the operating system to implement its security features for a multiuser environment, ie, they are used to establish ownership and to specify the way in which different users can share the same files. An important feature of the ext2 file-system is that it treats everything as files - directories are also represented as files containing pointers to other files. This does not stop only at directories, even the hardware can be addressed as files under the standard directory /dev. More about these directories later ...
One drawback in Linux has been the susceptibility of ext2 to damages due to power failures. But there has been significant development to rectify this shortcoming through the introduction of journaling file-systems like reiserfs, ext3. A journaling file-system has the inherent capability to be recovered to a stable state in case of crashed due to power failures.
In Linux, different partitions need not be assigned special names to access them. This is because Linux uses a standard directory structure to take care of all partitions. This structure ensures that a particular file for a particular program will almost always be present at the same place on any machine running Linux.
Example 2-1. Example listing of directories under /
# du -Hms /* 5 /bin 4 /boot 1 /dev 5 /etc 23 /home 26 /lib 1 /lost+found 5470 /mnt 1 /opt 97 /proc 25 /root 5 /sbin 1 /tmp 1070 /usr 58 /var |
What we see are the directories created on the file-system by default, and which are considered to be standard for all installations. The figures at the beginning of the line indicate the size in MB of each directory. Let us take a look at some of the more important ones.
/dev is the directory through which all the devices on the machine are accessible as files. These include the serial terminals (COM ports), modem, mouse, sound card ... everything!
/var contains most of the "variable" data such as mails, log files, databases, etc.
/usr is where almost all the packages get installed. Discounting /mnt, it is the largest directory on the hard-disk. This directory itself has a pretty complicated sub-directory system used by the packages.
/etc contains all the configuration files, used by the operating system itself as well as various packages installed on the system.
/home contains the home directories for all the users created on the system.
/mnt is conventionally used as the base for all directories which are not part of the standard directory hierarchy. It is most commonly used to mount the cd-rom drives, floppy drives, non-Linux partitions, etc.
/root is the home directory of the privileged user or the system administrator, called "root".
On a normal home PC, there are two IDE ports, to which the CD-ROM drives and the hard disks are connected. One is called the primary IDE port and the other is called the secondary IDE port. Each port supports two devices of either type, which have to be specified using jumpers as "Master" and "Slave". These devices can be CD-ROM drives or hard discs or combinations, on either port. The devices are labeled as follows:
/dev/hda -> Primary Master
/dev/hdb -> Primary Slave
/dev/hdc -> Secondary Master
/dev/hdd -> Secondary Slave
A hard disk can have two types of partitions - primary and extended - upto a total of four. You can create four primary partitions or three primary and one extended. All of these are numbered between 1 to 4. The extended partition in turn can contain any number of logical partitions which are numbered from 5 onwards. This particular partition may be any one of the first four, ie, the primary partitions. It provides a lot of flexibility for creating a large number of partitions.
Example 2-2. A simple partition listing
# fdisk -l /dev/hdc Disk /dev/hdc: 255 heads, 63 sectors, 1048 cylinders Units = cylinders of 16065 * 512 bytes Device Boot Start End Blocks Id System /dev/hdc1 * 1 128 1028128+ b Win95 FAT32 /dev/hdc2 129 833 5662912+ 5 Extended /dev/hdc3 834 1024 1534207+ 83 Linux /dev/hdc4 1025 1033 72292+ 82 Linux swap /dev/hdc5 129 383 2048256 b Win95 FAT32 /dev/hdc6 384 638 2048256 b Win95 FAT32 /dev/hdc7 639 833 1566306 b Win95 FAT32 |
The column "Id" specifies the type of file-system hosted on a particular partition. Note the partition called "Linux swap" - this is used by the system for memory management. A popular thumb rule is that its size should be about twice the RAM on the machine, but a maximum of 100MB seems to be enough for most desktop PC's.
![]() | It seems rather unfair that only about 1.5 GB has been allotted to Linux on a hard disk of 8.6 GB. But it is interesting to note that Linux accomplishes a lot more in that space as compared to Windows installed on the rest of the hard disk! |
The earlier sections describe how the standard directory structure and the partition labeling on IDE devices. But the obvious question is what happens to the multiple partitions that a user might wish to create on his system? Does every partition have an entire directory structure as describe above?
The answer to this question is quite the opposite - instead of the directory hierarchy being present on every partition, the partitions themselves become part of a single hierarchy! The idea is that it is possible for the user to specify that a particular directory should be hosted on a particular partition. Thus all the files and sub-directories of that directory will reside on that particular partition, unless of course, some particular sub-directory has been allotted its own separate partition! This might be more clear with an example.
Consider from the above directories, that you are currently working in /home/anamik. For some reason you want to move to /usr/doc, which you do by saying cd /usr/doc at the prompt. But suppose the system has two partitions, where the whole root file-system / resides on Partition1 while everything under /usr resides on Partition2. If you try the above command, the system will transparently take you to Partition2, and so that you never realise that you have actually crossed partitions while changing the current directory!
All this is accomplished by mounting the partition in their intended place. It can be considered to be like placing a pointer in the directory hierarchy, which indicates the partition where the directory actually resides. For this we need to know a few things first - the device name of that partition and its file-system type. We also need to make sure we know where we want to place the partition in the overall directories and ensure that such a blank directory exists.
Example 2-3. Mounting a customized data partition
Consider for example that you create a 1GB partition, which you want to use to store your data. This can be done on the command line in the following steps -
Create a blank directory as a mount-point for the partition, normally under /mnt.
# mkdir /mnt/data |
Mount the partition (let us assume /dev/hdc3) at the newly created mount-point.
# mount -t ext2 /dev/hdc3 /mnt/data |
![]() | Further exploration |
|---|---|
There is a lot more to mount than what we have seen just now. The man-pages provide detailed information about mounting partitions, which can be accessed by doing a man mount at the prompt. An important point to note is the file /etc/fstab which is used to control all the options for mounting various types of partitions. |
Linux can also support filesystems used by other operating systems. All that needs to be done is to mount them under a suitable mount-point, and now the user can access these partitions just like any other. Consider a pre-existing MS Windows installation for example - the partitions may be mounted under suitable directories in /mnt. Modern distributions are able to detect such partitions and prompt the user for mount points during installation. eg, the C-drive may be mounted as /mnt/c and so on. All this information is written in /etc/fstab, which is accessed at boot time to determine which partitions need to be mounted.
Example 2-4. Example listing of mounted partitions
$ mount /dev/hdc3 on / type ext2 (rw,noatime) none on /proc type proc (rw) /dev/hdc1 on /mnt/c type vfat (rw) /dev/hdc5 on /mnt/d type vfat (rw) /dev/hdc6 on /mnt/e type vfat (rw) /dev/hdc7 on /mnt/f type vfat (rw) none on /dev/pts type devpts (rw,gid=5,mode=620) |
Here we see a number of partitions along with their mount points and filesystems. All the mount points were specified during installation, where the letters c, d, ... were used for the corresponding MS Windows partitions. The brackets at the end of each line represented options used for that partition. The default one's are different from what you see here. These options can be changed by editing the /etc/fstab file.
Thus far we have seen how partitions and file-systems work under Linux. Now we can move on to an important part of the installation process, which is creating partitions.
The simplest case is to have gigantic partition spanning the entire hard-disk. But this would be a very bad strategy since the time taken to check the file-system would be enormous. Also if the hard-disk crashes, all the data could be lost in a single blow. Also in case of desktops, its very likely that the machine will be used as a dual-boot system with other operating systems. This means that there is a need for not just multiple partitions but also diverse file-systems existing on them. And then of course, there is the swap partition, which is used for memory management by the Linux system. Seems there is no way to survive without dirtying up your hands with partitioning stunts during installation, after all ...
Its generally a good idea to create separate partitions for the /home and /var directories since they contain user data. The /usr directory might also be separted, since it is the largest directory in the whole hierarchy. All the non-standard partitions are normally mounted under /mnt. But this a convention rather than a rule. But it's necessary that /etc be a part of the root partition, because some system utilities need to read files from this directory even before other partitions are mounted at boot-up time.
![]() | Dual boot systems |
|---|---|
In case of a dual-boot system using LILO, the /boot partition if it exists or else the root partition / should exist within the first 1024 cylinders of the hard-disk due to a limitation on the current versions of LILO. |
![]() | Further exploration |
|---|---|
Most modern installations provide an extremely user-friendly way of creating partitions and specifying their mount-points. Be sure to go through the installation manual about this. |