I'd like to figure out whether an arbitrary path is the root of a ZFS mountpoint for evaluation in a (Python) script (so return code of a command is preferred over parsing of output). The btrfs equivalent is btrfs subvolume show [path] which returns 0 or 1 is the path is the root of a btrfs subvolume or not.

Afaik I'd use zfs list and parse it, but maybe there's a more elegant way.

I'm using ZFS on Ubuntu 16.10 with Linux 4.8.0.

3 Answers 3


There doesn't seem to be an easy way to tell whether mountpoint is a parent or child. You could use e.g. property usedbychildren that should be 0B for leaf (lowest child) node.

$ zfs list -o name,usedbychildren
tank             40.4T
tank/backup         0B

if your hierarchy is more complex you can limit maximum depth using -d (although minimal depth is not available). Header can be turned off using -H:

$ zfs list -o name,usedbychildren -H -d 0
tank    40.4T

For given mountpoint you can use from a script zfs get:

$ zfs get -H -o value usedbychildren tank/backup

See man zfs-props for more details.


Currently mounted file systems only

If you are willing to limit yourself to currently mounted ZFS file systems, you can parse /proc/mounts and don't need any particular ZFS knowledge (unless you specifically want to restrict yourself to ZFS file systems).

This may or may not work on non-Linux systems.

/proc/mounts is basically /etc/mtab, but is maintained by the kernel. It contains a list of file system backing devices, mount paths, file system types, and file system flags.

For example, to list the mount points of all mounted ZFS file systems, you could do something like

$ awk '$3 == "zfs" { print $2 }' < /proc/mounts

To check whether a given directory corresponds to a mount point for a mounted ZFS file system,

$ awk '$3 == "zfs" && $2 == "/some/particular/absolute/path" { print "yes" }' < /proc/mounts

To allow for all file systems (not just ZFS), simply remove the $3 == "zfs" check.

Mounted or unmounted ZFS file systems

If you need to include unmounted file systems on currently imported pools, then you need to use zfs get to get a list of all ZFS mountpoints within currently imported pools:

$ sudo zfs list -pH -o mountpoint | grep -q '^/some/particular/absolute/path$' && echo yes

will print yes if a file system with a mount point of /some/particular/absolute/path exists on a pool that is currently imported, whether or not that file system is currently mounted.

File systems on exported pools

I am not aware of any way of listing file systems on exported pools without out-of-band knowledge about the file systems on the pools in question. Hence, I do not believe this combination is possible.

Finishing notes

Always consider whether there exists a utility that does what you want. For example, df, as a side effect, prints the list of currently mounted file systems and their backing devices, and can be expected to not partake in any kernel magic (only using interfaces intended for public use). strace df 2>&1 | less is a good start in that case to see how one might go about finding the information you require.


You can use zfs get to display selected properties, like mountpoint.

# zfs get -pH -o value mountpoint rpool/swap


  • -p produces parsable output with tabs as separators
  • -H omits headers
  • -o name,property,value,source displays the four columns, or any variation of them

You will receive either the path that is set as mountpoint (in most cases this will be / plus dataset name (1), but it can be different(2)), - if no mountpoint is set (3), or legacy (4). You can then use grep to differentiate:

# zfs get -pH -o value mountpoint rpool
# zfs get -pH -o value mountpoint rpool/export/home
# zfs get -pH -o value mountpoint rpool/swap
# zfs get -pH -o value mountpoint rpool/ROOT

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.