×

Search anything:

Linux file system - an overview

Binary Tree book by OpenGenus

Open-Source Internship opportunity by OpenGenus for programmers. Apply now.

In this article we go over an overview of the Linux file system, this will give new Linux users an idea of how Linux stores, retrieves and manages data/files.

Table of contents.

  1. Introduction.
  2. File system architecture.
  3. Linux file systems.
  4. Summary.
  5. References.

Introduction.

The hard disk's only function is to store data and the only way to access this stored data is to specify its physical location(cylinder, head, sector) or logical location(block numbers) on the disk, however remembering sectors and block numbers is difficult. We need a way of filing information in an easily accessible way.
A file system is an organization of data and metadata on a storage device.

The Linux file system is implemented as a layered architecture and thus separates the UI layer from the file system implementation.

It controls how data is stored and retrieved by managing information such as file names, file sizes, modification and creation dates etc.

File system architecture.

A file system is responsible for providing a namespace to define how a file can be named and logical structure for data on the disk. Once these are defined, a metadata structure provides the logical foundation for the namespace.

Metadata may include structures to determine used and free blocks of space, maintain names of files and directories and their corresponding information such as size, modification dates, access times, other structures can store high-level information about logical volumes and partitions, high-level metadata structures will contain information about the stored file system on the drive or partition however, this is separated from the file system metadata.

APIs provide access to system calls which manipulate files and directories. They aid in tasks such as creation, moving, deletion of files. Algorithms are also implemented to account for speed and to minimize disk fragmentation.
A security model defines access rights to files and directories.

Finally the software that ties all these functions together. This software is a two part implementation so as to improve system and programmer efficiency.
The virtual file system provides a set of commands for the kernel and programmers to access all types of files systems.

The drivers interpret file system commands to the ones specified for the file system.

Linux file systems.

UNIX file systems have a similar general structure. Even though exact details vary, the central concepts remain the same. These are superblocks which will contain information about the file system e.g size, inode which will contain information about a file excluding its name since it is stored in the directory together with inode number, the inode will have data block numbers and if more are needed, space for pointers is allocated dynamically. Dynamically allocated blocks are referred to as indirect blocks and thus to find a data block, we first find the indirect block first.

There exist almost 100 types of Linux file system each defining how data is stored and accessed.

Some of linux's file systems are, minix, vfat, ext, ext2, ext3, ext4, msdos, fat, ntfs, reiserfs, xfs, cramfs, btrfs, gfs, hfsplus, jfs, swap, zfs.

Ext, Ext2, Ext3, Ext4.

These stand for extended file system. Ext is the older version no longer used.

Ext2 allows managing 2TB of data.
Ext3 is an improvement of its predecessor and exhibits backwards compatibility, however, it does not support file recovery and disk snapshots hence not used for severs.
Ext4 is much faster among all its predecessors and compatible for SSDs, this is the default file system for linux distros.

Btrfs.

B-Tree file system is a copy-on-write file system aiming to implement advanced fs(file system) features while focusing on easy administration, fault tolerance and repairs.

It can be used where high performance and large storage capabilities are required.
A drawback of CoW is that big files are fragmented as they are modified and therefore defragmentation is required however btrfs supports online defragmentation therefore no unmounting of the fs is required.

Swap.

Physical memory is supplemented by configured space on the physical disk swap space , together referred to as virtual memory.
This space can either be configured on a swap partition or on a swap file system.

swap files can also be configured in other file systems currently on a system.
This swap file system is useful for memory paging since physical memory is finite and therefore cannot handle all system processes.

This space provided by the swap file system reduces need for configuration of large amounts of disk-based swap space in systems with large physical memory because it provides virtual swap space addresses instead of real physical swap space to respond to requests to reserve space.

XFS.

It is a 64-bit journaling file system in that, it logs changes before committing them to the main file system.

It is consistent and has an expedited recovery in case of failures or crashes.
Its parallel I/O performance makes it highly scalable for I/O threads, file system bandwidth, and file system sizes even when spanning many storage devices.
An example for its application is the implementation of a several TB file system across multiple storage servers each consisting of multiple FC-connected disk arrays.

ReiserFs.

It was the first journaled file system by Hans Reiser and Namesys company, developed when Ext file systems we not yet thought of.

It works fast with small files and supports journaling hence fast recovery in case of issues. With it you can place small files and file tails in a block and thus reduces the space taken.

It is based on trees and supports fast rebuilding.

The maximum file size is 1 exabyte and on a single partition it can host about 4 billion files.

This file system is unique because it has the ability to optimize occupied disk space by small files, a draw back is that it is non-compatible with ext2 at file system maintenance utility level.

JFS.

Journaled file system is a 64-bit journaling file system. It supports up to 255 bytes filenames, up to 4 petabytes files and up to 32 petabyte file systems.
There exists two versions, jfs1 and jsf2, the latter is similar to the former except that it supports larger volumes and file sizes, which is very useful for storing large databases often contained in a single file.

ZFS.

The zettabyte file system is the most advanced and feature complete file systems.
We can think of it as a volume manager plus RAID array in one package, this feature allows extra disks to be added to ZFS volume and therefore extra space can be added to the file system at once.

This file system is dependent on memory therefore at least 8GB is needed.
It can manage multiple disks and competes with some of the greatest RAID setups.
It is scalable in that it can manage zettabytes of data.

It has integrity in that, all actions inside ZFS use a checksum to ensure file integrity.

It is capable of different RAID levels while also delivering performance comparable to hardware RAID controllers.

Summary.

In a UNIX/Linux system everything is a file otherwise it is a process. Programs, services, images etc, are all files even I/O devices are considered files and all these are handled and managed by a file system.

References.

  1. File systems and hierarchy pdf by Professor Stewart Weiss from The City University of New York (CUNY), USA
Linux file system - an overview
Share this