How to Mount and Unmount Drives in Linux
Introduction
Mounting is how Linux makes storage devices (disks, partitions, USB sticks) available in the filesystem tree; unmounting detaches them cleanly. This tutorial explains how to find drives, mount them temporarily or persistently, safely unmount, and avoid common pitfalls — with practical examples you can run in a terminal.
Understanding mounts and filesystems
Mounting is the act of attaching a filesystem (on a partition, disk, or image) to a directory (the mount point) so you can access files under that path. The kernel drivers handle device I/O; userspace tools (mount, umount) instruct the kernel to attach or detach filesystems.
Key concepts:
- Device node: typically /dev/sdX or /dev/nvme0n1p1 — represents a partition.
- Mount point: an empty directory (e.g., /mnt/usb or /media/username/Label).
- Filesystem type: ext4, vfat (FAT32), ntfs, xfs, btrfs, etc.
- Temporary mount: lasts until system reboot or umount.
- Persistent mount: defined in /etc/fstab so it mounts at boot.
Example: mounting a USB partition to /mnt/usb
# Create mount point (if needed)
sudo mkdir -p /mnt/usb
# Mount device /dev/sdb1 as vfat (auto-detected usually)
sudo mount /dev/sdb1 /mnt/usb
# List mounted filesystems to verify
mount | grep /mnt/usb
This attaches the contents of /dev/sdb1 at /mnt/usb. Files then appear at that directory.
Finding drives and partition info
Before mounting, identify the correct device and filesystem. Common commands: lsblk, fdisk -l, blkid, and the kernel logs (dmesg) for hotplugged USB devices.
Examples:
# List block devices in a tree (shows partitions, sizes, mountpoints)
lsblk -f
# Show partition table and types
sudo fdisk -l /dev/sdb
# Show filesystem UUID and type
sudo blkid /dev/sdb1
# Check kernel messages after plugging a USB drive
dmesg | tail -n 20
Interpreting output:
- lsblk -f prints NAME, FSTYPE, LABEL, UUID, and MOUNTPOINT — very useful to find which partition already has a filesystem and whether it's mounted.
- blkid gives UUID and TYPE that are used in /etc/fstab for persistent mounts.
- If you see /dev/sdb and /dev/sdb1, sdb is the whole disk and sdb1 is a partition; mount the partition (sdb1), not the whole disk (except for raw images or loop devices).
If a partition doesn't have a filesystem yet, create one (e.g., mkfs.ext4). Example:
# Create an ext4 filesystem on /dev/sdb1 (WARNING: this erases data)
sudo mkfs.ext4 /dev/sdb1
Mounting drives temporarily and persistently
Temporary mounting (manual) is simple with mount. Persistent mounting uses /etc/fstab or systemd mount units.
Temporary mount example:
# Mount with explicit fs type and options
sudo mount -t ext4 -o defaults /dev/sdb1 /mnt/data
# Mount a vfat (FAT32) USB so normal users can write
sudo mount -t vfat -o uid=1000,gid=1000,umask=0022 /dev/sdc1 /home/username/usb
Notes:
- uid/gid and umask are useful with FAT/NTFS to set ownership and permissions for non-Unix filesystems.
- If mount auto-detects the type, omit -t. Use mount -o ro to mount read-only.
Persistent mount via /etc/fstab:
Test the fstab entry without reboot:
# Try to mount all entries from fstab that are not currently mounted
sudo mount -a
Edit /etc/fstab and add a line:
UUID=abcd-1234 /mnt/data ext4 defaults,noatime 0 2
Get the UUID:
sudo blkid /dev/sdb1
# Example output: /dev/sdb1: UUID="abcd-1234" TYPE="ext4"
Best practices for /etc/fstab:
- Use UUIDs or labels instead of device names like /dev/sdb1 (device names can change).
- Use noauto if you don't want it mounted at boot (manual only).
- For removable media, prefer udev/desktop automounters instead of fstab.
Unmounting drives safely
Always unmount before removing a device to avoid data loss and filesystem corruption. Use umount (note spelling) and check for processes keeping files open.
Basic unmount:
# Unmount by mount point
sudo umount /mnt/usb
# Or unmount by device
sudo umount /dev/sdb1
If unmount fails (device busy), find what's using it:
# List open files on the mount point
sudo lsof +f -- /mnt/usb
# Or use fuser
sudo fuser -v /mnt/usb
# Kill processes if necessary (use with care)
sudo fuser -km /mnt/usb
Common unmount problems and remedies:
- "device is busy": some process has files open (including shells with cwd on that mount). Close terminals, stop services, or use lsof/fuser to identify processes.
- Unmount during photos or writes: ensure buffered writes are flushed; umount will flush by default. Use sync to flush buffers as a precaution: sync && sudo umount /mnt/usb.
If umount still fails, consider lazy unmount (detaches immediately, cleans up when not busy):
# Lazy unmount (unsafe if you plan to remove immediately)
sudo umount -l /mnt/usb
Lazy unmount should be used with caution; it may hide ongoing IO and delaying cleanup.
Commands table
Below is a quick reference table for common commands used when mounting or unmounting drives.
| Command | Purpose | Example |
|---|---|---|
| lsblk -f | List block devices, filesystems, and mount points | lsblk -f |
| sudo fdisk -l /dev/sdb | Show partition table of a disk | sudo fdisk -l /dev/sdb |
| sudo blkid /dev/sdb1 | Show UUID and filesystem type | sudo blkid /dev/sdb1 |
| sudo mount /dev/sdb1 /mnt/point | Mount a device to a mount point | sudo mount /dev/sdb1 /mnt/data |
| sudo umount /mnt/point | Unmount by mount point | sudo umount /mnt/data |
| sudo mount -a | Mount all entries from /etc/fstab | sudo mount -a |
| sudo mkfs.ext4 /dev/sdb1 | Create ext4 filesystem (destroys data) | sudo mkfs.ext4 /dev/sdb1 |
| sudo lsof +f -- /mnt/point | List open files on a mount point | sudo lsof +f -- /mnt/usb |
| sudo fuser -v /mnt/point | Show processes using mount point | sudo fuser -v /mnt/usb |
| dmesg | Kernel messages (useful after plugging devices) | dmesg |
| mount | Show currently mounted filesystems | mount |
Use these commands together: find the device with lsblk/blkid, create a filesystem if needed, mount it, and unmount when finished.
Common Pitfalls
- Mixing up device names: /dev/sda vs /dev/sdb. Device names can change after reboot; prefer UUIDs in /etc/fstab.
- Forgetting to unmount before removal: unplugging a USB without umount may corrupt the filesystem.
- Mounting to a non-empty directory: mount hides existing files in the mount point directory — they remain but are inaccessible until you unmount. Always mount to a dedicated, empty directory.
Next Steps
- Practice mounting and unmounting with a spare USB stick to build confidence.
- Learn more about /etc/fstab options (noauto, nofail, user, defaults) to tailor persistent mounts.
- Explore automounters (udisks2, udev rules, or desktop environments) for user-friendly removable media handling.
That covers the essentials: identifying devices, mounting temporarily or persistently, unmounting safely, and using the common commands. Keep a reference of the commands table handy as you practice.
👉 Explore more IT books and guides at dargslan.com.