Objective

Setting up automatic USB drive mounting on a Linux server using systemd mount and automount units


Environment

  • OS: Ubuntu
  • Tools: system, USB drive

Step 1 - Find Partition UUID

Prerequisite: Plugin USB drive

blkid /dev/sdb1

sdb1

Note: UUID and filesystem type

Step 2 - Create the Mount Unit

sudo nano /etc/systemd/system/mnt-usb.mount

mnt-usb.mount

Step 3 - Create Automount Unit

sudo nano /etc/systemd/system/mnt-usb.automount

mnt-usb.automount

Step 4 - Enable and Start

sudo systemctl enable mnt-usb.automount
sudo systemctl start mnt-usb.automount

Step 5 - Verify and test

Check the automount is active:

systemctl status mnt-usb.automount

status

Trigger the mount by accessing the path:

ls -l /mnt/usb

usb_mount

Verify it’s mounted:

lsblk 
mount | grep usb

verify