일. 8월 3rd, 2025

Struggling with manually mounting partitions every time you boot? Let’s fix that! The /etc/fstab file is your secret weapon for automating mounts in Linux. This guide breaks down fstab setup step by step—perfect for beginners.


What Is fstab?

fstab (File System Table) is a configuration file that tells Linux where and how to mount storage devices (partitions, USB drives, network shares) automatically at boot. No more manual mount commands!


Prerequisites

  1. Terminal Access: You’ll need sudo privileges.
  2. Know Your Device: Identify the partition (e.g., /dev/sdb1) or network share (e.g., nas:/data) you want to mount.
  3. Basic Linux Comfort: Familiarity with commands like lsblk, mkdir, and text editors (nano/vim).

Step 1: Identify Your Device

Use UUID (recommended for reliability) or device path:

lsblk -f  # Lists partitions with UUIDs and filesystems  

Example output:

sdb1  
└─UUID: 5e3a9d7a-01e2-4b4a-bd15-3c6f04d7b1e9  EXT4  

Step 2: Create a Mount Point

Choose where files will appear (e.g., /mnt/data):

sudo mkdir /mnt/data  # Replace "/mnt/data" with your desired path  

Step 3: Edit /etc/fstab

Open the file with elevated privileges:

sudo nano /etc/fstab  

Add a line using this structure:

[UUID or Device]  [Mount Point]  [Filesystem]  [Options]  [Dump]  [Pass]  

Example entry for an EXT4 partition:

UUID=5e3a9d7a-01e2-4b4a-bd15-3c6f04d7b1e9  /mnt/data  ext4  defaults  0  0  

Field Breakdown:

  1. Device: UUID (preferred) or path (e.g., /dev/sdb1).
  2. Mount Point: Directory you created (e.g., /mnt/data).
  3. Filesystem: Type like ext4, ntfs, nfs, or auto for auto-detect.
  4. Options:
    • defaults: Standard options (rw, exec, auto, etc.).
    • nofail: Prevents boot errors if device is missing.
    • user: Allows non-root users to mount.
  5. Dump: Set to (disabled) for backups.
  6. Pass: = no boot fsck, 1 = root fsck, 2 = non-root fsck.

Step 4: Test & Apply

Avoid reboot mistakes with:

sudo mount -a  # Mounts all entries in fstab  

Verify success:

df -h | grep /mnt/data  # Check if mounted  

If errors appear, check logs:

dmesg | tail  # Diagnose issues  

Common Use Cases

  1. NTFS Drives (Windows):

    UUID=1234ABCD /mnt/win ntfs-3g defaults,uid=1000,gid=1000 0 0  

    (Replace uid/gid with your user’s ID from id -u/id -g)

  2. NFS Network Shares:

    nas:/shared /mnt/nfs nfs defaults 0 0  
  3. External USB (Prevent Boot Hangs):

    UUID=ABCD5678 /media/usb auto nofail,user 0 0  

Troubleshooting Tips

  • Typos: Double-check UUIDs and paths! Use blkid to verify.
  • Filesystem Errors: Run fsck on the device if corrupted.
  • Mount Fails: Add nofail to options if the device isn’t always connected.
  • Read-Only Issues: Ensure NTFS/NTFS-3g drivers are installed.

Why Automate with fstab?

Saves time: No manual mounting after reboots.
Flexible: Supports local, network, and exotic filesystems.
Reliable: UUIDs persist even if device paths change.

Warning: Incorrect fstab edits can break your system! Always test with mount -a before rebooting.


Mastering fstab unlocks seamless storage management. Got questions? Share them in the comments below! 🐧💾

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다