Attaching filesystems with mount and umount
- Version
- unversioned
- Review
- Draft
Summary#
mount attaches a filesystem to a directory and umount detaches it. findmnt shows what is mounted and where.
Syntax#
findmnt
findmnt --target /var/lib
sudo mount /dev/sdb1 /mnt/data
sudo mount -o ro UUID=1234-ABCD /mnt/data
sudo umount /mnt/data
sudo mount -a
-o ro mounts read-only. mount -a mounts the entries in /etc/fstab that are not mounted yet. umount takes the mount point or the device.
Example#
This example only reads the mount table.
(
set -eu
findmnt -n -o FSTYPE --mountpoint /proc
findmnt -n -o TARGET --target /proc/self
mountpoint -q /proc && echo '/proc is a mount point'
)
Expected output#
proc
/proc
/proc is a mount point
Common mistakes#
Ordinary users cannot mount most filesystems, and mount reports that you must be superuser to use mount. umount fails with target is busy while a process uses a file or has its working directory under the mount point; find it with lsof +f -- /mnt/data or fuser -vm /mnt/data, then stop it. A lazy unmount with umount -l hides the mount point but leaves the filesystem in use, so it is not a safe signal to remove a disk. After editing /etc/fstab, test with sudo findmnt --verify and sudo mount -a before rebooting, because a bad entry can interrupt startup.
Version applicability#
This entry describes mount, umount and findmnt from util-linux 2.41 on Linux. macOS and BSD tools use different options.
Sources#
- Attribution
- DevLookup contributors
- License
- CC-BY-4.0