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).
- Plug your USB drive into your Ubuntu machine.
- Open your terminal and run:
sudo blkid - Look through the output for your USB drive. It will look something like this:
/dev/sdb1: UUID="1234-ABCD" TYPE="ext4" - 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.
- 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.
- Open the file in a text editor:
sudo nano /etc/fstab - Use your arrow keys to scroll to the very bottom of the file.
- Add a new line using this format:
UUID=[Your UUID] [Mount Point] [File System Type] defaults 0 0 - For example:
UUID=1234-ABCD /mnt/usb_drive ext4 defaults 0 0 - 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!
- 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.