How to use the command 'findmnt' (with examples)
- Linux
- December 17, 2024
The findmnt
command is a versatile utility in Linux that helps users to display a list of mounted filesystems, offering a clear and organized view of your system’s mount points. Whether you are managing storage, troubleshooting filesystem issues, or just need a quick look at what’s mounted where, findmnt
provides intuitive ways to gather this information. With options to search for specific devices, mount points, filesystem types, and labels, it becomes an essential tool for system administrators and developers alike.
Use case 1: List all mounted filesystems
Code:
findmnt
Motivation:
Listing all currently mounted filesystems is a basic yet crucial task when you need a snapshot of your system’s current state. It allows a user to quickly assess what filesystems are available, their sources, and where they are mounted. This is particularly useful for system audits, troubleshooting, or when you need to verify the presence and accuracy of your mounts without diving into complex configuration files.
Explanation:
- The command
findmnt
without any additional arguments will output all mounted filesystems by default. It provides a detailed tree-like structure showing each mount point and its upstream source, enabling users to visually understand dependencies and mounts hierarchy.
Example output:
TARGET SOURCE FSTYPE OPTIONS
/ /dev/sda1 ext4 rw,relatime
└─/media tmpfs tmpfs rw,nosuid,nodev,mode=755
Use case 2: Search for a device
Code:
findmnt /dev/sdb1
Motivation:
Searching for a specific device’s mount point is invaluable when you want to see if a particular storage device, such as a USB drive or additional hard disk, is currently in use. Whether verifying device mounting before data transfer operations or debugging problems with particular hardware mounts, this command simplifies identifying where exactly the device is interacting with the system.
Explanation:
findmnt
searches specifically for the given device,/dev/sdb1
, displaying the mount information related only to this particular device. This allows users to avoid sifting through a comprehensive list of mounts and directly retrieves relevant information.
Example output:
TARGET SOURCE FSTYPE OPTIONS
/media /dev/sdb1 ext4 rw,relatime
Use case 3: Search for a mountpoint
Code:
findmnt /
Motivation:
Understanding where a directory is mounted is crucial for tasks involving system reconfiguration, disk space management, or troubleshooting. By verifying mounts like the root directory /
, you can confirm the basic integrity and distribution of filesystems across critical locations, which is foundational for system health and configuration management.
Explanation:
findmnt
checks the given directory mountpoint/
and shows details of whatever filesystem is mounted there. It simplifies identifying the source device and relevant filesystem options used, assisting in system checks and validations.
Example output:
TARGET SOURCE FSTYPE OPTIONS
/ /dev/sda1 ext4 rw,relatime
Use case 4: Find filesystems in specific type
Code:
findmnt -t ext4
Motivation:
Filtering filesystems by type, such as ext4
, helps in isolating and managing similar types of storage, which is beneficial for maintenance tasks and aligning consistency across storage mediums. This is particularly useful when needing to perform operations specific to a filesystem type, such as tuning settings or running filesystem checks.
Explanation:
- The
-t
option tellsfindmnt
to list only filesystems of the specified type,ext4
. This means the output is filtered, allowing users to focus on just one type of filesystem among potential many types present on the system.
Example output:
TARGET SOURCE FSTYPE OPTIONS
/ /dev/sda1 ext4 rw,relatime
/media/usb /dev/sdb2 ext4 rw,relatime
Use case 5: Find filesystems with specific label
Code:
findmnt LABEL=BigStorage
Motivation:
Using storage labels as identifiers provides an intuitive way of managing storage when device names can be unpredictable or may change, such as swapping cables or dynamic allocation in systems. By searching for a specific label, administrators can quickly locate and verify storage devices irrespective of their current system-assigned device names.
Explanation:
LABEL=BigStorage
is used to instructfindmnt
to look for a filesystem labeled as “BigStorage”, displaying all related mount information. This label-based searching adds a layer of abstraction and simplification, especially in environments with multiple and frequently changing devices.
Example output:
TARGET SOURCE FSTYPE OPTIONS
/media/backup /dev/sdc1 ext4 rw,relatime
Use case 6: Check mount table content in detail and verify /etc/fstab
Code:
findmnt --verify --verbose
Motivation:
Verifying the consistency and correctness of the mount table and /etc/fstab
file is critical during system setup, recovery, or reconfiguration phases. A mismatch or error here could lead to mounting failures or system boot problems. The verbose output offers insights into potential discrepancies, making it easier to pinpoint and rectify issues.
Explanation:
- The
--verify
option checks the current mounts against the system’s/etc/fstab
and detects any inconsistencies or errors. --verbose
introduces detailed output, allowing you to see expanded information that may include error messages, thus facilitating clearer diagnostics compared to a simple verification.
Example output:
[/etc/fstab] verifying...
[ / ] : source correct
[ /media/usb ] : source correct
Conclusion:
The findmnt
command is an indispensable tool in Linux system management, offering a powerful yet straightforward way to interact with and understand mounted filesystems. Its ability to list mounts, search by devices, mount points, types, and labels, as well as verify the accuracy of mount tables, makes it essential for system administrators looking to optimize and verify their storage setups. By leveraging its capabilities, users can ensure that their systems are operating efficiently and effectively.