How to permanently mount a drive in Linux (and why you should)
‘ZDNET Recommends’: What exactly does it mean?
ZDNET’s recommendations are based on many hours of testing, research, and comparison shopping. We gather data from the best available sources, including vendor and retailer listings as well as other relevant and independent reviews sites. And we pore over customer reviews to find out what matters to real people who already own and use the products and services we’re assessing.
When you click through from our site to a retailer and buy a product or service, we may earn affiliate commissions. This helps support our work, but does not affect what we cover or how, and it does not affect the price you pay. Neither ZDNET nor the author are compensated for these independent reviews. Indeed, we follow strict guidelines that ensure our editorial content is never influenced by advertisers.
ZDNET’s editorial team writes on behalf of you, our reader. Our goal is to deliver the most accurate information and the most knowledgeable advice possible in order to help you make smarter buying decisions on tech gear and a wide array of products and services. Our editors thoroughly review and fact-check every article to ensure that our content meets the highest standards. If we have made an error or published misleading information, we will correct or clarify the article. If you see inaccuracies in our content, please report the mistake via this form.
How to permanently mount a drive in Linux (and why you should)
Morsa Images/Getty Images
I currently have four hard drives inside of my System76 Thelio desktop. The primary drive serves as my operating system and the others are strictly for housing different types of files. I have one drive for virtual machines, one for music, and one for miscellaneous files. By laying out my system this way, even if the operating system fails, my data is still accessible.
I have those secondary drives set up such that they are automatically available at all times. In the Linux-verse, this is called “automounting” and it’s an important task you’ll want to understand.
Also: Open source and Linux skills are still in demand in a dark economy
Automounting is a thing because when you have secondary drives attached to a machine, they aren’t automatically available to you upon boot of the machine. Yes, you can open your desktop file manager, navigate to the drive, and mount it by clicking the entry. However, this can be problematic if you forget to do that and you either have a backup configured to automatically save files to that drive or you simply go to save a file to that drive from an application. If the drive isn’t mounted, the app (or backup) won’t be able to access the drive.
And that’s why we always want to configure these drives for automounting.
Let me show you how it’s done.
How to automount a drive in Linux
What you’ll need: To make this work, you’ll need a running instance of Linux, a secondary drive plugged into your machine, and a user with sudo privileges. I’ll demonstrate with Pop!_OS Linux but the process should be the same, regardless of which distribution you use. I will also assume the drive has been formatted. I always format my secondary Linux drives with the ext4 format. If you’re using an NTFS drive (a Windows drive), you’ll need to install the ntfs-3g software with a command like sudo apt-get install ntfs-3g.
1. Locate the name of your drive
The first thing to be done is to locate the name of the drive to be mounted. Here’s a simple way to find the name.
Also: Can’t remember the Linux command you ran earlier? Let history repeat itself
Without the drive plugged in, issue the following command:
lsblk
In the output of that command, you should see entries like this:
sda 8:0 0 931.5G 0 disk ââsda1 8:1 0 931.5G 0 part
Plug the drive in and run the command again and you’ll see a new entry like:
sdb 8:16 0 931.5G 0 disk ââsdb1 8:17 0 931.5G 0 part
If you can’t easily unplug the secondary disk, just run the lsblk command. If you see two drives, sda and sdb, chances are very good your secondary drive is sdb. For the purpose of showing this process, we’ll assume the name of your drive is /dev/sdb.
2. Create a mount point
The mount point will be the directory on your primary drive that will serve as a location you will access the secondary drive from.
Also: The most important reason you should be using Linux at home
This doesn’t copy or move the files from one to the other but, rather, creates a place for the operating system to “mount” the secondary drive. Let’s create a mount point called /data with the command:
sudo mkdir /data
Next, change the ownership of the new directory to your user with the command:
sudo chown -R $USER:$USER /data
The -R option makes sure all child folders have the same ownership.
3. Create an entry in /etc/fstab
The /etc/fstab is the file responsible for mapping the secondary drive to the mount point.
Also: 8 things you can do with Linux that you can’t do with MacOS or Windows
Assuming the name of your secondary drive is /dev/sdb, we’ll tack on a 1 to the end (because /dev/sdb1 is the first usable partition). Open the fstab file for editing with the command:
sudo nano /etc/fstab
At the bottom of that file, add an entry like this:
/dev/sdb1 /data ext4 defaults 0 0
Here’s an explanation:
- /dev/sdb1 — the secondary drive
- /data — the mount point
- ext4 — the secondary drive file system type. If this is an NTFS drive, substitute with ntfs-3g
- defaults — uses the default options
- 0 0 — these fields are for dump and fsck. Just leave them both as zeros
Save and close the file with Ctrl-X.
Testing the mount
All you need to do to test the mount is issue the command:
mount -a
If you receive no feedback, everything is good. You can now reboot your machine and the secondary drive will be automatically mounted so you can access the files from /data.
Also: How to choose the right Linux desktop distribution for you
Congratulations, you’ve just successfully set up a secondary drive automount on Linux.