Mount a Drive Permanently with fstab in Linux

💾 TL;DR for the Impatient

Permanently mount drives in Linux using /etc/fstab with UUIDs for stability. Create mount point, backup fstab, add entry with proper format, and test before rebooting.

What is fstab and Why Use It?

The /etc/fstab (file systems table) is a system configuration file that defines how disk partitions, various other block devices, or remote filesystems should be mounted into the filesystem. Think of it as Linux’s “auto-mount rulebook” that runs every time your system boots.

Why choose fstab over manual mounting?

Got a new drive that you want to access automatically every time your Linux system boots? While you can manually mount drives using the mount command each time, that’s hardly convenient for drives you use regularly.

This comprehensive guide will walk you through the entire process of permanently mounting drives using fstab, ensuring your storage is always ready when you need it.

Common Use Cases for Permanent Mounts

Understanding when to use fstab can help you decide if this guide is right for your situation:

External Storage

Internal Storage

Network Storage

Special Cases

Prerequisites

Before diving in, make sure you have:

Alternative Methods (When NOT to Use fstab)

While fstab is excellent for permanent mounts, consider these alternatives for specific scenarios:

AutoFS: Better for network shares that aren’t always available

# Install autofs for on-demand mounting
sudo apt install autofs  # Ubuntu/Debian
sudo yum install autofs  # CentOS/RHEL

Systemd Mount Units: For more complex mounting logic

# Create systemd mount unit
sudo systemctl edit --force --full mnt-mydrive.mount

udisks2: For user-space mounting without root privileges

# Mount as regular user
udisksctl mount -b /dev/sdb1

Step 1: Identify Your Drive

First, you need to identify both the device name and UUID of the drive you want to mount. The UUID (Universal Unique Identifier) is preferred because it remains constant even if device names change.

Find the UUID

sudo blkid

This will output something like:

/dev/sda1: UUID="b8e4a1f6-6e8f-4f6e-8b6e-6e8f4f6e8b6e" BLOCK_SIZE="4096" TYPE="ext4"
/dev/sdb1: UUID="c8e4a1f6-6e8f-4f6e-8b6e-6e8f4f6e8b6e" BLOCK_SIZE="4096" TYPE="ntfs"

Identify Device Names

To see a tree-like view of all connected drives:

lsblk

Output example:

NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    0 931.5G  0 disk
└─sda1        8:1    0 931.5G  0 part
sdb           8:16   1  64.0G  0 disk
└─sdb1        8:17   1  64.0G  0 part
nvme0n1     259:0    0 931.5G  0 disk
├─nvme0n1p1 259:1    0     4M  0 part
└─nvme0n1p2 259:2    0 931.5G  0 part /

Additional Drive Information Commands

For more detailed drive information:

# Show partition table and filesystem info
sudo fdisk -l

# Display drive health and SMART data
sudo smartctl -a /dev/sda

# Show filesystem usage and inodes
sudo tune2fs -l /dev/sda1  # For ext2/3/4 filesystems

Note down both the device name (e.g., /dev/sdb1) and its corresponding UUID from the blkid output.

Step 2: Create the Mount Point

Mount Point Best Practices

Choose mount points that make sense for your workflow:

Standard Locations:

Naming Conventions:

# Good examples
/mnt/backup-drive
/mnt/photos-2024
/media/usb-backup
/data/projects

# Avoid spaces and special characters
/mnt/my drive        # Bad - contains space  
/mnt/backup&restore  # Bad - contains special char

Create a directory where your drive will be mounted. Common locations are /mnt or /media:

sudo mkdir /mnt/mydrive

Choose a descriptive name that reflects the drive’s purpose. For example:

Step 3: Backup fstab (Critical Step!)

Always backup the fstab file before editing – a corrupted fstab can prevent your system from booting:

sudo cp /etc/fstab /etc/fstab.backup

Step 4: Edit the fstab File

Open fstab with your preferred text editor:

sudo nano /etc/fstab

Add a new line at the end of the file following this format:

