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 if 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 want 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.
Select mount on startup and enter the mount point(or)mount directory, and file system type of the 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 its 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 the second hard drive.
Enter the following command in a terminal and find the name(Linux gives its name like sda, sdb, etc.) for the second hard drive.
Now find the UUID of the second hard drive by entering the next command.
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 editing it using the default editor. However, 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 the 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 the file manager and check whether the second hard drive is mounted or not. After a successful change to the fstab file, the second hard drive will be mounted automatically on every boot.