Initialize & Auto-Mount an External USB Disk on Ubuntu Server 24.04

— THIS GUIDE ERASES THE ENTIRE TARGET DISK —

Data-destructive warning: The steps below wipe the whole disk (wipefs -a, new GPT). Double-check the device path before running. There is no undo.


Why server doesn’t auto-mount USB

Ubuntu Server has no desktop automounter. Using /etc/fstab with:

  • x-systemd.automount → mounts on first access (no boot delay)
  • nofail → boot continues even if the disk is absent
  • x-systemd.idle-timeout=60 (optional) → auto-unmount after 60s idle
    keeps the machine reliable even if you unplug the disk.

  1. Identify the correct USB disk
lsblk -dpno NAME,TRAN,TYPE,SIZE,MODEL \
| awk '$2=="usb" && $3=="disk"{print $1, $4, substr($0, index($0,$5))}'
/dev/sda 931.5G PSSD T7
lsblk -S -o NAME,TRAN,TYPE,SIZE,MODEL,SERIAL | awk '$2=="usb" && $3=="disk"'
sda  usb  disk 931.5G PSSD T7 A682101Y0SNLM7S
  • Device: /dev/sda
  • Model: PSSD T7
  • Serial: A682101Y0SNLM7S

  1. Remove old signatures (destructive)
sudo wipefs -a /dev/sda

  1. Create a clean GPT and a single partition (full disk)

Some USB bridges misreport “optimal I/O size” and make parted warn about alignment. Use -a minimal with 1 MiB start; alignment is correct.

sudo parted -s /dev/sda mklabel gpt
sudo parted -s -a minimal /dev/sda mkpart primary ext4 1MiB 100%
sudo parted -s /dev/sda name 1 data
sudo parted -s /dev/sda align-check minimal 1

The ext4 in mkpart is only a hint. The real filesystem is created next.


  1. Format the filesystem (EXT4)
sudo mkfs.ext4 -L DATA /dev/sda1

  1. Mount now & configure auto-mount

Mount by label:

sudo mkdir -p /mnt/data
sudo mount /dev/disk/by-label/DATA /mnt/data

Add one line to /etc/fstab (UUID method):

UUID=$(sudo blkid -s UUID -o value /dev/sda1)
echo "UUID=${UUID} /mnt/data ext4 defaults,noatime,nofail,x-systemd.automount,x-systemd.idle-timeout=60 0 2" \
| sudo tee -a /etc/fstab

Apply & test:

sudo systemctl daemon-reload
sudo mount -a
df -h | grep /mnt/data

Why these options

  • nofail → no boot hang if the disk is unplugged
  • x-systemd.automount → lazy mount on first access
  • x-systemd.idle-timeout=60 → optional idle unmount
  • noatime → fewer writes

Ownership & permissions

sudo chown -R $USER:$USER /mnt/data

Safe eject / power-off before unplug

sync
sudo umount /mnt/data
sudo udisksctl power-off -b /dev/sda

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top