How to Automatically Mount a USB Drive on Boot in Ubuntu Linux

When you plug a USB hard drive into an Ubuntu desktop, the operating system usually mounts it automatically. However, if you are running an Ubuntu server without a graphical interface, or if you want the drive to be permanently available immediately after a reboot, you must configure the system to mount it automatically using the fstab file.

Step 1: Find the Drive UUID

You should never use standard device names (like /dev/sdb1) for automatic mounting because these can change if you plug the drive into a different USB port. Instead, you must use the drive’s unique Universally Unique Identifier (UUID).

  1. Plug your USB drive into your Ubuntu machine.
  2. Open your terminal and run: sudo blkid
  3. Look through the output for your USB drive. It will look something like this: /dev/sdb1: UUID="1234-ABCD" TYPE="ext4"
  4. Copy the exact UUID (without the quotes). Also, take note of the file system TYPE (e.g., ext4, vfat, or ntfs).

Step 2: Create a Mount Point

You need an empty folder where you can access the drive’s files.

  1. Run: sudo mkdir /mnt/usb_drive (you can name the folder anything you like).

Step 3: Edit the fstab File

The fstab (File System Table) file tells Ubuntu which drives to mount when the system turns on.

  1. Open the file in a text editor: sudo nano /etc/fstab
  2. Use your arrow keys to scroll to the very bottom of the file.
  3. Add a new line using this format: UUID=[Your UUID] [Mount Point] [File System Type] defaults 0 0
  4. For example: UUID=1234-ABCD /mnt/usb_drive ext4 defaults 0 0
  5. Press Ctrl + O then Enter to save, and Ctrl + X to exit Nano.

Step 4: Test the Configuration

Warning: If you made a typo in the fstab file, your server might fail to boot. Always test it before restarting!

  1. Run: sudo mount -a

If the command returns no errors, your configuration is perfect. Your USB drive will now mount automatically every time you restart your Ubuntu machine.

Leave a Reply

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

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.

Receive our best articles and tips delivered straight to your inbox.