Auto-mounting second hard drive in Linux

In Linux, auto-mounting a second hard drive on boot seems difficult particularly for users coming from windows. So, I wanted to make this easy to understand and implement. If you have Linux installed on one hard drive and there is a second one in your system. But you’re tired of mounting it manually in a file manager after every boot to access the data on it, then follow along with me.

If you prefer not to edit the fstab file and wanted to do it easily using a gui. Install gnome disks utility. Right-click on the second hard drive and select edit mount options and un-select user session defaults. See the below picture.

Gnome disks Utility mount options

Select mount on startup and enter the mount point(or)mount directory, file system type of second hard drive(if you don’t know, see below 2) and set mount options as default. press Ok and reboot.

1. Create a mount point or mount directory.

First thing, you need to create a directory as a mount point for mounting your second hard drive. Open the terminal and enter the command.

sudo mkdir /media

Here media is the directory for mounting the hard drive. Don’t mount your hard drive in /mnt directory or run/mnt or /run/media. These other directories require changing file permissions of the second hard drive.

Create a sub-directory with your username as it’s name within the media directory. Now create a mount point for the second hard drive within the sub-directory. Let the mount point be HDD for example. Name the mount point according to your preference.

sudo mkdir /media/your_username

sudo mkdir /media/your_username/HDD

2. Find the UUID and file system type of second hard drive.

Enter the following command in a terminal and find the name(Linux gives its own name like sda, sdb, etc) for the second hard drive.

sudo lsblk

Now find the UUID of the second hard drive by entering the next command.

sudo blkid

Check for the UUID (not PARTUUID) and file system of the hard drive by cross-checking with the name of the hard drive found from the previous command. Copy the UUID and remember the file system type.

3. Edit the fstab file for auto-mounting on every boot.

The fstab file is found in /etc/fstab.

This part can be done easily by going to the file using file manager and edit it using the default editor. But the file can be edited only using root privileges. so open it using root and make the following changes.

The second method of editing is using the terminal. Open a terminal and use any editor such as nano, gedit, or vim depending on your preference.

In the terminal, enter the command

sudo nano /etc/fstab

come down to the last line, and paste the UUID that was copied earlier without double quotes. Now press the tab and enter the mount point which is /media/your_username/Data. Give a tab space and enter the file system of the second hard drive. Next another tab space and set the options to defaults. The last two values in fstab are dump and pass. Enter 0 and 0 respectively. Press ctrl+O and Enter to write into fstab file and ctrl+x to exit the nano editor.

Let’s check whether it’s working or not using the command.

sudo mount -a

Open file manager and check whether the second hard drive is mounted or not. After a successful change to fstab file, the second hard drive will be mounted automatically on every boot.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Veda Swaroop

I am Post Grad. Electrical Engineering graduate. I love Science, Technology, Linux and Computers in general. Machine Learning, Deep Learning Enthusiast.