Mounting Drives and /etc/fstab Explained

Mounting Drives and /etc/fstab Explained

Linux does not assign storage devices separate drive letters the way Windows does. Instead, every device gets attached, or mounted, at a specific point within a single unified directory tree that starts at /. Understanding mounting, and how /etc/fstab makes mounts persist across reboots, is essential for anything involving external drives, additional internal disks, or network storage.

Finding a drive to mount

Before mounting anything, identify the device:

lsblk

This lists all block devices (drives) and their partitions in a tree view, along with size and current mount points, if any. A freshly connected USB drive typically appears as something like /dev/sdb1 (a partition on the second detected disk), though the exact name depends on what else is already connected.

sudo fdisk -l           # more detail on partitions and filesystem types
lsblk -f                # includes filesystem type and UUID for each partition

Mounting a drive manually

sudo mkdir -p /mnt/mydrive
sudo mount /dev/sdb1 /mnt/mydrive

The mount point (/mnt/mydrive here) must already exist as a directory before you can mount onto it, hence the mkdir -p first. After mounting, the contents of /dev/sdb1 become accessible as ordinary files under /mnt/mydrive, and stay that way until the drive is unmounted or the system reboots.

To specify the filesystem type explicitly (usually auto-detected correctly, but occasionally necessary):

sudo mount -t ext4 /dev/sdb1 /mnt/mydrive
sudo mount -t ntfs-3g /dev/sdb1 /mnt/mydrive    # Windows-formatted drives

Viewing currently mounted filesystems

mount                 # list all currently mounted filesystems
df -h                  # list mounted filesystems with human-readable space usage
findmnt /mnt/mydrive   # show details for a specific mount point

Unmounting a drive

sudo umount /mnt/mydrive

Note the command is umount, without an “n”, a frequent typo for newcomers. Always unmount a drive before physically disconnecting it. The kernel commonly caches writes in memory before flushing them to the physical device, so unplugging without unmounting risks losing data that appeared to be saved but had not actually reached the disk yet.

If unmounting fails with “target is busy,” something still has an open file or working directory on that filesystem:

sudo lsof +D /mnt/mydrive       # list processes with open files under this mount point
sudo fuser -vm /mnt/mydrive     # similar, verbose process list

Close whatever program is holding it open, or in genuine emergencies, umount -l (lazy unmount) detaches the filesystem immediately and cleans up once it is no longer busy, though this should be a last resort rather than a routine habit.

Making a mount permanent with /etc/fstab

Manual mounts do not survive a reboot. To have a drive mount automatically every time the system starts, add an entry to /etc/fstab.

First, find the filesystem’s UUID rather than relying on its device name:

sudo blkid /dev/sdb1
# /dev/sdb1: UUID="1234abcd-56ef-78gh-90ij-klmnopqrstuv" TYPE="ext4"

Device names like /dev/sdb1 are assigned based on detection order at boot and can shift if you add, remove, or reorder storage devices. A UUID is generated when the filesystem is created and never changes, which is why fstab entries should reference drives by UUID rather than by device name.

Edit /etc/fstab:

sudo vim /etc/fstab

Add a line in this format:

UUID=1234abcd-56ef-78gh-90ij-klmnopqrstuv  /mnt/mydrive  ext4  defaults  0  2

The fields, in order: the device (by UUID here), the mount point, the filesystem type, mount options, the dump flag (legacy, almost always 0), and the fsck pass number (0 to skip checking, 1 for the root filesystem, 2 for other filesystems checked after root).

defaults expands to a standard set of common mount options: read-write, allow executing binaries, mount automatically at boot, and a few others. For specific needs, list options explicitly instead, such as noexec to prevent running programs from that drive, or ro to mount it read-only.

Testing an fstab entry safely

A broken fstab entry can prevent the system from booting cleanly, since fstab is processed very early in the boot sequence. Before rebooting to test a new entry, apply it immediately without a reboot:

sudo mount -a

