Home / Alt manpages / findmnt(8)

  • findmnt(8)
  • Admin command
  • linux

Map Linux Mounts Safely with findmnt

You will finish with a reliable way to answer three common questions: which filesystem contains a path, what mounts are declared in /etc/fstab, and which columns are safe to consume from a script. The workflow uses findmnt from util-linux and does not mount, unmount or alter anything.

Allow about fifteen minutes. You need a shell and a normal user account. Reading the kernel mount table and /etc/fstab normally needs no elevated privileges. This guide was checked against the local findmnt manpage, generated for util-linux 2.39.3. The installed binary reports 2.41.3, while the Ubuntu package database reports util-linux 2.39.3-9ubuntu6.6; check findmnt --version on the machine where a detail matters.

1. Check the command you are about to use

Start with the version and help output. These are read-only commands:

$ findmnt --version
findmnt from util-linux 2.41.3
$ findmnt --help | sed -n '1,12p'
Usage:
 findmnt [options]
 findmnt [options] <device> | <mountpoint>
 findmnt [options] <device> <mountpoint>
 findmnt [options] [--source <device>] [--target <path> | --mountpoint <dir>]

Option lists can grow between util-linux releases. The examples below use options present in the local manpage. Do not assume that a flag copied from a newer machine exists on an older host.

Checkpoint

If findmnt --version fails, stop and install or repair the util-linux package through your normal system-management process. Do not work around a missing system utility with a downloaded binary in a production script.

2. Find the filesystem behind a path

Use --target when you mean a file or directory. It asks findmnt to identify the filesystem serving that path:

$ findmnt --target /etc/hosts -o SOURCE,FSTYPE,TARGET
SOURCE   FSTYPE TARGET
/dev/md2  ext4   /

The target can be an ordinary file, not only a mountpoint. If the exact path is not itself a mountpoint, the kernel search checks its path elements in reverse order and returns the containing mount. That is why /etc/hosts can report the root filesystem. Use --mountpoint instead when the supplied path must be treated as the exact mountpoint and you do not want that fallback.

Keep the output narrow when you are investigating one path. SOURCE is the device or other source, FSTYPE is the filesystem type, and TARGET is the mount target. Add SIZE,USED,AVAIL,USE% for a capacity view:

$ findmnt --target /etc/hosts -o SOURCE,FSTYPE,SIZE,USED,AVAIL,USE%,TARGET
/dev/md2 ext4  3.6T 712.5G 2.7T 20% /

Sizes are human-readable by default, using powers of 1024 with shortened unit labels. Add --bytes when a consumer requires byte counts. Host capacity changes, so treat the numbers as a point-in-time observation.

3. Inspect mounted filesystems without guessing

With no source or target, findmnt lists mounted filesystems. The default is a tree-like view based on the kernel mount table, and its layout is allowed to change. For a quick human inspection, make the output easier to scan:

$ findmnt --real --list -o SOURCE,FSTYPE,TARGET | head -n 8
SOURCE                                    FSTYPE TARGET
/dev/loop1                                squashfs /snap/core24/1643
/dev/loop0                                squashfs /snap/canonical-livepatch/414
/dev/md2                                  ext4     /

--real filters out pseudo filesystems, while --list requests rows instead of the tree. The exact mounts and spacing belong to the host, so use the command to discover what is present rather than treating the sample as a fixed inventory. If you need pseudo filesystems instead, use --pseudo.

Filter by filesystem type with --types. For example, this lists ext4 mounts and chooses explicit columns:

$ findmnt --types ext4 --list --output SOURCE,FSTYPE,TARGET
SOURCE   FSTYPE TARGET
/dev/md2  ext4   /

More than one type can be supplied as a comma-separated list. Combine type and mount-option filters only when you can explain the resulting intersection. A filter that returns no filesystem is an error condition, not an empty success: the command exits with status 1 when no match is found.

4. Read fstab declarations separately from live mounts

findmnt can search the static file /etc/fstab with --fstab. This answers what is configured, not necessarily what is mounted now:

