How To Mount External Hard Drives In Linux

Have you ever wanted to make it so that external hard drives connected to your Linux PC show up in dedicated folders? How about just understanding how to access the hard drives on Linux in general? Each hard drive, USB disk has a label on Linux. Before any hard drive is accessible, we must find out the device label. This is easy, but very important. This is because external hard drives in Linux (unlike Windows and Mac) do not automatically start up so that users can access files. To find out the label of an external hard drive, open up a terminal, and use the following command.

lsblk

The lsblk command (list block devices) shows all attached drives. When the list block command finishes, all of the drives connected will appear in this list. If any hard drives are in use, it’ll be easy to see. This is because the command always shows what directories hard drive partitions are using.

For example: Linux almost always is installed on /dev/sda and is mounted to / (and sometimes /boot and /home too). The second drive on this list in the screenshot is /dev/sdb, and is not mounted to anything.

It is important to note that the entire hard drive is labeled as /dev/sdb. This label always belongs to the second drive. After that, each connected hard drive will be another letter in the alphabet. Also keep in mind that in the screenshot, there are /dev/sdb1, /dev/sdb2, /dev/sdb3 and /dev/sdb4. These let the user know that there are 4 partitions on the SDB hard drive. The sizes of each partition is also in this list.

In this tutorial, we’ll be mounting the /dev/sdb4 partition. Yours may differ.

Using The File Manager To Mount

There are a few ways to mount external hard drives in Linux. By far the easiest, and quickest way to gain access to an attached hard drive that is not in use by Linux, is to use the Linux file manager.

First, open the file manager installed on your Linux PC. Not sure what a file manager is? It’s the program on Linux that you use to access files and folders. Click “other locations”, if your Linux file manager has an option to do this. If all hard drives show up in the side panel, click on the hard drive from here.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

After clicking on the hard drive to load it up on the system, the user will be asked to enter a password. Enter the password attached to your username. Once entered, the hard drive is mounted to the system. Using the file manager, click on the drive to view the files. Unmount by clicking the eject icon, or by right-clicking it and then clicking “unmount”.

Note: there are many file managers for Linux, and they all have small differences. However, though they look different, the basic concept in this tutorial is the same.

Temporary Mount

It is possible to mount any hard drive temporarily, to any folder. To start off, create the mount folder in the home directory. If you decide to create a folder with a different name than in the example, be sure to remember what the folder is for, as it will be empty when the hard drive is not mounted.

mkdir -p ~/secondary-hard-drive

With the folder created, mount the hard drive. In this example, /dev/sdb4 is used. Yours may differ. Be sure to change the command to fit your needs.

sudo mount /dev/sdb4 ~/secondary-hard-drive/

The hard drive partition (/dev/sdb4) is set to the correct folder. When Linux reboots, it will disconnect.

Permanent Mount

Permanently mounting a secondary hard drive requires modifying the file system tab. The file system tab lets Linux know where every hard drive partition needs to go. To make secondary hard drives permanently mountable at boot, do the following:

First, create the folder where the hard drive will load to. This folder will be this hard drive’s home, so DO NOT delete it. If you do, Linux will fail to boot and everything will break.

mkdir -p ~/secondary-hard-drive

The folder secondary-hard-drive is present in /home/username. Now tell Linux to mount it permanently.

Note: adding the hard drive to the filesystem tab WILL NOT WORK if you do not specify the correct filesystem type. Learn the correct filesystem type by first figuring out the drive label with lsblk then using df -T to figure out the filesystem type. Each drive in df -T will have the drive label next to it.

Editing Fstab

First, gain a root shell.

sudo -s

Then, add a comment. This is important as there are many existing things in the filesystem tab, and this will help differentiate the entry from the others.

echo "# Secondary Hard Drive" >> /etc/fstab

Lastly, add the hard drive to the mount list. Please take note of this command, and edit the part that says username, so that it has your username instead. Also edit the part in the command with NTFS if the partition uses a different file system, and change /dev/sdb4 to the partition you’d like to mount.

echo "/dev/sdb4 /home/username/secondary-hard-drive ntfs swap defaults,noatime 0 2" >> /etc/fstab

Repeat this for as many hard drives as desired.

Conclusion

Accessing hard drives on Linux can be pretty confusing, especially if you’re a new user. This is because no Linux distribution really takes the time to explain how hard drives work. Luckily, adding additional hard drives is an easy process, once you follow this guide.

قالب وردپرس

About Kelli Smith

Kelli Smith
Kelli runs customer support and creates content for Skillcrush, a digital skills training and education platform with friendly instructors, an active student community, and laser focus on helping you achieve your career goals with technology. She has an MBA and successfully ran an international company and her own freelancing business before pursuing her passion for tech by taking advanced web development classes. Kelli loves listening to tech podcasts at 2x speed, looking for cute Corgi photos online and teaching and performing country line dancing—as a true Texan living in Finland would do. Say hi on Twitter.

Leave a Reply

Your email address will not be published. Required fields are marked *