How to Auto-Mount Drives in Linux

How to Auto-Mount Drives in Linux

In many Linux distributions, non-boot drives are not mounted when you boot into the system. They do mount when you open them, but it is helpful in many cases to already have the drive mounted when you first boot up your machine. For example, if you have a separate steam or media library on a drive some applications my need access to the data before you can manually mount the drives.

This was originally a section on the 5 MUST DO Tasks after Installing Manjaro article, but it needs more of a deep drive as it could apply to any distribution.

There are two ways to do this. The first is through a GUI disk manager on your system or through the terminal. I recommend using the terminal, but it’s always good to double-check on a disk manager such as Disks, KDE Partition Manager, or GParted.

To do this though a program you can open the ‘Disks’ utility and identify the drive. You’re going to want to find the Device, UUID, and the type of file system. For my example, I will be mounting my Backup drive.

Finding the device information though the terminal is very easy and in most cases preferred to using software.

Find the fdisk list command to see all drives and their partitions.

sudo fdisk -l
 

The blkid command allows you to display information about available block devices. This will allow you to view the filesystem type, UUID, labels, and more.

sudo blkid
 

Editing the fstab file

Now that you know your disk UUID we will create the mounting directory. You can make this almost anywhere, but it is common practice to do this in the /media folder. Type the following command replacing “Backup” with the label of your preference.

sudo mkdir /media/Backup
 

Finally, we will edit our fstab file. First we need to open the file in nano with superuser privileges.

sudo nano /etc/fstab
 

Now we will input the information of the disk so it will mount on boot. It is critical to pay close attention to how it is typed. Watch the video above to ensure this is done correctly. Instead of typing a space make sure you hit tab. Start with a note (anything with a # will be ignored by the system) so its easy to tell what drive is what. Example:

# Backup (dev/sdb1)
 

Now the input will look something like this. Be sure to replace the UUID, mount point, and file system type to match your drive. See the image below.

UUID=a213ed98-641f-4f67-9480-d92a8d7e82f7       /media/Backup   ext4    defaults        0       0
 

Now we will CTRL-O and it ENTER to save the file. Reboot your system and it should be mounted!

For more details on the configuration of this, check out this video from Server Gyan. He does a great job explaining exactly what they do. For our purposes defaults 0 0 will work fine.

Learn more about fstab settings here!

After you edit fstab, enter this command that will mount all drives set to auto-mount. If this gives you any errors ensure you’ve entered everything correctly.

sudo mount -a
 

All the drives you have configured to automatically mount in your system!

Edit: Ubuntu Server

When I installed the Ubuntu Server distribution I noticed the formatting is slightly different. Instread of starting with UUID= the format starts with /dev/disk/by-uuid/[uuid here]. Below is an example.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments