Tech

How to Permanently Mount a Drive in Linux (and Why You Should)


People who work on computers

Morsa Image / Getty Images

I currently have four internal hard drives System76 Thelio . Desktop. The main drive serves as my operating system, and the other drives are purely for holding different types of files. I have a drive for virtual machine, 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’ve set up those extra drives so that they’re always available automatically. In the Linux-verse, this is called “automounting” and it’s an important task that you want to understand.

Also: Linux and Open Source Skills Still In Demand in the Dark Economy

Auto-counting is a problem because when you have secondary drives attached to the machine, they are not automatically available to you at machine startup. Yes, you can open a file manager on your desktop, navigate to the drive and mount it by clicking on the entry. However, this can be problematic if you forget to do it and you have a backup configured to automatically save files to that drive, or you simply save files to that drive from an application . If the drive is not mounted, the application (or backup) will not be able to access the drive.

And that’s why we always want to configure these drives to count automatically.

Let me show you how it’s done.

How to automatically count drives in Linux

What you need: To make this work, you will need a running instance of Linux, the extra drive is plugged into your machine and the user has sudo privileges. I will prove it with Pop!_OS Linux but the procedure should be the same, no matter which distro you use. I’ll also assume the drive is formatted. I always format my secondary Linux drives using ext4 format. If you are using an NTFS drive (Windows drive) you will need to install the ntfs-3g software using a command like sudo apt-get install ntfs-3g.

In the output of that command you will 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 should 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 remove the extra drive, just run the program lsblk request. If you see two drives, sda and sdb, most likely your secondary drive is sdb. For the purposes of showing this process, we will assume your drive letter is /dev/sdb.

The mount point will be the directory on your main drive. This folder will act as the location that you will access the secondary drive from.

Also: The most important reason you should use Linux at home

This does not copy or move files from one file to another, but instead creates a location for the operating system to “mount” the secondary drive. Let’s create a mount point named /data with the command:

Next, change the ownership of the new folder to your user with the command:

sudo chown -R $USER:$USER /data

The -R option ensures that all subdirectories have the same ownership.

/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 add a 1 at the end (since /dev/sdb1 is the first usable partition). Open the fstab file for editing with the command:

At the bottom of that file, add an entry like this:

/dev/sdb1 /data    ext4    defaults        0       0

Here is an explanation:

  • /dev/sdb1 — extra drive
  • /data — mount point
  • ext4 – type of secondary drive file system. If this is an NTFS volume, replace it with ntfs-3g
  • default — use default options
  • 0 0 — these fields are for render and fsck. Just let both be zero

Save and close the file with Ctrl-X.

Mounting test

All you need to do to test the mount is issue the command:

If you don’t get a response, everything is fine. You can now reboot your machine and the secondary drive will be automatically mounted so you can access files from /data.

Also: How to choose the right Linux desktop distro for you

Congratulations, you have successfully set up your secondary drive automount on Linux.

news7g

News7g: Update the world's latest breaking news online of the day, breaking news, politics, society today, international mainstream news .Updated news 24/7: Entertainment, Sports...at the World everyday world. Hot news, images, video clips that are updated quickly and reliably

Related Articles

Back to top button