UUID=your-drive-uuid /mnt/mydrive filesystem-type defaults 0 2

Real Example

UUID=b8e4a1f6-6e8f-4f6e-8b6e-6e8f4f6e8b6e /mnt/mydrive ext4 defaults 0 2

Understanding Each Field

  1. UUID: The unique identifier of your drive (more reliable than device names)
  2. Mount Point: The directory where the drive will be mounted (/mnt/mydrive)
  3. Filesystem Type: The drive’s filesystem (ext4, ntfs, vfat, xfs, etc.)
  4. Mount Options: defaults is suitable for most cases
  5. Dump: Set to 0 (modern systems don’t use dump)
  6. Pass: Set to 2 for non-root filesystems, 1 for root, 0 to skip fsck

Complete Mount Options Reference

Here’s a comprehensive list of mount options you might need:

Performance Options:

Security Options:

User Options:

Filesystem-Specific Options:

# NTFS drives
defaults,uid=1000,gid=1000,umask=022,windows_names

# FAT32/VFAT drives  
defaults,uid=1000,gid=1000,umask=022,utf8

# Network shares (NFS)
defaults,_netdev,timeo=14,intr

# Encrypted drives
defaults,noauto,user,exec

Common Mount Options

Instead of defaults, you might want:

Step 5: Test Your Configuration

Before rebooting, test that your configuration works:

# If the drive is currently mounted, unmount it first
sudo umount /mnt/mydrive

# Test mount all fstab entries
sudo mount -a

Verify the drive mounted successfully:

df -h | grep mydrive

You should see your drive listed with its mount point.

Step 6: Verify Automatic Mounting

Reboot your system to ensure the drive mounts automatically:

sudo reboot

After reboot, check that your drive is mounted:

df -h
# or
lsblk

Security Considerations

When permanently mounting drives, keep these security aspects in mind:

Permission Management

# Set proper ownership after mounting
sudo chown -R $USER:$USER /mnt/mydrive

