Partitions And Filesystems In Linux – Introduction

Partitions

Partitions and Filesystems are one of those terms that everyone familiar with computing has come across at some point in their lives. Whether it be in the context of creating a swap partition while installing a Linux system, getting confused between MBR and GPT or simply formatting your pen drive to FAT32 or NFTS. Today we will be learning about these two data management concepts in depth.

What is a partition in Linux?

A partition is a segment of a storage device that has been logically separated from the rest of the device. All the partitions can be managed as if they are separate storage devices. To store data on a device you need to have at least 1 partition on the device.

Having multiple partitions on the device helps the device store data more efficiently. This is no longer the case with modern filesystems and storage devices. A good analogy might be that a storage device is similar to an empty plot of land. And to store your items in that empty plot of land, you need to build rooms aka partitions.

What are partition tables?

Now that we have created a few partitions how do we store the location and size of each partition?

This is where the partition table comes into play. Partition tables store the metadata of each partition i.e. starting position, ending position, size, etc.

There are two major types of partition tables used in different operating systems, MBR (older) and GPT (newer).

Partition tablesMaximum primary partitionsMaximum size for each partitionSecurity Operating system Support
Master Boot Record (MBR) 42TBNo such security featuresSupports most modern OS
Guid Partition Table (GPT)No such limit18 ExabytesCRC32 checksum mechanism to verify the integrity of filesSupports most modern OS

From the table above it should be obvious why GPT is preferred over MBR.

What is a filesystem in Linux?

A filesystem is how we manage data in each partition. It is responsible for indexing, storing, retrieving, naming the files, and maintaining metadata (file owner, size, permissions, etc.) of the files. stored in a partition.

A file is kept in multiple continuous sectors, each sector being around 4096 bytes in modern times. It is the job of the file system to recognize which sectors are ready to be used, which sector a file must be stored in, and which sector contains which file. Without this organization, it would be impossible to retrieve any files because the system doesn’t know the location(block) of the file.

How filesystems store this metadata differs from filesystem to filesystem. For example, while FAT maintains a table for each directory/folder, NTFS has a Master File Table that holds a record of metadata for each file contained by the filesystem including the table itself.

Let’s look at major filesystems in use today:

1. FAT

FAT or File Allocation Table is the first filesystem developed by Microsoft. Since it was originally released in 1977, there have been multiple versions of it, namely FAT12, FAT16, FAT32 with an increase in the maximum supported file size and drive size.

The maximum file size allowed in FAT32 is 4Gb. FAT32 was the default file system till WindowsXP after which NTFS took over. While very basic, FAT supported almost all devices and operating systems which is one of the reasons it hasn’t gone out of use completely and can be spotted in the wild.

2. NTFS

New Technology File System is a modern take on FAT. Apart from supporting drive sizes of up to 16 exabytes (more than 17 billion gigabytes) and individual file sizes of 256TB, it also has a journaling system.

This roughly means that NTFS stores the logs of all the changes committed on the device. This makes it easy to revert back to a previous version of the filesystem if anything breaks or crashes. (similar to git version control).

Unlike FAT, NTFS also supported file permissions, file compression, and encrypted file support. So this was a major upgrade over FAT32 and any drive running Windows today should be formatted in NTFS.

3. ext/ext2/ext3/ext4

The extended file system or ext was released in 1992 for Linux. Since then we have had three updates with ext2 introducing file attributes (file permissions) and ext3 introducing journaling.

ext4 introduced backward compatibility with ext3 and ext2, increased storage limits, and some performance tweaks. This filesystem can support volumes with sizes up to 1 exabyte and single files with sizes up to 16 terabytes.

ext4 also introduces the concept of delayed allocation which allocates the sectors to the file when they are forcefully flushed to the storage. This improves CPU performance and less bad sectors. Today almost all the modern Linux distributions use ext4 as the default file system.

4. ZFS

The Z file system was originally developed by Sun Microsystems as a part of their Open Solaris OS but was later taken over by Oracle. It was later ported to FreeBSD and Linux.

ZFS is an advanced file system that supports

  • disk pooling (pooling different storage devices to make them work as one)
  • copy-on-write (copying data to a different sector before overwriting it)
  • Snapshots (keeping track of all file changes)
  • Data integrity verification (verifying checksums of files to verify if they have been corrupted or not)
  • and RAID-Z (Data redundancy to make storage more reliable).

These features make ZFS very scalable, reliable, and safe for production environments.

5. Btrfs

B-Tree file system of Butter file system was developed by Oracle as an expansion of ext4. It includes Data pooling, copy-on-write, Snapshots, and RAID just like ZFS. Apart from that it also offers online defragmentation.

This makes it perfect for laptops and production servers alike. In fact, OpenSUSE has been using BtrFS as the primary filesystem since 2015.

Conclusion – Partitions and Filesystems in Linux

Perhaps a good way to conclude the article would be to show an example of the partition-filesystem hierarchy.

Example Of Partition And Filesystem1 Partitions and Filesystems in Linux

I have a 500 GB SSD with three partitions (Boot, Root, and Home) and use GPT as the partition table.

I don’t have any swap partition at the moment. All the partitions run the ext4 filesystem however you can change the filesystem as you wish.

On a dual-booted storage device(Windows and Linux), there are several NTFS partitions for Windows besides these.

You can check the partitions on any of your storage devices by running the following command.

lsblk

To read more regarding partitions and filesystems you can refer to the following sources :

Thank you!