Only mask Systemd mounts on block devices (#129)

The gparted shell wrapper masks Systemd mount units to prevent it
automounting file systems while GParted is running [1], excluding
virtual file system which GParted isn't interested in [2].  The problem
is that there are a lot of virtual file systems and they have changed
between Fedora 19 and 33 so now the exclusion list is out of date.

Run GParted on Fedora 33 and query the mount units while it is running:
    $ systemctl list-units -t mount --full --all
      UNIT                          LOAD   ACTIVE   SUB     DESCRIPTION
      -.mount                       loaded active   mounted Root Mount
    * boot.mount                    masked active   mounted /boot
      dev-hugepages.mount           loaded active   mounted Huge Pages File System
      dev-mqueue.mount              loaded active   mounted POSIX Message Queue File System
    * home.mount                    masked active   mounted /home
    * proc-fs-nfsd.mount            masked inactive dead    proc-fs-nfsd.mount
      proc-sys-fs-binfmt_misc.mount loaded inactive dead    Arbitrary Executable File Formats File System
      run-user-1000-gvfs.mount      loaded active   mounted /run/user/1000/gvfs
    * run-user-1000.mount           masked active   mounted /run/user/1000
    * run-user-42.mount             masked active   mounted /run/user/42
      sys-fs-fuse-connections.mount loaded active   mounted FUSE Control File System
      sys-kernel-config.mount       loaded active   mounted Kernel Configuration File System
      sys-kernel-debug.mount        loaded active   mounted Kernel Debug File System
    * sys-kernel-tracing.mount      masked active   mounted /sys/kernel/tracing
    * sysroot.mount                 masked inactive dead    sysroot.mount
    * tmp.mount                     masked active   mounted /tmp
    * var-lib-machines.mount        masked inactive dead    var-lib-machines.mount
    * var-lib-nfs-rpc_pipefs.mount  masked active   mounted /var/lib/nfs/rpc_pipefs
    * var.mount                     masked inactive dead    var.mount

    LOAD   = Reflects whether the unit definition was properly loaded.
    ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
    SUB    = The low-level unit activation state, values depend on unit type.

    19 loaded units listed.
    To show all installed unit files use 'systemctl list-unit-files'.

So it masked these virtual file systems which didn't need to be masked:
    * proc-fs-nfsd.mount            masked inactive dead    proc-fs-nfsd.mount
    * run-user-1000.mount           masked active   mounted /run/user/1000
    * run-user-42.mount             masked active   mounted /run/user/42
    * sys-kernel-tracing.mount      masked active   mounted /sys/kernel/tracing
    * var-lib-machines.mount        masked inactive dead    var-lib-machines.mount
    * var-lib-nfs-rpc_pipefs.mount  masked active   mounted /var/lib/nfs/rpc_pipefs

Lines from /proc/partitions for some of these virtual file systems:
    $  egrep '/run/user|/sys/kernel/tracing|/var/lib/nfs/rpc_pipefs' /proc/mounts
    tmpfs /run/user/42 tmpfs rw,seclabel,nosuid,nodev,relatime,size=202656k,nr_inodes=50664,mode=700,uid=42,gid=42,inode64 0 0
    tmpfs /run/user/1000 tmpfs rw,seclabel,nosuid,nodev,relatime,size=202656k,nr_inodes=50664,mode=700,uid=1000,gid=1000,inode64 0 0
    none /sys/kernel/tracing tracefs rw,seclabel,relatime 0 0
    sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw,relatime 0 0
    gvfsd-fuse /run/user/1000/gvfs fuse.gvfsd-fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=1000 0 0

And for contrast the lines from /proc/mounts for disk backed file systems:
    $ egrep '^/dev/' /proc/mounts
    /dev/sda1 /boot ext4 rw,seclabel,relatime 0 0
    /dev/sda2 / btrfs rw,seclabel,relatime,space_cache,subvolid=258,subvol=/root 0 0
    /dev/sda2 /home btrfs rw,seclabel,relatime,space_cache,subvolid=256,subvol=/home 0 0

Going back to first principles GParted cares that Systemd doesn't
automount file systems on block devices.  So instead only mask mount
units which are on block devices.  Where the 'What' property starts
"/dev/".

Systemd maintains hundreds of properties for each unit.
    $ systemctl show boot.mount | wc -l
    221

The properties of interest for all mount units can be queries like this:
    $ systemctl show --all --property=What,Id,LoadState '*.mount'
    ...

    What=sunrpc
    Id=var-lib-nfs-rpc_pipefs.mount
    LoadState=masked

    What=/dev/sda1
    Id=boot.mount
    LoadState=masked

    ...

[1] 4c109df9b5
    Use systemctl runtime mask to prevent automounting (#701676)

[2] 43de8e326a
    Do not mask virtual file systems when using systemctl (#708378)

Closes #129 - Unit \xe2\x97\x8f.service does not exist, proceeding
              anyway
This commit is contained in:
Mike Fleetwood 2021-01-04 23:00:54 +00:00 committed by Curtis Gedak
parent 3c9ae05cd8
commit 1a5614b3dd

View file

@ -144,9 +144,22 @@ done
# Use systemctl to prevent automount by masking currently unmasked mount points
#
if test "x$HAVE_SYSTEMCTL" = "xyes"; then
MOUNTLIST=`systemctl list-units --full --all -t mount --no-legend --plain \
| grep -v masked | cut -f1 -d' ' \
| egrep -v '^(dev-hugepages|dev-mqueue|proc-sys-fs-binfmt_misc|run-user-.*-gvfs|sys-fs-fuse-connections|sys-kernel-config|sys-kernel-debug)'`
MOUNTLIST=`systemctl show --all --property=What,Id,LoadState '*.mount' | \
awk '
function clear_properties() {
what = ""; id = ""; loadstate = ""
}
function process_unit() {
if (substr(what,1,5) == "/dev/" && loadstate != "masked")
print id
clear_properties()
}
/^What=/ { what = substr($0,6) }
/^Id=/ { id = substr($0,4) }
/^LoadState=/ { loadstate = substr($0,11) }
/^$/ { process_unit() }
END { process_unit() }
'`
systemctl --runtime mask --quiet -- $MOUNTLIST
fi