brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: findmnt --poll prints a line every time something is mounted or unmounted

Linux
~/tips/tip-mounts-findmnt-poll-watch

findmnt --poll

Watches the mount table and prints each mount, umount, remount or move as it happens.

Plugging in a USB disk and wondering where it landed is a classic. findmnt can simply sit there and tell you. It reads /proc/self/mountinfo and reports every change as it happens.

findmnt --poll

The command keeps running and prints one line per change. The first column is ACTION, followed by the usual target, source, filesystem type and options:

ACTION TARGET SOURCE FSTYPE OPTIONS

The man page lists four actions: mount, umount, remount and move. All of them are watched by default. To watch only some, pass a comma-separated list:

findmnt --poll=mount,umount

Two more options make it useful in scripts. --target limits the output to the filesystem at one path, and --timeout gives an upper limit in milliseconds for how long --poll blocks:

findmnt --poll --target /mnt/backup --timeout 60000

That waits up to a minute for something to happen at /mnt/backup. With a five second timeout, a tmpfs that is mounted and unmounted in that window produces one mount line and one umount line, and the command exits on its own afterwards.

There are extra columns in poll mode too: OLD-TARGET for umount and move, and OLD-OPTIONS for umount and remount. Pick them with -o.

One caveat: the standard columns show the new state, except for umount, where findmnt prints the information it cached before the filesystem went away. It also reads the mount table of its own mount namespace, so it only sees the mounts that process can see.

Further reading: findmnt(8) man page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link