Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A script that arranges all your mountpoints into a tree.
#!/usr/bin/env python3
This prints all your filesystem mounts in a tree so you can see how they
are laid out.
It only works on Linux because it uses ``/proc``.
:copyright: © 2014 Matthew Frazier
:license: MIT/X11
import os.path
filesystems = {}
def split_into(line, *names):
data = {}
for name, value in zip(names, line.split()):
data[name] = value
return data
with open('/proc/mounts', 'r') as fd:
for line in fd:
fs = split_into(line, "device", "mountpoint", "fstype",
"options", "dump_frequency", "fsck_order")
filesystems[fs['mountpoint']] = fs
# Make sure everything has a parent!
for fs in list(filesystems.values()):
parent = os.path.dirname(fs['mountpoint'])
while parent != '/':
# We use None to indicate a folder on the real filesystem.
if parent not in filesystems:
filesystems[parent] = None
parent = os.path.dirname(parent)
def indentation(mountpoint):
if mountpoint == '/':
return ''
return mountpoint.count('/') * ' '
# Find out how big to draw the table
max_length = 1
for mountpoint in filesystems.keys():
length = len(indentation(mountpoint)) + len(os.path.basename(mountpoint)) + 2
max_length = max([max_length, length])
def fs_info(fs):
if fs is None:
return '(directory)'
elif fs['fstype'] == fs['device']:
return '{} [{}]'.format(fs['fstype'], fs['options'])
return '{} on {} [{}]'.format(fs['fstype'], fs['device'], fs['options'])
for mountpoint, fs in sorted(filesystems.items()):
print((indentation(mountpoint) + os.path.basename(mountpoint) + '/').ljust(max_length) +
/ ext4 on /dev/mapper/fedora_tantive4-root [rw,seclabel,relatime,data=ordered]
boot/ ext4 on /dev/sda1 [rw,seclabel,relatime,data=ordered]
dev/ devtmpfs [rw,seclabel,nosuid,size=1979188k,nr_inodes=494797,mode=755]
hugepages/ hugetlbfs [rw,seclabel,relatime]
mqueue/ mqueue [rw,seclabel,relatime]
pts/ devpts [rw,seclabel,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000]
shm/ tmpfs [rw,seclabel,nosuid,nodev]
home/ ext4 on /dev/mapper/fedora_tantive4-home [rw,seclabel,relatime,data=ordered]
proc/ proc [rw,nosuid,nodev,noexec,relatime]
sys/ (directory)
fs/ (directory)
binfmt_misc/ autofs on systemd-1 [rw,relatime,fd=31,pgrp=1,timeout=300,minproto=5,maxproto=5,direct]
run/ tmpfs [rw,seclabel,nosuid,nodev,mode=755]
user/ (directory)
1000/ (directory)
gvfs/ fuse.gvfsd-fuse on gvfsd-fuse [rw,nosuid,nodev,relatime,user_id=1000,group_id=1000]
sys/ sysfs [rw,seclabel,nosuid,nodev,noexec,relatime]
fs/ (directory)
cgroup/ tmpfs [rw,seclabel,nosuid,nodev,noexec,mode=755]
blkio/ cgroup [rw,nosuid,nodev,noexec,relatime,blkio]
cpu,cpuacct/ cgroup [rw,nosuid,nodev,noexec,relatime,cpuacct,cpu]
cpuset/ cgroup [rw,nosuid,nodev,noexec,relatime,cpuset]
devices/ cgroup [rw,nosuid,nodev,noexec,relatime,devices]
freezer/ cgroup [rw,nosuid,nodev,noexec,relatime,freezer]
hugetlb/ cgroup [rw,nosuid,nodev,noexec,relatime,hugetlb]
memory/ cgroup [rw,nosuid,nodev,noexec,relatime,memory]
net_cls/ cgroup [rw,nosuid,nodev,noexec,relatime,net_cls]
perf_event/ cgroup [rw,nosuid,nodev,noexec,relatime,perf_event]
systemd/ cgroup [rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd]
fuse/ (directory)
connections/ fusectl [rw,relatime]
pstore/ pstore [rw,nosuid,nodev,noexec,relatime]
selinux/ selinuxfs [rw,relatime]
kernel/ (directory)
config/ configfs [rw,relatime]
debug/ debugfs [rw,relatime]
security/ securityfs [rw,nosuid,nodev,noexec,relatime]
tmp/ tmpfs [rw,seclabel]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.