View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Salvador Fandiño García > Linux-Proc-Mountinfo-0.02 > Linux::Proc::Mountinfo



Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  


Linux::Proc::Mountinfo - Parse Linux /proc/$PID/mountinfo data


  use Linux::Proc::Mountinfo;

  my $mi = Linux::Proc::Mountinfo->read;

  my $root = $mi->root;
  say $root->mount_source, " mounted at /, filesystem type is ", $root->fs_type;

  my $flatten = $root->flatten;

  # umount all file systems but / in an ordered fashion:
  for (reverse @flatten) {
    my $mount_point = $_->mount_point;
    system umount => $mount_point unless $mount_point eq '/';


Linux::Proc::Mounts parses the information about mount points provided by the Linux kernel at /proc/$PID/mountinfo.


The Linux::Proc::Mountinfo class

Internal public representation

The internal representation of the class is an array whose entries can be accessed directly unreferencing it. For instance:

  my $mnts = Linux::Proc::Mount->read;

  for my $e (@$mnts) {
    say $e->spec . " is mounted at " . $e->file . " as " . $e->fstype;


The following methods are available from this class:

$mnts = Linux::Proc::Mountinfo->read(%opts)

Reads /proc/$PID/mountinfo and returns a new object with the parsed data.

The accepted options are as follows:

mnt => $proc

Overrides the default mount point for the procfs at /proc.

pid => $pid

Reads the mountinfo file of the process with the given PID. By default the mouninfo file of the current process is read.

For instance, for reading init mountinfo file:

  my $mi = Linux::Proc::Mountinfo->read(pid => 1);
file => $filename

Reads and parses the file of the given name.


Returns an object representing the mount point at the given place.

For instance:

  my $var = $mi->at('/var');
  print $var->mount_source, " is mounted at /var" if $var;

Returns undef if no file system is mounted there.


Returns an object representing the root file system mount point.

The Linux::Proc::Mountinfo::Entry class

This class is used to represent the single entries on the mountinfo file.


The methods supported by this class are as follows:


See the excerpt from the Linux documentation below for the meaning of the return values from these accessors.


Returns the line number of this entry inside the mountinfo file.


Returns the full line on the mountinfo file.


Returns the major part or the major:minor field.


Returns the minor part of the major:minor field.


If the mount is a binding (i.e. created with mount --bind ...), this method returns the object representing the source file system. Othersise, it returns undef.


Returns an Linux::Proc::Mountinfo object containing the mount point that are on top of the given one.


This method is similar to children but returns all the descendants instead of just the direct ones.

Excerpt from Linux documentation ^

What follows is the documentation available from Linux Documentation/Linux/proc.txt (;a=blob_plain;f=Documentation/filesystems/proc.txt) related to mountinfo.

    3.5 /proc/<pid>/mountinfo - Information about mounts

    This file contains lines of the form:

    36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue
    (1)(2)(3)   (4)   (5)      (6)      (7)   (8) (9)   (10)         (11)

    (1) mount ID: unique identifier of the mount (may be reused after

    (2) parent ID: ID of parent (or of self for the top of the mount

    (3) major:minor: value of st_dev for files on filesystem

    (4) root: root of the mount within the filesystem

    (5) mount point: mount point relative to the process's root

    (6) mount options: per mount options

    (7) optional fields: zero or more fields of the form "tag[:value]"

    (8) separator: marks the end of the optional fields

    (9) filesystem type: name of filesystem of the form

    (10) mount source: filesystem specific information or "none"

    (11) super options: per super block options

    Parsers should ignore all unrecognised optional fields.  Currently
    the possible optional fields are:

    shared:X  mount is shared in peer group X
    master:X  mount is slave to peer group X
    propagate_from:X mount is slave and receives propagation from peer
    group X (*) unbindable mount is unbindable

    (*) X is the closest dominant peer group under the process's root.
    If X is the immediate master of the mount, or if there's no
    dominant peer group under the same root, then only the "master:X"
    field is present and not the "propagate_from:X" field.

    For more information on mount propagation see:



mount(8) describes the filesystems and the options accepted.

Sys::Filesystem provides similar functionality to this module and support most common operating systems.

Linux::Proc::Mounts provides similar information from /proc/mounts, though the information from /proc/$PID/mountinfo is supposedly more detailed so there is no reason to use that module (at least, this is the theory).


Salvador Fandiño, <<gt>


Copyright (C) 2012 Qindel Formación y Servicios S.L.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: