← Disk & Filesystem
Linux · Disk & Filesystem
How to mount and unmount a filesystem in Linux
Mount a filesystem temporarily or persistently via /etc/fstab, and unmount it safely, including a lazy unmount for busy mounts.
Mount a filesystem now, or make it permanent in /etc/fstab. Run as root.
Unmounting a filesystem a process or database is using will fail, or if forced can cause errors, so check it with fuser/lsof first. Add it to /etc/fstab only when the entry is correct: a bad fstab can stop the system booting.
# Mount an existing filesystem to a directory
sudo mount /dev/sdb1 /data
# Mount everything defined in /etc/fstab
sudo mount -a
# Unmount
sudo umount /data
# If it is busy, see who is using it first
sudo fuser -vm /data
# Lazy unmount (detach once no longer busy)
sudo umount -l /data
# Persistent: add a line to /etc/fstab, then test with: sudo mount -a
# UUID=<uuid> /data xfs defaults 0 0Linuxmountfstab