This reads /etc/fstab and mounts anything listed that is not already mounted, reporting any errors immediately. If mount -a succeeds cleanly, the entry is very likely safe to survive a reboot too. If it reports an error, fix the fstab entry before rebooting, rather than finding out the hard way at boot time.

Common fstab mistakes

A few things worth double-checking before saving changes to /etc/fstab: that the UUID is copied correctly with no typos, that the mount point directory actually exists, that the filesystem type matches what blkid reported, and that you have not accidentally duplicated or overwritten an existing entry for a critical filesystem like / or /home. Keeping a backup copy (sudo cp /etc/fstab /etc/fstab.bak) before editing is a cheap safeguard against a typo turning into an unbootable system.

Frequently Asked Questions

What does mounting a drive actually mean on Linux?

Mounting attaches a storage device’s filesystem to a specific point in the existing directory tree, called a mount point, so that its contents become accessible as ordinary files and directories under that path. Unlike Windows, which assigns drives separate letters like D: or E:, Linux has a single unified directory tree starting at /, and every additional storage device is grafted onto that tree at a mount point you choose, such as /mnt/usbdrive or /media/backup. Before mounting, a device’s contents are not accessible through the filesystem at all, even though the device itself is connected and recognized by the kernel.

How do I find the device name of a drive I just plugged in?

Run lsblk to list all block devices and their partitions in a tree view, or sudo fdisk -l for more detail on each device. A newly connected USB drive typically shows up as something like /dev/sdb1 (a partition on the second detected disk), though the exact letter depends on how many storage devices are already attached. Comparing lsblk output before and after plugging in the drive is a reliable way to confirm exactly which device name corresponds to the drive you just connected.

What is the difference between mounting by device name and by UUID?

Device names like /dev/sdb1 are assigned based on detection order at boot, which can change if you add, remove, or reorder storage devices, potentially causing the wrong drive to mount at a given mount point after a hardware change. A UUID (Universally Unique Identifier) is generated when a filesystem is created and stays fixed for the life of that filesystem, regardless of which device name the kernel happens to assign it on a given boot. For this reason, entries in /etc/fstab should reference drives by UUID rather than by device name like /dev/sdb1, which is why blkid or lsblk -f are the standard tools for finding a filesystem’s UUID before writing an fstab entry.

What happens if I get an entry in /etc/fstab wrong?

A malformed or invalid /etc/fstab entry can prevent the system from booting normally, since fstab is read very early in the boot process to mount essential filesystems. Many distributions will drop you into an emergency shell or recovery mode if a required entry fails, rather than silently ignoring it, precisely because a botched fstab is one of the more common ways to render a system unbootable after manual editing. Before rebooting after editing fstab, test the new entry with sudo mount -a, which processes fstab immediately and reports errors without requiring a reboot, letting you catch mistakes safely.

How do I safely unmount a drive before removing it?

Run sudo umount /path/to/mountpoint (note: the command is umount, without an “n”, not “unmount”). If you get a “target is busy” error, a program still has an open file or working directory on that filesystem; close whatever is using it, or find the culprit with sudo lsof +D /path/to/mountpoint or sudo fuser -vm /path/to/mountpoint, which lists the processes currently holding files open on that mount. Unplugging a drive without unmounting it first risks data loss or filesystem corruption, since the kernel may still have unwritten data cached in memory that has not yet been flushed to the physical device.

What does the defaults option mean in an fstab entry?

defaults is a shorthand in the mount options field of an fstab entry that expands to a standard set of common options: rw (read-write), suid (allow setuid/setgid bits), dev (interpret device files), exec (allow executing binaries), auto (mount automatically at boot or with mount -a), nouser (only root can mount/unmount), and async (asynchronous I/O). It is a reasonable starting point for most internal drives. For removable media or drives where you want different behavior, such as noexec to prevent running programs from that drive, or user to let non-root users mount it, you list those options explicitly instead of, or in addition to, defaults.