If you plug an external USB hard drive or flash drive into an Ubuntu desktop running a graphical environment (like GNOME), the system usually detects it and mounts it automatically, placing an icon on your desktop or sidebar. However, if you are running an Ubuntu server, using a headless setup, or rebooting your machine, that USB drive will not mount automatically on startup. The operating system sees the hardware, but it does not make the file system accessible until you manually command it to do so.
If you are using an external USB drive to host a Plex media server library, store automated backups, or act as a network-attached storage (NAS) share, requiring a manual mount after every system reboot is unacceptable. You need the drive to mount autonomously the moment the system boots.
This guide explains how to configure the /etc/fstab file in Ubuntu to automatically mount a USB drive on startup safely and reliably.
Step 1: Identify the USB Drive UUID
You might be tempted to mount the drive using its traditional device name, such as /dev/sdb1. This is a critical mistake. If you unplug the drive and plug it into a different USB port, or if you attach a second USB device before booting, the system might reassign that device name to /dev/sdc1. If the fstab file points to the wrong device name, your system may fail to boot entirely.
Instead, you must use the Universally Unique Identifier (UUID). This is a permanent serial number assigned to the file system on the drive, which never changes regardless of which port you use.
Open your terminal and run the blkid command with root privileges:
sudo blkid
Locate your USB drive in the output list. It will look something like this:
/dev/sdb1: UUID="1a2b3c4d-5e6f-7g8h-9i0j-1234567890ab" TYPE="ext4" PARTUUID="12345678-01"
Copy the long string of letters and numbers inside the quotation marks next to UUID=. Do not copy the quotation marks themselves.
Step 2: Create a Mount Point
Ubuntu needs an empty directory to act as the gateway (mount point) to the USB drive’s contents. A common practice is to create a folder inside the /mnt or /media directories.
To create a new directory named usbdrive inside the /mnt folder, run:
sudo mkdir -p /mnt/usbdrive
Ensure that your user account has the correct permissions to read and write to this directory. If necessary, change the ownership to your specific username (replace yourusername):
sudo chown -R yourusername:yourusername /mnt/usbdrive
Step 3: Edit the fstab File
The /etc/fstab (file systems table) file is the configuration document that tells Ubuntu exactly what drives to mount during the boot process.
Warning: A syntax error in this file can prevent your server from booting. Proceed carefully.
Open the file in a text editor like Nano:
sudo nano /etc/fstab
Use your arrow keys to scroll to the very bottom of the file. Add a new line at the bottom containing five specific pieces of information, separated by spaces or tabs:
- The UUID of the drive.
- The mount point directory.
- The file system type (e.g., ext4, ntfs, exfat). Check the
blkidoutput if you are unsure. - The mount options. Using
defaults,nofailis highly recommended. Thenofailoption ensures that if the USB drive is unplugged or fails to spin up, Ubuntu will ignore the error and continue booting the system normally, rather than halting in an emergency recovery state. - The dump and pass numbers (usually
0 0for external USB drives).
The final line you add should look exactly like this (substituting your actual UUID and file system type):
UUID=1a2b3c4d-5e6f-7g8h-9i0j-1234567890ab /mnt/usbdrive ext4 defaults,nofail 0 0
Save the file and exit Nano (press Ctrl+O, Enter, then Ctrl+X).
Step 4: Test the Configuration
Before you reboot your machine, you must test the configuration to ensure there are no syntax errors.
First, unmount the drive if it is currently mounted elsewhere:
sudo umount /dev/sdb1
Next, instruct Ubuntu to mount all file systems listed in the fstab file:
sudo mount -a
If the command returns to the prompt silently without any error messages, your syntax is correct. You can verify the drive is mounted by running ls /mnt/usbdrive to view the files.
From now on, whenever you reboot your Ubuntu machine, the USB drive will be automatically and silently mounted to /mnt/usbdrive, ready for immediate use by your applications.