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 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.
I followed your instructions as a new user and you messed up. You should have been using UUID’s to mount the drives with, because they never change. I followed your stupid instructions for 4 external drives so every time I boot up they’re all switched around with the wrong folder names. I find it ridiculous that such an amateur mistake would be published on the web for other people to use. I’m guessing you only have one secondary hard drive so you’ve never had to experience the repercussions of your mistake.
Thanks
Ayhan
I’ve tried doing this, but, although the external drive is connected, it does not show in the ‘Other locations’ panel – the drive that does show, called OS, contains information about the system, users etc.
It is a new hard drive, I am not sure how to begin to use it, any tips much apprechated.
Hey Reverend,
I just followed your instructions to permanently mount my external drive and they worked as you described. I mounted 3 partitions from my external drive using your instructions. I assume they will be where I put them when I reboot.
I have been using online instructions for the last half year and have seldom used a tutorial that actually works. I am grateful. I am going to look around at your other tutorials to see if you have solved some of the other mysteries that plague Linux.
For educational purposes, would you like to explain the instructions “default,noatime 0 2”? It would help demystify your instructions and increase the learning.
I haven’t tried yet, but could these instructions be used to permanently mount (physically internally mounted) usb drives?
Finally, I am also impressed by the failure of the community to explain hard drives (as you mentioned), and permissions in particular. In trying to build my current system, I have had to copy files across multiple hard drives, and frequently get the “you don’t have permission” message. “But it’s my computer!” I shout at my machine.
So I look up “permissions”, and I find tutorials that tell me how to change the permissions on files using the terminal. No one tries to explain what it means when a copy attempt returns “you do not have permission to complete this operation”. This is one of the biggest hassles I have with Linux and it makes me wonder why I bother to switch away from Windows. A person can’t just install a Linux system and use it. They have to also study and learn to use complex command instructions. I am waiting for any Linux wiz to step forward and explain how I can make my system actually belong to me. (I don’t expect to move system files, only my own, but even these…) My dream is a gui that allows me to alter permissions without learning command language. Or how about a right click copy command that asks me for my password? Would you be interested in explaining why copy operations get blocked and how to unblock them, for files and for directories? I really just want to use linux without any need to use the terminal. I have other ambitions for my time. Any help will be appreciated!
Oh my god thank you so much! I had been trying to permanently mount my internal HDD with no luck after days of googling. For reference, I am running Ubuntu Server 20.04 and this worked on a 2TB Western Digital HDD. Good luck everyone!
Awesome guys for this very helpful tutorial. Bookmarked and subscribed to your website. Cheers
Thank you!