As a Linux system administrator, knowledge of underlying file system formats and types is critical for effective management of storage infrastructure. When issues crop up with stability, performance or fragmentation, you need to pick the appropriate tools based on the capabilities exposed by the given file system implementation.

With the wide variety available today like Ext4, XFS, Btrfs and more, identifying the file system correctly becomes vital. In this comprehensive guide, we will drill down the various methods to determine the file system type in Linux.

But before we look at the commands, it helps to have an understanding of popular file system types and their core attributes.

Overview of Key File Systems in Linux

While the traditional Ext file systems continue to be popular, we now have advanced next-gen implementations that unlock more features and functionality. Let‘s briefly compare some of the mainstream file systems available for Linux.

1. ext4

The fourth extended filesystem is the default in most Linux distributions today. It is based on traditional Unix filesystem concepts focused on performance and reliability. Some key aspects:

  • Mature and stable codebase
  • Supports volume sizes up to 1 exabyte
  • Fast metadata and data journalling to prevent corruption
  • Scales reasonably to handle large number of inodes

Where it shines: Day to day business critical workloads; Proven stability at scale

2. XFS

Developed by SGI to support extremely large storage and high throughput, XFS has production-ready stability features:

  • Optimized for parallel I/O with near linear scalability
  • Supports filesystem sizes up to 8 exabytes
  • Fast recovery with journaling
  • Online defragmentation while mounted and active

Where it shines: Media servers and applications needing high speed sequential I/O

3. Btrfs

Btrfs is positioned as the next-gen Linux file system due to its advanced capabilities:

  • Efficient snapshots and rollbacks using copy-on-write
  • In-built RAID and storage pooling features
  • Capable of handling millions of subvolumes
  • Online defragmentation, compression and error detection
  • Flexible file / block / metadata partitioning

Where it shines: Future-proof scalable storage for modern applications

4. ZFS

ZFS was developed for Solaris and prevents data corruption via:

  • Transactional copy-on-write semantics
  • End-to-end checksumming for error detection
  • Continuous integrity checking and automatic repair
  • Advanced snapshotting and cloning
  • Read/Write speed optimizations

Where it shines: Massive storage backends where data integrity is critical

Above are just some of the choices available. Understanding their capabilities can help decide the right file system for your workload when architecting Linux storage systems.

Now let‘s move on to the methods for detecting the underlying file system format on a Linux box.

1. Check Mounted File Systems using df

The most straightforward method is using the df (disk free) utility. It displays metrics on consumed disk space for mounted file systems.

Include the -T parameter to reveal the file system types:

df -Th

Here‘s sample output on a test system:

Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda2      ext4       97G  3.6G   89G   4% /
tmpfs          tmpfs     1.9G     0  1.9G   0% /dev/shm
/dev/sda1      vfat      510M   17M  494M   4% /boot/efi 
/dev/sdc1      xfs       2.7T  1.2T  1.5T  44% /data

We can see ext4 on root, tmpfs for temporary in-memory filesystem, vfat on the boot partition and xfs on my high capacity storage volume.

Use grep to filter and query for specific mount paths:

df -Th | grep ‘/data‘

Some examples of options:

  • -x fs-type to exclude specific types from output
  • -h for human readable sizes
  • -l to only display local filesystems

So df quickly reveals formats for currently mounted file systems.

2. Identify File Systems of Block Devices using lsblk

The lsblk utility lists information related to block devices like physical disks and partitions.

Use the -f parameter to view file system types:

lsblk -f 

Here‘s some sample output:

NAME   FSTYPE   LABEL UUID                                 MOUNTPOINT
sda                                                          
├─sda1 ntfs     System BB34-1278                            
├─sda2 ext4     Root  4967a9a5-ff96-4089-b123-123b53a601c7 /
└─sda3 btrfs   Data  968c6705-ec41-46f5-a85b-7cbaa92b7ee7 /data   
sdb                                                          
└─sdb1 swap    Swap  a142f947-37b3-479f-859d-a99496372fbe [SWAP]
sdc
└─sdc1 xfs            63abd981-9807-4160-b936-6bffa780bc5e 

Here we detect an ext4 root, btrfs data volume, swap and an xfs LUN which is currently unmounted.

Filter using grep if required:

lsblk -f | grep btrfs

Some useful options:

  • Add -e7 to exclude loop devices
  • -o FSTYPE,KNAME to display only filesystem type and kernel name
  • -p to show full device paths

So lsblk allows identification of file systems associated with both mounted and unmounted block devices.

3. Check Mount Points using findmnt

The findmnt command displays information only for mounted filesystems.

Invoke it with the -T flag to reveal types:

sudo findmnt -T

Sample output:

TARGET               SOURCE     FSTYPE     
/                    /dev/sda2  ext4  
├─/proc               proc       proc                
├─/sys                sysfs      sysfs
└─/dev                devtmpfs   devtmpfs

