Mounting a drive permanently in Linux requires adding an entry to the fstab configuration file. This is the core of how to permanently mount a drive in linux, and it ensures your drive is available every time you boot up. Without this step, you would have to manually mount the drive each session, which is tedious and impractical for drives you use daily.
In this guide, you will learn the exact steps to make a drive mount automatically. We will cover finding the drive, creating a mount point, editing the fstab file, and testing everything. By the end, you will have a reliable, permanent mount that survives reboots.
Understanding The Fstab File
The fstab file, located at /etc/fstab, is a system configuration file that tells Linux which filesystems to mount and where. Each line in fstab represents a filesystem entry with specific options. When your system boots, it reads this file and mounts everything listed.
To edit fstab, you need root privileges. Always make a backup before making changes. A simple mistake can prevent your system from booting properly, so proceed carefully.
What You Need Before Starting
- Root or sudo access
- The drive you want to mount (internal or external)
- A terminal window
- Basic familiarity with command line
How To Permanently Mount A Drive In Linux
Now we get into the practical steps. Follow these in order to avoid errors. The process involves identifying your drive, formatting it if needed, creating a mount point, and editing fstab.
Step 1: Identify Your Drive
First, you need to know the device name of your drive. Use the lsblk command to list all block devices. This shows partitions and their sizes.
lsblk
Look for your drive by size or label. It will appear as something like /dev/sdb1 or /dev/nvme0n1p1. If you are unsure, use the -f flag to see filesystem types:
lsblk -f
This also shows UUIDs, which are unique identifiers. UUIDs are preffered for fstab because they remain constant even if device names change.
Step 2: Check The Filesystem
If your drive is new or unformatted, you need to create a filesystem. Common choices are ext4 for Linux, NTFS for Windows compatibility, or FAT32 for universal use. Use mkfs to format:
sudo mkfs.ext4 /dev/sdb1
Warning: This erases all data on the partition. Double-check you have the correct device.
Step 3: Create A Mount Point
A mount point is a directory where the drive will be accessible. Create it anywhere, but common locations are /mnt or /media. For example:
sudo mkdir /mnt/mydrive
Choose a descriptive name so you remember what it is. You can also create it in your home directory, but system-wide mounts are better in /mnt.
Step 4: Get The UUID
Using the UUID is the safest way to reference your drive. Run blkid to see UUIDs:
sudo blkid
Copy the UUID for your partition. It looks like a long string: “a1b2c3d4-e5f6-7890-abcd-ef1234567890”. Keep it handy for the next step.
Step 5: Edit The Fstab File
Open /etc/fstab with a text editor as root. Use nano or vim:
sudo nano /etc/fstab
Add a new line at the end of the file. The format is:
UUID=your-uuid-here /mnt/mydrive ext4 defaults 0 2
Replace “your-uuid-here” with the actual UUID. The mount point is /mnt/mydrive. The filesystem type is ext4 (adjust if needed). “defaults” is a common option set. The last two numbers are dump and pass; 0 2 is typical for data drives.
Step 6: Test The Entry
Before rebooting, test if the fstab entry works. Run:
sudo mount -a
This mounts all filesystems in fstab. If there are no errors, your drive should now be mounted. Check with:
df -h
Look for your mount point. If it appears, the entry is correct. If you get errors, review your fstab line for typos.
Step 7: Reboot And Verify
Finally, reboot your system:
sudo reboot
After logging back in, check that the drive is still mounted. Use lsblk or df -h. If everything is fine, you have successfully made the mount permanent.
Common Fstab Options Explained
The “defaults” option set includes rw, suid, dev, exec, auto, nouser, and async. For most users, this is sufficient. However, you may need specific options for certain situations.
Useful Options
- noauto: Do not mount at boot. Useful for removable drives.
- user: Allow any user to mount the drive.
- uid and gid: Set ownership to a specific user or group.
- umask: Set permissions for NTFS or FAT drives.
For example, to mount an NTFS drive with full read/write for your user:
UUID=... /mnt/windrive ntfs-3g defaults,uid=1000,gid=1000,umask=022 0 0
Replace uid and gid with your user’s ID (find it with id -u).
Mounting Network Drives Permanently
You can also use fstab to mount network shares like NFS or Samba. The process is similar but uses different filesystem types and options.
NFS Example
For an NFS share:
server:/export /mnt/nfs nfs defaults 0 0
Replace “server:/export” with the actual server and path.
Samba/CIFS Example
For a Windows share:
//server/share /mnt/smb cifs username=user,password=pass,uid=1000,gid=1000 0 0
Storing passwords in fstab is not secure. Use a credentials file instead:
//server/share /mnt/smb cifs credentials=/etc/smbcreds,uid=1000,gid=1000 0 0
Create /etc/smbcreds with:
username=user
password=pass
Then set permissions to 600.
Troubleshooting Common Issues
Even with careful steps, problems can occur. Here are frequent issues and fixes.
Drive Not Mounting After Reboot
If the drive does not mount, check fstab for errors. Use:
sudo mount -a
If it fails, look at the error message. Common causes are wrong UUID, incorrect filesystem type, or missing mount point.
Permission Denied
If you cannot write to the drive, check ownership and permissions. Use chown to change owner:
sudo chown -R youruser:yourgroup /mnt/mydrive
For NTFS/FAT, use uid and gid options in fstab.
System Fails To Boot
If you make a critical error in fstab, the system may drop to a recovery shell. Boot from a live USB, mount your root partition, and edit fstab to fix the line. Always keep a backup.
Advanced Mounting Techniques
For power users, there are additional ways to manage mounts.
Using Systemd Mount Units
Instead of fstab, you can create a systemd mount unit. This offers more control and integration with systemd. Create a file like /etc/systemd/system/mnt-mydrive.mount:
[Unit]
Description=My Drive Mount
[Mount]
What=/dev/disk/by-uuid/your-uuid
Where=/mnt/mydrive
Type=ext4
Options=defaults
[Install]
WantedBy=multi-user.target
Then enable it:
sudo systemctl enable mnt-mydrive.mount
Using Autofs
Autofs mounts drives on demand. It is useful for network shares or removable media. Install autofs and configure /etc/auto.master and /etc/auto.misc.
Frequently Asked Questions
What is the safest way to edit fstab?
Always back up the original file: sudo cp /etc/fstab /etc/fstab.backup. Use a text editor and double-check your syntax before saving.
Can I mount a drive without a UUID?
Yes, you can use the device path like /dev/sdb1, but this is not recommended because device names can change (e.g., after adding new drives). UUIDs are stable.
How do I mount a drive with special characters in its label?
Use the UUID instead of the label. Labels with spaces or special characters can cause issues in fstab.
Why does my drive mount read-only?
This often happens with NTFS or FAT drives that were not unmounted properly. Use the “uid” and “gid” options, or run a filesystem check on Windows.
Can I use fstab for external USB drives?
Yes, but use the “noauto” option if you do not want it to mount at boot. You can then mount it manually when connected.
Final Tips For Permanent Mounts
Always test your fstab entry with sudo mount -a before rebooting. This catches errors early. If you are unsure about options, start with “defaults” and adjust later.
Remember that fstab is read at boot, so changes take effect after reboot. For immediate mounting, use mount -a after editing.
With these steps, you now know how to permanently mount a drive in linux. It is a fundamental skill that makes your system more convenient and reliable. Practice on a test drive first if you are nervous.
By mastering fstab, you gain control over your storage. Whether it is an internal SSD, a USB drive, or a network share, permanent mounting simplifies your workflow. Happy mounting!