Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Permanently Mount a Drive in Linux: Step-by-Step

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To permanently mount a drive in Linux, you add an entry to the /etc/fstab file. This tells the system to mount the drive automatically at boot, so you don't have to run mount manually every time. It also gives you control over mount options like permissions and filesystem type. Below is a safe, accurate guide that works on most modern distributions (Ubuntu, Debian, Fedora, etc.).

What You'll Need

  • A Linux system with sudo access (administrative privileges).
  • The drive you want to mount (internal or external) already connected.
  • A terminal window (Ctrl+Alt+T on most desktops).
  • Basic familiarity with command line editing (we'll use nano or vim, but any text editor works).

Step-by-Step

  1. Identify the drive – Run lsblk in the terminal. This lists all block devices. Look for your drive by size or label (e.g., /dev/sdb1). Note the exact device name (e.g., /dev/sdb1) and its filesystem type (e.g., ext4, ntfs, exfat). If you're unsure, run sudo blkid – it shows the UUID and filesystem type for each partition.
  2. Create a mount point – A mount point is a directory where the drive will appear. For example, sudo mkdir /mnt/mydrive. Use a descriptive name. Avoid mounting directly under / or /home unless you know what you're doing.
  3. Back up your fstab file – Before editing, make a copy: sudo cp /etc/fstab /etc/fstab.backup. This lets you restore if something goes wrong.
  4. Find the drive's UUID – Run sudo blkid /dev/sdb1 (replace with your device). The UUID is a long string like 5f3c9a2e-... . Using the UUID is more reliable than device names (like /dev/sdb1) because device names can change between reboots.
  5. Edit /etc/fstab – Open the file with sudo nano /etc/fstab (or sudo vim /etc/fstab). Add a new line at the end in this format:
    UUID=your-uuid-here /mnt/mydrive ext4 defaults 0 2
    Replace your-uuid-here with the actual UUID, /mnt/mydrive with your mount point, and ext4 with your filesystem type (e.g., ntfs-3g for NTFS, exfat for exFAT). The defaults option works for most internal drives. For external drives you might add nofail to avoid boot delays if the drive is absent (see Tips).
  6. Save and close the file – In nano, press Ctrl+O, then Enter, then Ctrl+X. In vim, press Esc, type :wq, then Enter.
  7. Test the mount – Run sudo mount -a. This reads fstab and mounts everything listed. If there are no errors, your drive is now mounted. Check with lsblk or df -h.
  8. Reboot to confirm – Restart your system. After boot, the drive should be mounted automatically. If not, see Troubleshooting below.

Common Mistakes

  • Using device names instead of UUID – /dev/sdb1 can change to /dev/sdc1 after adding another drive. Always use UUID.
  • Wrong filesystem type – If you specify the wrong type (e.g., ext4 for an NTFS drive), mount fails. Check with blkid.
  • Missing mount point – The directory must exist before mounting. If you delete it later, the mount fails.
  • Typos in fstab – A single wrong character can prevent boot. That's why we test with mount -a before rebooting.
  • Forgetting the nofail option for external drives – If an external drive is not connected at boot, the system may hang or show errors. Add nofail to the options column (e.g., defaults,nofail).

Tips

  • Use nofail for removable drives – This prevents boot errors if the drive is unplugged. It's safe for internal drives too.
  • Set proper permissions – If you want to write as a normal user, add uid=1000,gid=1000 (replace with your user ID) to the options for vfat/exfat/ntfs drives. For ext4, you can use chown after mounting.
  • Use discard for SSDs – If your drive is an SSD with ext4, adding discard enables TRIM. But only if your kernel supports it – most do.
  • Keep fstab simple – Don't add options you don't understand. defaults is usually enough for internal drives.
  • Document your fstab – Add a comment (line starting with #) above your entry, like # My backup drive, to remember what it is.

Troubleshooting

If sudo mount -a gives an error: Read the error message carefully. It usually tells you the exact problem – wrong UUID, wrong filesystem, or missing mount point. Fix the fstab line and try again.

If the system won't boot after editing fstab: You'll see a message like “an error occurred while mounting /mnt/mydrive”. Press Ctrl+D to continue booting in emergency mode. Then edit fstab to fix the error, or restore from backup: sudo cp /etc/fstab.backup /etc/fstab. If you can't get to a terminal, boot from a live USB and edit the fstab from there.

If the drive mounts but you can't write to it: Check permissions. For NTFS/exFAT, add uid=1000,gid=1000 to options (replace 1000 with your user ID from id -u). For ext4, run sudo chown -R $USER:$USER /mnt/mydrive after mounting.

If the drive mounts but appears empty: Make sure you're mounting the correct partition. Sometimes the whole disk (/dev/sdb) is listed, but you need the partition (/dev/sdb1). Use lsblk to check.

If the drive doesn't mount at boot but works with mount -a: This can happen if the drive isn't ready when fstab is processed. Add nofail and possibly x-systemd.device-timeout=10 (for systemd systems) to the options to wait a bit longer.

Frequently Asked Questions

Is it safe to edit /etc/fstab?

Yes, as long as you back it up first and test with mount -a before rebooting. A wrong entry can cause boot issues, but you can always recover by editing from a live USB.

What does the “0 2” at the end of the fstab line mean?

The first number is the dump flag (usually 0). The second is the fsck order: 1 for root, 2 for other drives, 0 to skip checking. Using 0 is fine for most drives, but 2 is common for data drives.

Can I mount a Windows NTFS drive permanently?

Yes. Use ntfs-3g as the filesystem type (e.g., ntfs-3g). You may need to install ntfs-3g first: sudo apt install ntfs-3g (Debian/Ubuntu) or sudo dnf install ntfs-3g (Fedora).

What is the difference between /mnt and /media?

/media is typically used for automatically mounted removable media (like USB sticks). /mnt is for manual mounts. Either works, but using /mnt for permanent mounts is conventional.

Can I mount a network drive in fstab?

Yes, for NFS or SMB/CIFS shares. For example: //server/share /mnt/share cifs credentials=/etc/smbcreds,uid=1000,gid=1000 0 0. You'll need the cifs-utils package installed.

What if my drive has a partition table but no filesystem?

You need to format it first. Use sudo mkfs.ext4 /dev/sdb1 (or mkfs.ntfs for NTFS). Warning: this erases all data on that partition. Only do this if you're sure.