$ findmnt --fstab --output SOURCE,FSTYPE,TARGET,OPTIONS
SOURCE                                    FSTYPE TARGET OPTIONS
proc                                      proc   /proc  defaults
UUID=242175d2-d353-417c-98f9-341c92a571b4 ext4   /      quota,relatime,usrquota,grpquota,rw

Use --fstab --types nfs to find configured NFS entries, or --fstab --target /mnt/example to select a declared target. A bare path can also match a bind source, so use --target when you specifically mean the mountpoint column.

Tags such as UUID= and LABEL= remain useful in configuration. Add --evaluate when you need findmnt to resolve those tags to device names in the SOURCE column:

$ findmnt --fstab --evaluate --output SOURCE,FSTYPE,TARGET
SOURCE       FSTYPE TARGET
/dev/md2     ext4   /
/dev/sdX2    ext3   /boot

The device names in this example are illustrative because they depend on the host. Do not copy a resolved device name into /etc/fstab merely because it appeared in output. If the same tag is found on more than one device, the manpage provides a SOURCES column to expose the ambiguity.

5. Make output suitable for a script

Never parse the default tree display in automation. Select the columns explicitly with --output, use --list, and suppress headings if the consumer expects data rows only:

$ findmnt --target /etc/hosts --list --noheadings --output SOURCE,FSTYPE,TARGET
/dev/md2 ext4 /

For shell-style key and value fields, use --pairs --shell. The shell option changes column names to valid shell variable identifiers:

$ findmnt --target /etc/hosts --pairs --shell --output SOURCE,FSTYPE,TARGET
SOURCE="/dev/md2" FSTYPE="ext4" TARGET="/"

Even with escaping, treat output as data. Do not execute a line with eval if any part can be influenced by a user, remote filesystem or untrusted configuration. For a program that understands it, --json can be a clearer interchange format. Test the exact columns and format against every util-linux version you support.

Checkpoint

A stable script has an explicit column list, a deliberate list or raw format, and a defined response to exit status 1. It does not depend on column order from the default display or on a particular host's mount names.

6. Validate fstab without changing it

Use --verify to check the mount-table content. The default verification target is /etc/fstab, and --verbose asks for more detail:

$ findmnt --verify --verbose
0 parse errors, 0 errors, 4 warnings
... warning details for the entries in /etc/fstab ...

The wording, warning count and checks vary by util-linux release and by the contents of the file. A zero status does not mean that warnings can be ignored, and a non-zero status means you should read the diagnostic before attempting a mount. This command does not repair entries, mount filesystems or make a service reload its configuration.

Do not test an edited /etc/fstab by rebooting first. Keep a root shell or console recovery path available, check the file with findmnt --verify, and review every change. Mounting a bad network, encrypted or remote entry can delay boot or expose credentials. Verification is read-only, but a later mount -a is an operational change and may require elevated privileges and a maintenance window.

7. Diagnose the common traps

A missing result usually means the filter did not match, the path does not exist, or the source and target were interpreted differently than you intended. Repeat the query with an explicit selector: --source for a device, label or UUID, --target for a containing path, and --mountpoint for an exact mountpoint.

Remember that the kernel view, /etc/mtab and /etc/fstab answer different questions. --kernel reports kernel-maintained mount information, --mtab can include userspace mount options, and --fstab reads declarations. Do not compare their rows as if they were three copies of the same table.

Finally, quote paths and tag values in scripts. A space or shell metacharacter in a mount target is data, not a command boundary. If you need to monitor changes, --poll watches mount, unmount, remount and move events and can block until a timeout. Treat that as a long-running observer, not as an ordinary one-shot lookup.

Done means

  • You can identify the filesystem containing a file with --target.
  • You know when to use --mountpoint for an exact target.
  • You can distinguish live kernel mounts from /etc/fstab declarations.
  • Your scripts select explicit columns and handle a no-match exit status.
  • You can run --verify --verbose before considering any mount change.
  • You have not mounted, unmounted or edited anything while following this guide.