Mount and fstab Basics - How to Attach Filesystems in Linux
What You'll Learn
- What "mounting" means in Linux and how it works
- How to manually mount a USB drive or additional disk
- How to read and write
/etc/fstabfor persistent mounts - Why UUID is safer than device names like
/dev/sdb1 - How to safely unmount a device
Quick Summary
- Mount = attach a device to a directory (mount point) so you can access its files
- Manual mount:
sudo mount /dev/sdX /mnt/point - Persistent mount: write to
/etc/fstab→ auto-mounted on every boot - Always use UUID in fstab — device names like
/dev/sdbchange between reboots
Prerequisites
- Ubuntu / Debian-based system (commands also work on RHEL/CentOS)
mount,umount, and fstab edits require root (sudo)
What Is Mounting?
In Linux, you cannot access a storage device until it is mounted. Mounting attaches the device to a directory in the filesystem tree, making its contents accessible at that path.
/ ← root filesystem (mounted at /) ├── home/ ← separate partition mounted at /home ├── mnt/ │ └── usb/ ← USB drive mounted here becomes browsable └── var/
Unlike Windows drive letters (C:, D:), Linux integrates all devices into a single directory tree. The directory where a device is attached is called the mount point.
How to Check What Is Currently Mounted
Use findmnt for a clean tree view, or mount for the traditional listing.
$ findmnt
TARGET SOURCE FSTYPE OPTIONS / /dev/sda1 ext4 rw,relatime ├─/sys sysfs sysfs rw,nosuid,nodev,noexec ├─/proc proc proc rw,nosuid,nodev,noexec ├─/dev udev devtmpfs rw,nosuid ├─/run tmpfs tmpfs rw,nosuid,nodev └─/home /dev/sda2 ext4 rw,relatime
Check a specific mount point:
$ findmnt /home TARGET SOURCE FSTYPE OPTIONS /home /dev/sda2 ext4 rw,relatime
How to Find Device Names and UUIDs
Before mounting, identify your target device.
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 20G 0 disk ├─sda1 8:1 0 19G 0 part / └─sda2 8:2 0 1G 0 part /home sdb 8:16 1 8G 0 disk └─sdb1 8:17 1 8G 0 part
sdb1 has no MOUNTPOINTS entry — it is not yet mounted.
Get the UUID for a device:
$ sudo blkid
/dev/sda1: UUID="a1b2c3d4-1111-2222-3333-444455556666" TYPE="ext4" /dev/sda2: UUID="b2c3d4e5-2222-3333-4444-555566667777" TYPE="ext4" /dev/sdb1: UUID="c3d4e5f6-3333-4444-5555-666677778888" TYPE="vfat"
For a single device:
$ sudo blkid /dev/sdb1 /dev/sdb1: UUID="c3d4e5f6-3333-4444-5555-666677778888" TYPE="vfat"
How to Mount a Device Manually
Create a mount point directory first, then run mount.
# Create the mount point $ sudo mkdir -p /mnt/usb # Mount (filesystem type auto-detected) $ sudo mount /dev/sdb1 /mnt/usb # Verify $ findmnt /mnt/usb TARGET SOURCE FSTYPE OPTIONS /mnt/usb /dev/sdb1 vfat rw,relatime
Specify the filesystem explicitly with -t:
$ sudo mount -t ext4 /dev/sdb1 /mnt/data $ sudo mount -t vfat /dev/sdb1 /mnt/usb $ sudo mount -t ntfs /dev/sdb1 /mnt/win
Omitting -t lets mount auto-detect the filesystem. Works reliably for ext4, vfat, ntfs, and most common types.
Common mount options (-o):
| Option | Meaning |
|---|---|
ro |
Read-only |
rw |
Read-write (default) |
noexec |
Prevent executing binaries |
nosuid |
Disable SUID bits |
remount |
Change options on an already-mounted filesystem |
# Mount read-only $ sudo mount -o ro /dev/sdb1 /mnt/usb # Switch to read-write without unmounting $ sudo mount -o remount,rw /mnt/usb
How to Unmount a Device
Always unmount before physically removing a device. This flushes write buffers and prevents data corruption.
$ sudo umount /mnt/usb # Or specify the device $ sudo umount /dev/sdb1
If you see "target is busy"
# Find which process is using the mount $ lsof /mnt/usb
Identify and stop the process, or cd out of the directory first. Then retry umount.
What Is /etc/fstab?
/etc/fstab (filesystem table) defines which devices to mount automatically at boot. Every entry in this file is processed during startup.
$ cat /etc/fstab
# <file system> <mount point> <type> <options> <dump> <pass> UUID=a1b2c3d4-... / ext4 defaults 0 1 UUID=b2c3d4e5-... /home ext4 defaults 0 2 UUID=f9g0h1i2-... none swap sw 0 0
A broken fstab can make your system unbootable. Always test changes with sudo mount -a before rebooting.
How to Write an fstab Entry
Each line has six space-separated fields:
| Field | Description |
|---|---|
<file system> |
Device to mount — UUID recommended, /dev/sdX also works |
<mount point> |
Directory to mount at (none for swap) |
<type> |
Filesystem type: ext4, vfat, ntfs, swap, etc. |
<options> |
Mount options (defaults = rw,suid,exec,auto,nouser,async) |
<dump> |
Dump backup flag (0 = disabled, 1 = enabled). Use 0. |
<pass> |
fsck order at boot (0 = skip, 1 = root first, 2 = others) |
Example entry for an ext4 data partition:
UUID=c3d4e5f6-3333-4444-5555-666677778888 /mnt/data ext4 defaults 0 2
Why Use UUID Instead of Device Names?
Device names like /dev/sdb depend on the order the kernel detects drives. After adding, removing, or reordering disks, the same physical drive may get a different name. UUID never changes.
# Risky — device name can change after reboot /dev/sdb1 /mnt/data ext4 defaults 0 2 # Safe — UUID is permanent UUID=c3d4e5f6-3333-4444-5555-666677778888 /mnt/data ext4 defaults 0 2
How to Make a Mount Persistent with fstab
Step-by-step: add a second disk or USB drive so it auto-mounts on every boot.
# 1. Get the UUID $ sudo blkid /dev/sdb1 /dev/sdb1: UUID="c3d4e5f6-3333-4444-5555-666677778888" TYPE="ext4" # 2. Create the mount point $ sudo mkdir -p /mnt/data # 3. Edit fstab $ sudo nano /etc/fstab
Add this line:
UUID=c3d4e5f6-3333-4444-5555-666677778888 /mnt/data ext4 defaults 0 2
# 4. Test without rebooting $ sudo mount -a # 5. Verify $ findmnt /mnt/data TARGET SOURCE FSTYPE OPTIONS /mnt/data /dev/sdb1 ext4 rw,relatime
sudo mount -a applies all fstab entries immediately. If it exits without errors, your fstab is correct. Always run this before rebooting after any fstab change.