Skip to main content
How To Manual & Auto Mount via fstab (Ext4/NTFS)

How To Manual & Auto Mount via fstab (Ext4/NTFS)

·746 words·4 mins
Zarvelion Zynji
Author
Zarvelion Zynji
Tech enthusiasts (self-proclaimed). Gaming addict (diagnosed). Anime simp (no regrets). I turn my hyperfixations into content—welcome to the chaos.
Table of Contents

Introduction
#

Mounting a drive in Linux is the process of connecting a storage device’s file system (HDD, SSD, USB, etc.) to a specific directory in the Linux directory structure. This tutorial will explain manual mounting and configuring auto-mount at boot for ext4 and NTFS file systems.

Prerequisites
#

  1. Root/sudo access
  2. Linux terminal
  3. The drive to be mounted is already connected to the system

Step 1: Identify the Drive
#

Before mounting, we need to identify the drive:

lsblk -f

or

sudo fdisk -l

Example output:

NAME   FSTYPE LABEL UUID                                 MOUNTPOINT  
sda  
├─sda1 ext4         a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8 /  
├─sda2 ext4   Data  1234abcd-5678-90ef-ghij-klmnopqrstuv  
└─sda3 ntfs   WinOS 87654321-DCBA-FE98-7654-3210ABCDEFGH  
nvme0n1  
├─nvme0n1p1  
└─nvme0n1p2  

Note the following key details:

  • Device name (e.g., /dev/sda2, /dev/sda3)
  • UUID (preferred over device names)
  • File system type (ext4, ntfs, etc.)
  • Label (if available)

Step 2: Create a Mount Point Directory
#

Create a directory where the drive will be mounted:

sudo mkdir /mnt/data       # For ext4 drive  
sudo mkdir /mnt/windows    # For NTFS drive  

Step 3: Manual (Temporary) Mount
#

Before editing fstab, perform a manual mount first to ensure no issues.

For ext4 file system:
#

sudo mount -t ext4 /dev/sda2 /mnt/data

or using UUID:

sudo mount -t ext4 UUID=1234abcd-5678-90ef-ghij-klmnopqrstuv /mnt/data

For NTFS file system:
#

sudo mount -t ntfs /dev/sda3 /mnt/windows

or using UUID:

sudo mount -t ntfs UUID=87654321-DCBA-FE98-7654-3210ABCDEFGH /mnt/windows

Verify the mount was successful:

df -h

Step 4: Configure Auto-Mount (fstab)
#

The /etc/fstab file controls auto-mounting at boot. First, back up the existing fstab:

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

Edit fstab:

sudo nano /etc/fstab

fstab Entry Format:
#

<file system> <mount point> <type> <options> <dump> <pass>

Example Entry for ext4:
#

UUID=1234abcd-5678-90ef-ghij-klmnopqrstuv /mnt/data ext4 defaults 0 2

Example Entry for NTFS:
#

UUID=87654321-DCBA-FE98-7654-3210ABCDEFGH /mnt/windows ntfs defaults,uid=1000,gid=1000,dmask=022,fmask=133 0 0

Explanation of Mount Options
#

General Options:
#

  • defaults: Uses default options (rw, suid, dev, exec, auto, nouser, async)
  • rw: Read-write
  • ro: Read-only
  • noexec: Prevents binary execution
  • nosuid: Ignores setuid/setgid bits
  • nodev: Disallows device files
  • sync: Synchronous I/O
  • async: Asynchronous I/O
  • auto: Mount at boot or with ‘mount -a’
  • noauto: Manual mount only
  • user: Allows regular users to mount
  • nouser: Only root can mount (default)
  • relatime: Updates inode access times relative to modify/change time
  • strictatime: Always updates access time
  • noatime: Does not update access time (improves performance)
  • nofail: Allows the system to boot even if the device is unavailable (useful for external disks)

ext4-Specific Options:
#

  • journal_checksum: Enables journal checksumming
  • journal_async_commit: Commit blocks can be written to disk without waiting for descriptor blocks
  • data=writeback: No data ordering (fastest)
  • data=ordered: Writes data only after metadata is committed (default)
  • data=journal: Journals all data before writing to the file system (safest but slowest)
  • discard: Enables TRIM (for SSDs)
  • nodelalloc: Disables delayed allocation
  • nodirtime: Disables access time updates for directories only (files still log access if noatime is not used)

NTFS-Specific Options:
#

  • uid=1000: Sets owner user (replace 1000 with your user’s UID)
  • gid=1000: Sets owner group
  • umask=022: Sets permission mask (0022 for rwxr-xr-x)
  • dmask=022: Directory permission mask
  • fmask=133: File permission mask (133 for rw-r–r–)
  • windows_names: Prevents creating files with invalid Windows characters
  • big_writes: Allows larger writes
  • norecover: Does not attempt recovery of a dirty file system

Step 5: Verify fstab Configuration
#

After editing fstab, verify there are no errors:

sudo mount -a

If no errors appear, the configuration is correct. If errors occur, fix them before rebooting.

Step 6: Reboot (Optional)
#

sudo reboot

After rebooting, verify the drive is auto-mounted:

df -h

Troubleshooting
#

  1. NTFS Mount Error: If NTFS fails to mount with “The disk contains an unclean file system,” use ntfsfix:

    sudo ntfsfix /dev/sdXn
    
  2. Permission Issues: For NTFS, ensure the correct uid and gid are used. Check uid/gid with:

    id username
    
  3. Drive Not Detected: If the drive doesn’t appear in lsblk, try:

    sudo partprobe
    
  4. Corrupt File System: For ext4, run fsck:

    sudo fsck /dev/sdXn
    

Additional Tips
#

  1. Always use UUID instead of device names (/dev/sdX) because UUIDs remain consistent even if device order changes.

  2. To list UUIDs of all file systems:

    sudo blkid
    
  3. To unmount a drive:

    sudo umount /mnt/data
    
  4. If mounting a directory with spaces in its name, use escape characters:

    UUID=xxx /mnt/My\040Data ntfs defaults 0 0
    

    (\040 is the ASCII code for space)

By following these steps, you should be able to mount ext4 and NTFS drives both manually and automatically at boot. Always verify fstab configurations before rebooting to avoid boot failures.


This translation maintains the original technical accuracy while adapting it for an English-speaking audience. Let me know if you’d like any refinements!


Load Comments