Linux File System

Linux File System

A file system is used to control how data is stored and retrieved. Without a file system, information placed in a storage area would be one large body of data with no way to tell where one piece of information stops and the next begins.

Linux supports many different file systems, but common choices for the system disk on a block device include the ext* family (such as ext2, ext3 and ext4), XFS, JFS, ReiserFS and btrfs.

A file system journal keeps track of file write operations by first performing the write (like adding new files or changing the content of files) in a journal first. Then, it performs the write on the file system itself after which it removes the entry from the journal. This set of operations ensures that, if at any point the file system operation is interrupted (for example a power failure), the file system is able to recover when it is back up and running by either replaying the journal or removing the incomplete entry. In this way, the file system is always at a consistent state.

Linux uses an hierarchical file system, everything starts from what is called the ‘/’ directory (known as the root directory). This is the top most level of the file system and all other directories are placed at some level from here. Here is how the directory structure looks like:

Linux FileSystem

Directories that are only one level below the root directory are often preceded by a slash (/), to indicate their position and prevent confusion with other directories that could have the same name. When starting with a new system, it is always a good idea to take a look in the root directory. Let’s see what does these directories contain:

DirectoryContents
/binCommon programs, shared by the system, the system administrator and the users.
/bootThe startup files and the kernel, vmlinuz. In some recent distributions also grub data. Grub is the GRand Unified Boot loader and is an attempt to get rid of the many different boot-loaders we know today.
/devContains references to all the CPU peripheral hardware, which are represented as files with special properties.
/etcMost important system configuration files are in /etc, this directory contains data similar to those in the Control Panel in Windows
/homeHome directories of the common users.
/initrd(on some distributions) Information for booting. Do not remove!
/lib

Library files, includes files for all kinds of programs needed by the system and the users.

/lost+foundEvery partition has a lost+found in its upper directory. Files that were saved during failures (orphaned files) are here.
/miscFor miscellaneous purposes.
/mntStandard mount point for external file systems, e.g. a CD-ROM or a digital camera.
/netStandard mount point for entire remote file systems
/optTypically contains extra and third party software.
/procA virtual file system containing information about system resources. More information about the meaning of the files in proc is obtained by entering the command man proc in a terminal window. The file proc.txt discusses the virtual file system in detail.
/rootThe administrative user’s home directory. Mind the difference between /, the root directory and /root, the home directory of the root user.
/sbinPrograms for use by the system and the system administrator.
/tmpTemporary space for use by the system, cleaned upon reboot, so don’t use this for saving any work!
/usrPrograms, libraries, documentation etc. for all user-related programs.
/varStorage for all variable files and temporary files created by users, such as log files, the mail queue, the print spooler area, space for temporary storage of files downloaded from the Internet, or to keep an image of a CD before burning it.

File System in Reality

For most users and for most common system administration tasks, it is enough to accept that files and directories are ordered in a tree-like structure. The computer, however, doesn’t understand a thing about trees or tree-structures. Every partition has its own file system.

In a file system, a file is represented by an inode. Inode is a kind of serial number containing information about the actual data that makes up the file.

Inode describes a data structure on the hard disk, storing the properties of a file, including the physical location of the file data. When a hard disk is initialized to accept data storage, usually during the initial system installation process or when adding extra disks to an existing system, a fixed number of inodes per partition is created. This number will be the maximum amount of files, of all types (including directories, special files, links etc.) that can exist at the same time on the partition. We typically count on having 1 inode per 2 to 8 kilobytes of storage. The inodes have their own separate space on the disk.

At the time a new file is created, it gets a free inode. In that inode is the following information:

  • File size
  • Owner and group owner of the file.
  • File type (regular file, directory, link etc.).
  • Permissions on the file.
  • An address defining the actual location of the file data.
  • Date and time of creation, last read and change.
  • Date and time this information has been changed in the inode.
  • Number of links to this file.

The only information not included in an inode, is the file name and directory. These are stored in the special directory files. By comparing file names and inode numbers, the system can make up a tree-structure that the user understands. Users can display inode numbers using ls -i command.

[[email protected] ~]# ls -i
71199248 Files  71199238 One.txt
[[email protected] ~]#

Back



Microsoft Certified Professional | Cisco Certified Network Associate

Leave a Reply