Additional options:

  • -D to show filesystem types mounted at boot time per fstab
  • -l to view filesystem labels instead
  • -r for mount options

So findmnt is convenient for examining currently mounted filesystems when troubleshooting issues.

4. Parse /etc/fstab Filesystem Definitions

The /etc/fstab file indicates the filesystems to be automatically mounted at boot time.

It contains the storage device, mountpoint, filesystem type and mount options per device.

View sample contents:

cat /etc/fstab
UUID=e6097dd4-fa93-4ead-bd24-9d692736a31e /               ext4    defaults        0 1
UUID=7E409EA0409E85C7 /boot           ext2    defaults        0 2
/swap.img      none    swap    defaults        0 0
/dev/cdrom  /mnt/cdrom  auto    noauto,user  0 0

The 3rd column denotes filesystem type, which we see as ext4, ext2 and swap in this case.

So parsing /etc/fstab indicates the file system types for partitions configured to automount at OS boot.

5. Leverage /etc/mtab Mount Entries

The /etc/mtab file contains details of currently mounted filesystems including:

  • Mount point
  • Block device
  • Filesystem type
  • Mount options

It shows similar info as the output of the findmnt command.

Check file system types visible in /etc/mtab:

cat /etc/mtab

Sample excerpt from my test server:

/dev/sdb2 / btrfs rw,relatime,space_cache,subvolid=5,subvol=/@ 0 0
/dev/sdb2 /home btrfs rw,relatime,space_cache,subvolid=7,subvol=/@home 0 0  
/dev/sdb2 /.snapshots btrfs rw,relatime,space_cache,subvolid=18,subvol=/@snapshots 0 0

Here we detect that /, /home and /.snapshots are all on the same physical btrfs volume which has multiple sub-volumes.

You can further filter by mount paths:

cat /etc/mtab | grep /home 

So parsing /etc/mtab is handy for identifying the runtime file system types based on what‘s currently mounted.

6. Filesystem Attributes using blkid

The blkid utility displays identifiers and attributes associated with block devices including the filesystem type.

Run it without any options:

blkid

Here‘s a snippet of output on my system:

/dev/sdb1: UUID="a142f947-37b3-479f-859d-a99496372fbe" TYPE="swap" 
/dev/sdb2: LABEL="data" UUID="968c6705-ec41-46f5-a85b-7cbaa92b7ee7" TYPE="btrfs" 
/dev/sdc1: UUID="63abd981-9807-4160-b936-6bffa780bc5e" TYPE="xfs"

We detect swap, btrfs and xfs filesystems on various block devices.

Additional options:

  • -o list to list attributes in a readable format
  • -s to display device sizes

So blkid helps identify file system types regardless of whether they are currently mounted or offline.

7. Detect using file system magic numbers

The file utility examines and identifies the type of the given file by checking it‘s contents against a set of magic numbers corresponding to known formats.

Since disks and partitions are essentially device files in Linux, the file command can be used to determine the file system type as well.

Analyze sdb1 partition using file:

sudo file -sL /dev/sdb1  

Output:

/dev/sdb1: Linux/i386 swap file (new style), version 1 (4K pages), size 4 GiB (4294963200 bytes), no label, UUID=a142f947-37b3-479f-859d-a99496372fbe

We can see it detects the swap signature successfully.

And result for my /dev/sdb2 btrfs volume:

sudo file -sL /dev/sdb2
/dev/sdb2: BTRFS Filesystem sectorsize 4096, nodesize 16384, leafsize 16384, UUID=968c6705-ec41-46f5-a85b-7cbaa92b7ee7

So file carves filesystem metadata to reliably identify formats.

Best Practices for Checking Linux File Systems

Now that we have explored multiple approaches to detect file system types, let‘s briefly summarize best practices:

  • Leverage blkid to determine file system UUIDs and associate them with devices
  • Maintain a CMDB database mapping device names to their filesystem types
  • For mount troubleshooting examine findmnt first, then /etc/mtab entries
  • Monitor df output for nearing capacity thresholds proactively
  • During boot issues, compare filesystem types between lsblk and /etc/fstab
  • For unrecognized storage devices, use file to accurately determine formats
  • Consider volume topology and layout when using tools (e.g. layered LVM logical volumes etc)

So in addition to having multiple tools handy, understanding their capabilities, semantics and output in context is key to effectively employing them.

Conclusion

We went through a comprehensive set of methods to determine file system types in Linux environment, including legacy as well as next-generation implementations.

Ranging from querying currently mounted filesystems to block device attributes to magic number formats, Linux offers various filesystem inspection utilities.

Having expertise on when to use which analysis technique based on your specific situation comes in very handy in enterprise operations. Quick yet reliable identification of file system types helps pick appropriate tools for deeper troubleshooting, repair or scalability management.

Similar Posts