Back to graph

Page

Mounting an External Drive Using fstab

Page IDmounting-with-fstabUpdated

The fstab (file system table) file tells Linux which storage devices to mount at boot and where to place them in the directory tree. This guide walks you through mounting an external drive permanently using UUIDs, a robust method that survives reordering or renaming of device paths.

Prerequisites ๐Ÿ“‹

  • A connected external hard drive (USB, SATA via enclosure, etc.)
  • Root/sudo access to your Linux system
  • Basic familiarity with the terminal and text editors (nano, vim)

๐Ÿ’ก Tip: Always back up /etc/fstab before editing. One typo can prevent booting.


Step 1: Identify Your Drive ๐Ÿ”

Find Available Drives

List all block devices and their current mount points:

lsblk -f

Look for your external drive (e.g., /dev/sdb, /dev/nvme0n1p2). Note the UUID, filesystem type, and partition name.

Alternative: Use `blkid`

For detailed UUIDs:

sudo blkid /dev/sdXN  # Replace sdXN with your drive (e.g., sdb1)

Output example:

/dev/sdb1: UUID="a1b2c3d4-e5f6-7890-abcd-ef1234567890" TYPE="ext4"

Step 2: Create a Mount Point ๐Ÿ“

Create an empty directory where the drive will be accessible:

sudo mkdir -p /mnt/external-drive

The -p flag creates parent directories if needed.

โœ… Best Practice: Use descriptive names like /mnt/data, /mnt/backups, or /mnt/media. Avoid spaces in paths.


Step 3: Test Mounting Manually ๐Ÿงช

Before editing fstab, test that the drive mounts correctly:

sudo mount /dev/sdXN /mnt/external-drive

Check if it works:

df -h | grep external-drive
lsblk

If successful, unmount to proceed:

sudo umount /mnt/external-drive

Step 4: Edit `/etc/fstab` โœ๏ธ

Open the file with a text editor (use nano for simplicity):

sudo nano /etc/fstab

Add a new line at the end using this format:

UUID=a1b2c3d4-e5f6-7890-abcd-ef1234567890  /mnt/external-drive  ext4  defaults,nosuid,nodev,noatime  0  2

Field Breakdown:

Column Description
UUID Unique identifier for the partition (most reliable)
Mount Point Directory where drive will be mounted (/mnt/external-drive)
Filesystem Type ext4, ntfs-3g (for NTFS), vfat, etc.
Options Comma-separated flags like defaults,nosuid,nodev,noatime
Dump Usually 0 for non-root drives (1 rarely used)
Pass Order Filesystem check order at boot; use 2 for data drives, 1 only for root

Common Options:

  • defaults: Standard options (rw, suid, dev, exec, auto, nouser, async)
  • noatime: Improves performance by skipping access time updates
  • nosuid,nodev: Prevents special permissions on the mount point
  • user,noauto,rw,sync โ€“ For removable drives mounted manually (not in fstab at boot)
  • defaults,dmask=022,fmask=133,uid=1000,gid=1000 โ€“ NTFS-specific for ownership/permissions

โš ๏ธ NTFS Note: If mounting an NTFS drive (common with Windows dual-boot), use the filesystem type ntfs-3g. Install it first if missing:

# Debian/Ubuntu
sudo apt install ntfs-3g
# Arch/Fedora
sudo pacman -S ntfs-3g

Step 5: Verify and Test โœ…

Reload fstab without rebooting:

sudo mount -a

If no errors appear, your entry is valid. Check the drive is mounted:

df -h | grep external-drive
mount | grep /mnt/external-drive

Step 6: Reboot and Confirm ๐Ÿ”„

Reboot to ensure automatic mounting works at boot:

sudo reboot

After restart, verify the drive is mounted automatically.


Troubleshooting ๐Ÿ”ง

Issue: Boot Hangs in Emergency Mode โŒ

Cause: Typo or invalid UUID in /etc/fstab
Fix:

  1. Reboot and drop into emergency mode (or use a live USB)
  2. Remount root as read-write:
    mount -o remount,rw /
    
  3. Edit fstab: nano /etc/fstab
  4. Comment out the problematic line with # or correct it
  5. Reboot: reboot

Issue: Drive Not Mounting After Boot ๐Ÿšซ

Check:

  • Is UUID correct? Run sudo blkid again.
  • Are options valid for your filesystem?
  • Does the mount point exist and have permissions:
    ls -ld /mnt/external-drive
    sudo chown $USER:$USER /mnt/external-drive
    

Issue: NTFS Drive Shows Read-Only ๐Ÿ“‰

Cause: Windows "Fast Startup" leaves the drive in a dirty state.
Fix:

  1. Boot into Windows and perform a full shutdown (not restart)
  2. Or use ntfsfix from Linux:
    sudo ntfsfix /dev/sdXN
    
  3. Remount with proper options in fstab.

Quick Reference Table ๐Ÿ“Š

Scenario Filesystem Type Example Options
Linux ext4 data drive ext4 defaults,nosuid,nodev,noatime
NTFS Windows partition ntfs-3g defaults,uid=1000,gid=1000,dmask=022,fmask=133
FAT32 USB stick (removable) vfat user,noauto,rw,sync,dmask=022,fmask=133

Final Checklist โœ…

  • Drive identified with correct UUID via blkid
  • Mount point created (/mnt/...)
  • Manual mount tested successfully
  • /etc/fstab entry added and validated with mount -a
  • Rebooted to confirm automatic mounting
  • Backup of original fstab saved (e.g., cp /etc/fstab /etc/fstab.bak)

With this setup, your external drive will mount automatically at boot, accessible without password prompts or manual intervention. ๐ŸŽ‰