Methods of payment Abuse

How to Set Up Automatic USB Drive Mounting at Linux Startup

27.03.2025, 20:00

If you use a USB drive in Linux every day, you're probably familiar with this routine: after turning on your computer, you open your file manager, find the connected drive, click on it — and only then does it become available for use. Sure, it's not difficult. But doing this over and over again, day after day — especially if you're using the drive as a workspace or for storing projects — can start to feel like it takes too much time and attention.

The good news: Linux allows you to easily set up automatic mounting of a USB drive every time the system boots. This means that as soon as you power on your computer, the drive will automatically be "attached" to the desired folder, and you won't have to mount it manually each time.

In this detailed guide, I’ll show you how to set everything up. It works for almost any distribution — Ubuntu, Debian, Mint, Fedora, Arch, and others.

Step 1: Identify the device name

First, you need to find out how your system identifies the USB drive. The naming may vary depending on how many and what types of drives are in your system.

Plug the USB stick into your computer and run:

lsblk

This command displays a list of all storage devices connected to your system. You’ll see a table with columns such as device name (e.g., sda, sdb1, nvme0n1p1), size, type (disk, part), and mount point (if any).

Example output:
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   100G  0 disk
├─sda1   8:1    0    96G  0 part /
├─sda2   8:2    0     1G  0 part [SWAP]
sdb      8:16   1    16G  0 disk
└─sdb1   8:17   1    16G  0 part

In this example, sda is the main hard drive, and sdb is your USB stick. The partition on it is labeled sdb1.
Take note of the partition name (sdb1 in this case) — you'll need it later.

Step 2: Create a mount point

To tell the system where to “attach” the USB stick's contents, you need to create a special folder — a mount point.
You can create it anywhere, but the standard location is under /mnt.

Open the terminal and run:

sudo mkdir /mnt/usbdrive

Instead of usbdrive, you can choose any name you like, such as flash, mydisk, or projectdrive — whatever makes sense to you.
Now you have a place to mount the USB drive's contents.

Step 3: Get the USB drive's UUID

Device names can change — today your flash drive may be sdb1, tomorrow it might be sdc1. This depends on the order devices are connected. To avoid confusion, Linux lets you use a UUID — a unique identifier for a partition that doesn't change over time.

Run the command:

sudo blkid

This will list all partitions along with their UUIDs and filesystem types.

Example output:

/dev/sdb1: UUID="679C-87F2" TYPE="vfat" PARTUUID="0006a456-01"

Copy the UUID — the value inside the quotes after UUID=. In our case, it’s 679C-87F2. We’ll need to enter this into the configuration file.

Step 4: Set up auto-mounting via /etc/fstab

The /etc/fstab file is a system configuration file that defines which devices to mount, where, and with what options. We’ll add a line to tell the system: “Hey, mount this USB drive automatically to /mnt/usbdrive.”

Open the file with administrative rights:

sudo nano /etc/fstab

At the very bottom, add the following line:

UUID=679C-87F2  /mnt/usbdrive  vfat  defaults  0  2

Notes:
→ Replace 679C-87F2 with your actual UUID.


→ /mnt/usbdrive is the path to the mount point you created.


→ vfat is the filesystem type. If your flash drive is formatted as ext4, ntfs, or another type — specify the correct one.


Common filesystem types:
→ FAT32: vfat


→ NTFS: ntfs


→ EXT4: ext4


Explanation of the other parameters:
→ defaults — standard mount options (suitable in most cases).


→ 0 — disables backup of this partition using the old dump utility.


→ 2 — filesystem check order on boot:


— 0 — do not check;


— 1 — check the root filesystem;


— 2 — check all others (our case).


To save changes in nano, press Ctrl + X, then Y, then Enter.

Step 5: Test if it works

Reboot your computer:

sudo reboot

After booting, open the terminal and type:

df -h

You should see your USB stick listed among the mounted filesystems, with the mount path you specified (/mnt/usbdrive).

What if it didn’t work?

If the drive didn’t mount automatically, there might be a typo in your fstab entry. Check the logs:

sudo dmesg | grep mount

You can also manually mount the drive temporarily to test things:

sudo mount /mnt/usbdrive

If you get an error, check the following:
→ Is the UUID correct?


→ Is the correct filesystem type specified (vfat, ext4, ntfs, etc.)?


→ Does the mount path /mnt/usbdrive actually exist?

Conclusion

Now you know how to set up automatic mounting of a USB drive in Linux. This simple configuration can greatly streamline your daily workflow — especially if you store important documents, projects, or backups on the drive.

Just remember: any changes to system configuration files can affect overall system behavior. Always back up important data and be careful when editing /etc/fstab.