Understanding Linux File Systems - EXT4, XFS, BTRFS

It's all about Storage Management on Linux!

Understanding Linux File Systems - EXT4, XFS, BTRFS

What is a File System?

A File System is a process which controls how data is stored and retrieved to-and-fro a storage device typically a hard disk drive (HDD) or solid state drive (SSD).

It does indexing of data as well as provides a way to store meta data about these files such as their permissions, names, creation and modification times and other attributes.

You can understand it by how we organize our books or files within a bookshelf. People might have their own ways to organize stuff there. Similarly there exist many file systems to organize files and storing data about them.

Each Operating system uses their own choice of file system based on their targeted audience or requirements such as few are rich in security features, few does provide faster storage and few supports larger file sizes.

Ext4 File System

The fourth generation File System of the Ext (Extended) file system family. It is the default file system in RHEL 6, Debian 7, Ubuntu 18 and so on. Ext4 fs can read and write to Ext2 or Ext3 file systems, but the Ext4 it is not compatible with Ext2 and Ext3 drivers.

Ext4 comes up with some new and improved features such as:

  • Extent-based metadata
  • Delayed allocation
  • Journal check summing
  • Large storage support
  • Multi-block allocation

File system repair time (fsck) in Ext4 is much faster than earlier generation one's. Some file system repairs have demonstrated up to a six-fold increase in performance. The maximum supported size for Ext4 in RHEL 7 is 16TB compared to 500TB in XFS.

XFS File System

XFS is a robust and mature 64-bit journaling file system that supports very large files (scales to exabytes) and file systems on a single host. It is the default file system in RHEL 7. Journaling ensures file system integrity after system crashes (for example, due to power outages) by keeping a record of file system operations that can be replayed when the system is restarted and the file system remounted.

XFS supports a wealth of features including the following:

  • Delayed allocation
  • Dynamically allocated inodes
  • B-tree indexing for scalability of free space management
  • Online defragmentation
  • Online filesystem growing
  • Comprehensive diagnostics capabilities
  • Scalable and fast repair utilities
  • Optimized to support streaming video workloads
  • Support a large number of parallel operations
  • Extensive run-time metadata consistency checking
  • Sophisticated metadata read-ahead algorithms
  • Tightly integrated backup and restore utilities

XFS is one of the highest performing file systems on large systems with enterprise workloads and a preferred choice.

You cannot shrink (reduce) XFS file systems in size, so you should take extra care to not over-allocate storage to an existing file system.

BTRFS

It is around for quite some time now. Btrfs, short for B-Tree Filesystem and pronounced as "butter fuss", is actually a filesystem and volume manager rolled into one. It is based on the copy-on-write (COW) principle. Btrfs is default filesystem in Fedora these days.

It provides a very advanced filesystem feature set to Linux and might replace ext4 one day. Though Btrfs is currently considered experimental.

BTRFS can support up to a 16 exbibyte partition (sixteen times of the data of Ext4) and a file of the same size as ext4.

Comparative view

image.png

How do you choose your File System?

The main question here is what will be your criteria's while choosing file system for your application. To get the answer to this you must first understand the target operating system you are going to deploy the file system.

Ask yourself and your team following questions before deciding upon the file system:

  • What size of server and storage do you have?
  • What is your storage requirement?
  • Understand the nature of of I/O workloads your application will be putting.
  • What is the typical size of your files and data set?
  • Are you going to use data mirroring setups using RAID?
  • Is your machine/server and storage stable?
  • Analyze your throughput and latency requirements.
  • Think about affordable downtime in case of server/storage failure.
  • Will there be a need to shrink (reduce) the filesystem size in future?

When you have answers to above questions, you can easily make your choice.

Find out your File System

There are many ways we can find out file system details on our system.

root@lco-linux-master:~# lsblk -f
root@lco-linux-master:~# df -hT
root@lco-linux-master:~# blkid
root@lco-linux-master:~# file -sL /dev/mapper/vagrant--vg-root

ext4_find_out.png

What all File Systems does my System support?

To get the list of what filesystems a kernel can support run the following command:

root@lco-linux-master:~# ls /lib/modules/$(uname -r)/kernel/fs

fs_support_list.png

That's all for this tutorial. You should now be having a fair bit of idea about Linux File Systems.

Hope you like the article. Stay Tuned for more.

Thank you. Happy learning!

Did you find this article valuable?

Support Learn Code Online by becoming a sponsor. Any amount is appreciated!