Edit fstab to Auto-Mount Secondary Hard Drives on Linux

If you are using Linux and have multiple hard drives in your system, you may find that the system does not auto-mount the secondary hard drive when you start up your computer. You’re probably mounting it manually with your file manager (or even a terminal command), and this isn’t the best way to go about it.

Did you know that there’s an easier way to mount your secondary hard drive on Linux? It’s an easy process that just involves a few, simple edits to the fstab file on your system.

Before you can set up your second hard drive, you’ll need to determine some information about it. This can be easily done by opening a terminal and entering the command below.

lsblk

fstab-lsbk-hard-drive-system-name-and-partition-information

You’ll notice that entering this command prints out some detailed information on the storage drives connected to your machine. If you have your second hard drive connected (mounted or not), the information you’ll need to pay attention to will be something similar to this.

Note: depending on your drive configuration, your hard drive might be called something different instead of /dev/sdb.

With the help of lsblk, we know the drive we’re working with is known as /dev/sdb, and the partition we need is known as /dev/sdb1. Now we need to determine the exact file system. We can do this by running the parted command.

sudo parted /dev/sdb -l

fstab-parted-hard-drive-file-system-information

Parted will tell you your drive’s file system. Look for whatever file system is printed in the terminal. In this guide we’ll be using NTFS.

This information will be crucial later on down the line when we’re modifying the system file, so don’t forget the information you’ve just gathered about your hard drive.

All of the information has been gathered. Now it’s time to create a folder for your hard drive to live in. It’s very important that you make your hard drive’s folder in your home directory.

mkdir ~/Storage

Why in the home directory? Simple: you won’t have any issues changing permissions for your user to access the hard drive. Since it’s in your home directory, you can already access it just fine.

fstab is a crucial piece of your Linux installation. Since it’s an important file, it would be best that we back up this file before editing it. That way, if you mess something up, you can just restore the backup.

sudo mkdir /etc/backup
sudo cp /etc/fstab /etc/backup/fstab

Doing this will make a copy of your fstab configuration file for you to restore later if you need to.

Modifying the fstab file can be touchy. Don’t be worried about any mistakes. Remember, your configuration is backed up! To edit the file, enter this command:

sudo nano /etc/fstab

This will bring up the fstab file in the Nano text editor. Now it’s time to write in our secondary drive to the configuration file.

fstab-unmodified-file-system-configuration-file

If you look at the picture above, you’ll see that there are several different points in this file: file system, dir, type, options, dump and pass. All of these are important and will need to be filled out in order for your drive to mount in the directory created earlier.

Let’s start with the file system option. Going off the information that the lsblk command told us, we know the file system we need is /dev/sdb1. Enter /dev/sdb1 under <file system>.

fstab-specify-file-system-for-hard-drive

Note: don’t worry if the text you enter isn’t exactly under things like <file system>. All that matters is that the text is written in the right order.

After telling fstab which file system to use, we’ll need to point it to a directory. Enter “/home/username/Storage” under <dir>.

fstab-specify-file-directory-for-hard-drive

Using the information gained from entering the parted command, enter your drive’s file system type under <type>.

fstab-parted-hard-drive-specify-file-system-type

Time to specify the options for your hard drive. Enter defaults,noatime under <options>.

fstab-specify-file-system-options-for-fstab-configuration

Put the number 0 under <dump>.

fstab-specify-dump-option-for-file-system

Finally, put the number 2 under <pass>.

fstab-specify-pass-option-for-file-system

After that press “Ctrl + O” to save the newly edited file to your system. When you reboot, you’ll be able to access your new hard drive inside the Storage folder located in your home directory.

Did you decide you don’t want this sort of configuration anymore? Not to worry! Restoring is incredibly simple. Just open a terminal window and enter the following commands.

cd /etc/
sudo rm fstab
sudo cp /etc/backup/fstab /etc/

Running these commands will delete your modified fstab file and put a copy of the backup file in its place. After that just reboot your machine and everything will be back to normal!

Linux tends to handle secondary hard drives very well. The only real downside is if you want access to your drives at boot, you’ll need to tinker with system files. Most people won’t find it a nuisance opening up a text editor and adding a few lines to get a drive working, and that’s great.

I hope that the next generation of Linux distributions will add a feature that sets this all up beforehand. That’s the dream. It’ll happen one day, but until then we have this method.

Do you auto mount secondary hard drives on your Linux install? Why or why not? Let us know in the comments section below!