# Set appropriate permissions
sudo chmod 755 /mnt/mydrive  # Directory permissions
sudo chmod 644 /mnt/mydrive/* # File permissions (if needed)

Mounting External Drives Safely

# Secure mount for untrusted external drives
UUID=your-uuid /mnt/external ntfs defaults,noexec,nosuid,nodev,uid=1000 0 0

Network Share Security

# Secure NFS mount with specific user
server:/share /mnt/nfs nfs defaults,_netdev,sec=krb5 0 0

# SMB with credentials file (more secure than inline passwords)
//server/share /mnt/smb cifs defaults,credentials=/etc/cifs-credentials,uid=1000 0 0

Performance Optimization

SSD Optimization

For SSD drives, add these mount options for better performance and longevity:

# SSD-optimized mount
UUID=your-uuid /mnt/ssd ext4 defaults,noatime,discard 0 2

Large Drive Optimization

For drives over 1TB or with many files:

# Optimized for large drives
UUID=your-uuid /mnt/bigdrive ext4 defaults,noatime,commit=60 0 2

Troubleshooting Common Issues

If your drive doesn’t mount properly:

Check for Syntax Errors

sudo mount -a

This will show any fstab syntax errors.

Verify Mount Point Exists

ls -la /mnt/mydrive

Check System Logs

sudo journalctl -b | grep mount
# or
dmesg | grep -i mount

Common Problems and Solutions

Problem: Drive doesn’t mount after reboot

Problem: “mount: wrong fs type” error

Problem: Permission denied when accessing mounted drive

Problem: System won’t boot after editing fstab

Emergency Recovery

If your system won’t boot due to fstab errors:

  1. Boot into Recovery Mode

    • Hold Shift during boot (GRUB menu)
    • Select “Advanced options” → “Recovery mode”
  2. Mount Root Filesystem as Read-Write

    mount -o remount,rw /
    
  3. Fix fstab

    # Restore backup
    cp /etc/fstab.backup /etc/fstab
    
    # Or edit directly
    nano /etc/fstab
    
  4. Test Before Reboot

    mount -a
    # If no errors, reboot
    reboot
    

Advanced Scenarios

For NTFS Drives

UUID=your-uuid /mnt/mydrive ntfs defaults,uid=1000,gid=1000,umask=022 0 0

For Network Shares (NFS)

server:/path/to/share /mnt/nfs nfs defaults,_netdev 0 0

For Encrypted Drives (LUKS)

For LUKS encrypted drives, you need both crypttab and fstab entries:

  1. Add to /etc/crypttab:

    mydrive_crypt UUID=encrypted-partition-uuid none luks
    
  2. Add to /etc/fstab:

    /dev/mapper/mydrive_crypt /mnt/encrypted ext4 defaults 0 2
    

Conditional Mounting

Mount only if drive is present (useful for removable drives):

# Use noauto and add custom systemd service
UUID=your-uuid /mnt/mydrive ext4 defaults,noauto 0 0

Bind Mounts

Mount a directory to another location:

# Mount subdirectory elsewhere
/mnt/storage/photos /home/user/Pictures none bind 0 0

Monitoring and Maintenance

Regular Health Checks

Keep your mounted drives healthy with regular maintenance:

# Check filesystem health
sudo fsck -n /dev/sdb1  # Read-only check

# Monitor disk usage
df -h
du -sh /mnt/mydrive/*

# Check for errors in system logs
sudo journalctl -u systemd-fsck@dev-sdb1.service

Automated Backup Verification

Create a script to verify your mounted drives are working:

#!/bin/bash
# /usr/local/bin/check-mounts.sh

for mount_point in /mnt/mydrive /mnt/backup; do
    if mountpoint -q "$mount_point"; then
        echo "✓ $mount_point is mounted"
        # Test write access
        if touch "$mount_point/.test" 2>/dev/null; then
            rm "$mount_point/.test"
            echo "✓ $mount_point is writable"
        else
            echo "✗ $mount_point is not writable"
        fi
    else
        echo "✗ $mount_point is not mounted"
    fi
done

Distribution-Specific Notes

Ubuntu/Debian

# Install necessary tools
sudo apt update
sudo apt install util-linux parted ntfs-3g

# For GUI users, consider using GNOME Disks
sudo apt install gnome-disk-utility

CentOS/RHEL/Fedora

# Install necessary tools
sudo dnf install util-linux parted ntfs-3g  # Fedora
sudo yum install util-linux parted ntfs-3g  # CentOS/RHEL

# SELinux considerations
sudo setsebool -P use_nfs_home_dirs 1  # For NFS home directories

Arch Linux

# Install necessary packages
sudo pacman -S util-linux parted ntfs-3g

# For AUR helpers
yay -S ntfs-3g-fuse  # Alternative NTFS support

Best Practices

To expand your Linux storage management skills, consider exploring:

Advanced Storage Topics:

Automation and Monitoring:

Security Deep Dive:

Useful Commands to Remember:

# Quick reference commands
man fstab          # Complete fstab documentation
man mount          # Mount command options
lsof /mnt/mydrive  # See what's using the mount
umount -l /mnt/    # Lazy unmount if drive is busy
findmnt            # Show mounted filesystems in tree format

Conclusion

Permanently mounting drives using fstab is an essential Linux skill that saves time and ensures your storage is always available. By following this guide, you’ve learned not just how to mount drives, but also how to troubleshoot issues and implement best practices.

The key takeaways are using UUIDs for reliability, always backing up fstab, and testing configurations before rebooting. With these practices, you’ll have robust, automatically-mounted storage that works seamlessly with your Linux system.

For more advanced scenarios like mounting encrypted drives or network shares, consider exploring the extensive mount options available in the man fstab and man mount documentation.

Happy mounting!

Stay up to date

Get notified when I publish something new, and unsubscribe at any time.

Join 44 other subscribers.

Contact Pavlin Gunov at contact@pavlinbg.com

Phone: +1234567890

Address: Sofia, Bulgaria

© 2025 Pavlin

Instagram GitHub