Skip to content

Instantly share code, notes, and snippets.

@leafstorm
Created March 23, 2014 23:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leafstorm/9731337 to your computer and use it in GitHub Desktop.
Save leafstorm/9731337 to your computer and use it in GitHub Desktop.
A script that arranges all your mountpoints into a tree.
#!/usr/bin/env python3
"""
mountree
========
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 ''
else:
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'])
else:
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) +
fs_info(fs))
/ 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