Raspberry Pi: Mount USB Drive – Automatically

You can connect the external HDD, SSD or USB flash dives to any of the USB ports on the Raspberry Pi and mount the file system to access the data stored on it.

In this article i will show how to manually or automatically at boot time mount a storage device on the example of a USB flash drive.

I will also show how to mount USB storage devices automatically when they are plugged in, and unmount them when they are removed using usbmount tool.

Cool Tip: Test performance of HDD, SSD, USB Flash Drive, SD card! Read more →

Mount USB Drive on Raspberry Pi

Insert the flash drive into a USB port on your Raspberry Pi and execute the lsblk command to identify the name of the disk partition that points to your storage device and the filesystem type on it:

$ lsblk -fp
└─/dev/sda1      vfat   USD Drive  FC05-DF26
├─/dev/mmcblk0p1 vfat   boot       634...    199.9M    21%     /boot
└─/dev/mmcblk0p2 ext4   rootfs     805...    24.3G     12%     /

In the example above, the USB drive is recognized by the operating system of Raspberry Pi as a block device /dev/sda with a single partition /dev/sda1 in FAT format.

Create a mount point, for example:

$ sudo mkdir /mnt/usb0

Depending on the filesystem type, execute one of these commands to mount the USB drive:

Filesystem Mount Command
$ sudo mount -t vfat /dev/sda1 /mnt/usb0 -o umask=000
$ sudo apt install ntfs-3g
$ sudo mount -t ntfs /dev/sda1 /mnt/usb0 -o umask=000
$ sudo apt install exfat-fuse
$ sudo mount -t exfat /dev/sda1 /mnt/usb0
$ sudo mount -t ext4 /dev/sda1 /mnt/usb0

Once the USB drive is mounted, you can verify this by listing its contents:

$ ls -lt /mnt/usb0

To unmount the USB drive, execute the umount command:

$ sudo umount /mnt/usb0

Cool Tip: Check the real actual size of USB flash drive or SD card! Read More →

Automatically Mount USB Drive on Raspberry Pi

Run the blkid command to find out the UUID of the USB drive:

$ sudo blkid
/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="6341-C9E5" TYPE="vfat" PARTUUID="ea7d04d6-01"
/dev/mmcblk0p2: LABEL="rootfs" UUID="80571af6-21c9-48a0-9df5-cffb60cf79af" TYPE="ext4" PARTUUID="ea7d04d6-02"
/dev/sda1: UUID="FC05-DF26" TYPE="vfat" PARTUUID="2d72d270-01"

Make a backup and open the /etc/fstab file in your favorite text editor:

$ sudo cp /etc/fstab /etc/fstab.back
$ sudo nano /etc/fstab

Depending on the filesystem type, append one of the lines from the table below to /etc/fstab and save the changes:

Filesystem Line To Add To /etc/fstab
UUID=FC05-DF26 /mnt/usb0 vfat defaults,auto,users,rw,nofail,umask=000 0 0
UUID=FC05-DF26 /mnt/usb0 ntfs defaults,auto,users,rw,nofail,umask=000 0 0
UUID=FC05-DF26 /mnt/usb0 exfat defaults,auto,users,rw,nofail 0 0
UUID=FC05-DF26 /mnt/usb0 ext4 defaults,auto,users,rw,nofail 0 0

Don't forget to set the corresponding UUID and replace the mount point with the one you have created (if it is not /mnt/usb0).

Mount options:

Option Description
defaults Use default options: rw, suid, dev, exec, auto, nouser and async
auto Mount when mount -a is given (e.g., at boot time)
users Allow mount/unmount by any user
rw Mount read-write
nofail Do not report errors for this device if it does not exist
umask=000 Anyone can read, write or execute any file or directory
0 0 Don't dump. Don't check filesystem for errors during startup

Once the record is added to /etc/fstab, the USB drive will be automatically mounted on system boot.

Also you can mount and unmout the USB drive at any time without reboot using the following commands:

$ sudo mount /mnt/usb0
$ sudo umount /mnt/usb0

Cool Tip: Shutdown & reboot Raspberry Pi safely! Read more →

Auto-Mount USB Drive on Plugin-Time

Alternatively, you can install the usbmount tool - it automatically mounts USB drives when they are plugged in and unmounts them when they are removed.

The mount points (/media/usb[0-7] by default), supported filesystems (vfat, ext[2-4] and hfsplus by default) and mount options (sync, noexec, nodev, noatime, nodiratime by default) can be configured in /etc/usbmount/usbmount.conf file.

Install usbmount:

$ sudo apt install usbmount

When multiple devices are plugged in, the first available mount point is automatically selected:

$ ls -lt /media/usb0

To troubleshooting any issues with usbmount, use the following command to check logs:

$ journalctl -u systemd-udevd.service -f
Was it useful? Share this post with the world!

6 Replies to “Raspberry Pi: Mount USB Drive – Automatically”

  1. Thanks so much for this — I do have one call out about an odd case I encountered with mounting ext4 SATA’s over USB tonight:
    Do not be tempted to match initial assignments in /etc/fstab that declare PARTUUID=asdfasdfasdf on the new Raspberry Pi OS. If you attempt this, you might find pre-existing file system directories completely missing on the mounted device.

  2. Thanks for this complete and easily followed instruction. Works perfectly with my little rpi 4 file server. It easily handle nfs and cifs at full speed on my gigabit ethernet.
    Linux ubuntu 5.4.0-1045-raspi

  3. Thanks a lot, solve all issues following your instructions.

  4. I need to change some permissions for my NSTF drive but I can’t figure out how it is mounting as there is nothing in the fstab file about it. How can I tell if it is being auto-mounted? And if it is, how can I make that not happen?

  5. Very good guide. Thank you.
    exfat also needs to have umask=000 option in two places. Was able to figure out with this guide in no time but perhaps someone else has an issue.

  6. E: Unable to locate package usbmount

Leave a Reply