Methods of payment Abuse

How to Set Up Automatic Disk Mounting in Linux

19.12.2024, 14:14

Suppose you have a work computer or media server running Linux, and you want to connect an additional SSD or HDD to it. The issue is that in this system, such drives need to be manually mounted every time the computer restarts. This can be inconvenient and adds an extra repetitive task that disrupts your workflow on the PC or server.

The good news is that this problem can be solved by setting up automatic disk mounting. In this guide, we’ll explain how to configure it using the fstab configuration file.

How to Use fstab

The process is much simpler than it might seem at first glance. Even if you haven’t used the terminal extensively before, you can handle this task.
First, connect your disk and run the following command to identify the device name and UUID:

sudo blkid

Locate the line corresponding to your external disk. For example:

/dev/sdb2: UUID="12ab345cd-1234-4166-8539-ff4ff3ff2ff1" TYPE="ntfs"

Open the file /etc/fstab. For example, you can use the nano text editor:

sudo nano /etc/fstab

Add the following line at the end of the file:

UUID=12ab345cd-1234-4166-8539-ff4ff3ff2ff1 /media/hdd auto defaults,nofail,x-systemd.automount 0 2

Replace UUID with the value corresponding to your disk, and customize the mount point (/media/hdd) to your preference.

Reload systemd daemons to apply the changes:

sudo systemctl daemon-reload

Reboot your system, and the disk should automatically mount to the specified location.

Now your disk will automatically mount to the correct directory.

You can also use this method if you’re working in a dual-boot system and want to automatically mount Windows partitions.

Important: Always Use UUID

When configuring fstab, it’s always better to use the UUID rather than identifiers like /dev/sdX because the UUID remains constant between reboots.