How to Mount a USB Flash Device in Linux and Your Raspberry Pi

Christian Cawley 30-08-2016

Removable USB storage makes it simple to transfer data from one PC to another, but if the computer you’re using doesn’t automatically mount the device when you plug it in, you’re likely to find that moving data to and from the USB drive is difficult, if not impossible, without the right commands.


Alternatively, you might have a similar problem with an SD card.

Let’s take a look at problems — and their solutions — surrounding USB devices and SD cards with popular distros (we’re using Ubuntu) and less widely-used distros, such as the Raspberry Pi’s Raspbian Jessie operating system 5 Ways New Raspbian Jessie Makes Raspberry Pi Even Easier to Use Following the release of Debian Jessie in July, the Raspberry Pi community has been blessed with a new release of the Raspbian variant, based on the "parent" distro. Read More .

Using USB Flash Devices with Mature Linux Distros

What we want to happen when a USB device is connected can be seen in most long-running, mature Linux distributions, those that are designed with an enhanced, user-focused experience in mind. Typically, these are the distributions that are presented as alternatives to Windows and OS X, such as Ubuntu.

Here, connecting a USB flash device simply means plugging it in.



Once you’ve done this, a window will appear, listing the contents of the drive, which you can then browse as you need.


Meanwhile, safe removal of the drive is just as simple, and is as easy as clicking the eject button — for safe removal, of course — and physically disconnecting the device.

What About SD Cards?

The same is true with SD cards (for best results, make sure it is a device from a reliable manufacturer 5 Mistakes to Avoid When Buying a MicroSD Card Buying MicroSD cards may seem simple, but here are a few critical mistakes to avoid if you don't want to regret your purchase. Read More ), although you may find that if the card uses the exFAT file system, it won’t be mounted automatically. You might even see an error message. If this is the case, it’s probably because you don’t have the exfat-utils software installed. This enables your Linux system to read the contents of an exFAT storage device.



To install on Ubuntu 14.04 or later, use

sudo apt-get install exfat-fuse exfat-utils

For 13.04 and earlier, installation requires a ppa:

sudo apt-add-repository ppa:relan/exfat
sudo apt-get update
sudo apt-get install fuse-exfat

With exFAT support installed, when you insert your SD card (perhaps a device used with your digital camera), you’ll be prompted as to how you want to proceed. For convenience, I like to have the device open into the file manager.



Similarly, if you’re having difficulty mounting a device using the NTFS file table (some prefer this file system How To Reformat Your FAT32 Drive To NTFS - And The Advantages Of Doing It You may not know it, but choosing the right filesystem for your drives is actually pretty important. Although the main idea of all filesystems is the same, there are many advantages and disadvantages over each... Read More ), use

sudo apt-get install ntfs-3g

…then reinsert to see the contents.

Mounting Drives on the Raspberry Pi

If your chosen Linux distro doesn’t support automatically mounting USB drives, you’ll need to set this up manually.


For instance, if you inserted a USB drive into a Raspberry Pi running Raspbian, you’ll find that it doesn’t automatically mount. No additional software is required to make this happen, however; you simply need to add a few commands!

Begin by inserting the device. On recent devices, you should have enough spare slots, but if not, or if you’re using an older Pi with just two USB slots (or even a Pi Zero with just the one Getting Started with Raspberry Pi Zero Whether you bought a magazine with one glued to the front, or found a kit online, the chances are you're now the proud owner of a $5 computer: the Raspberry Pi Zero. Read More ), then a powered USB hub is recommended.


Should you wish to set up the device to automatically mount when inserted, check the unique reference number for the device with the command:

ls -l /dev/disk/by-uuid/

Make a note of the 8-digit ID code which is listed for /sda. You’ll need to do this for all USB storage devices you plan to connect, as each has its own UUID.

The next step is to create a mount point, which you can do by creating a folder:

sudo mkdir /media/usb

…then putting the pi user in control (if you’ve changed the default username Securing Your Raspberry Pi: From Passwords to Firewalls Anyone can use Google to find the default username and password of your Raspberry Pi. Don’t give intruders that chance! Read More , use this instead):

sudo chown -R pi:pi /media/usb

Manually mounting the drive is another single command:

sudo mount /dev/sda1 /media/usb -o uid=pi,gid=pi

At this stage, you can read, write, delete and move files in /media/usb, which you’ll find in the file manager. Note that the above command can also be entered as:

sudo mount /dev/sda1 /media/usb

…but this would result in you only being able to write to it using sudo, which isn’t ideal.

If your Pi is running when you wish to remove the drive, use the umount command:

umount /media/usb

Note that the correct command us umount, not “unmount”. When the Pi is shut down, you can disconnect drives as and when. The same is true for any device.

Auto-mount Drives on the Raspberry Pi

Manually mounting is useful enough, but to avoid going through most of the above, you can set the drive to mount automatically when inserted. Remember the UUID you made a note of? This comes in handy here.

Begin by opening the fstab file in a text editor, like nano.

sudo nano /etc/fstab

At the end of the file, add this line:

UUID=[YOUR_UUID] /media/usb vfat auto,nofail,noatime,users,rw,uid=pi,gid=pi 0 0

To make this work, you’ll need to restart the device.

sudo reboot

As long as you’ve inserted your UUID where stated, once saved (Ctrl + X to save and exit) the drive will be automatically mounted when inserted. Remember, for other drives, you’ll need to add additional lines with each device’s UUID.

To safely remove a drive that has been added to the fstab file, use

sudo umount /media/usb

Mounting and Removing USB Devices: Not Too Tricky

When I first came across problems mounting drives in Raspbian, I was surprised that it was actually an issue; Raspbian Jessie is such a useful operating system that I expected that it would have an automated software solution already in place.

However, the solution is straightforward enough, and of course the Debian-based OS is flexible enough to allow automation based on the user’s own requirements.

Have you had problems mounting USB flash or SD cards in Ubuntu or Raspbian? Tell us about it.

Related topics: Storage, USB Drive.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

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

  1. Howard Blair
    September 2, 2016 at 9:54 pm

    "...if the card uses the , it won’t be mounted automatically. You might even see an error message."
    Yep, definitely an error message. It's right next to the isolated comma above.