Introduction: Mounting a USB Thumb Drive With the Raspberry Pi

Picture of Mounting a USB Thumb Drive With the Raspberry Pi

This is another one of my "meat-and-potatoes" Raspberry Pi Instructables.

What this Instructable will show you how to do is to configure your Raspberry Pi to recognize and automatically mount a USB thumb drive. This is especially useful for exchanging files, running backups and using your Pi as a media device.

Before doing this Instructable, please make sure you have your Raspberry Pi up and running, which you can do with The Ultimate Raspberry Pi Configuration Guide Instructable.

I'm using the Mac OS for this guide, but you can extend the principles to other operating systems.

Step 1: Format the Thumb Drive

Picture of Format the Thumb Drive

Using Disk Utility, format the thumb drive as an MS-DOS (FAT) volume, which is a format that the Pi can easily recognize.

Step 2: Run Package Updates

I'm using ssh to access to Raspberry Pi. My IP address for the SD card for this is Your IP address may be different — just change the address accordingly.

Open the Terminal window and on the command line, type:
ssh pi@

If you are running directly hooked into the monitor, you can skip this step.

Run the latest package update and upgrades, just to make sure everything is current — you will have to have wifi access for this step.

First the update:
sudo apt-get update
Then the upgrade:
sudo apt-get upgrade
You'll see a spool of package updates, which will take several minutes.

Step 3: Set Up a "mounting Point" for the USB Drive

Picture of Set Up a "mounting Point" for the USB Drive
Now, unplug your USB power cable. Put the formatted USB drive into the Raspberry Pi. And turn the Pi back on.

I'm not sure if this matters, but I always leave the wi-fi dongle in the lower USB port and use the upper one for the external USB drive/keyboard/other things.

Wait a few seconds and then ssh back into the Pi.
ssh pi@
What we then type in;
mkdir usbdrv
What we are going to set up is a mount point — a way to always map this directory to the USB drive.

now, type in:
sudo blkid
check out output — we are looking for the USB drive device info, which is easy to identify because we called it GITPI when we initialized it.

Mine reads:
/dev/sda1: LABEL="GITPI" UUID="6D34-1514" TYPE="vfat"

This should be the similar on yours: /dev/sda1 is the USB thumb drive device.

Now, we are going to edit what is called the file systems table to make the USB drive map into the usbdrv directory

Type in:
sudo nano /etc/fstab
Here is the tricky part. We are going to modify the fstab file so that this device maps to the usbdrv directory.

add the line to the end of the file (you can copy and paste this line)

/dev/sda1        /home/pi/usbdrv       vfat    uid=pi,gid=pi,umask=0022,sync,auto,nosuid,rw,nouser 0   0

important: this is 1 line, not broken up over two lines  (the Instructable is doing weird things to the formatting).

What this does is to map the /dev/sda1 device — any thumb USB drive to the usbdrv directory. The flags are ones that I cribbed from the Thomas Loughlin guide. Admittedly, I'm not sure exactly what they do, except for allow the drive to be a read-write drive and not tied to a specific user.

Cntl-X, Y, Return to save.

Then restart:
sudo reboot
If you want to learn more about drive-mapping and mounting (and I'm sure you do) this eLinux Guide has a lot more information.

Step 4: Test It

Picture of Test It
After you've rebooted and have gotten back into the pi via ssh, navigate to your usbdrv directory:
cd usbdrv
create a simple text file
sudo nano test.txt
in the editor type in whatever you want — any sort of text message.

Cntl-X, Y will save it.

Turn off the power to your Pi and pull out the USB drive.

Check out the USB drive on your computer and it you should see your text file there.

Step 5: Extras: Unmounting and Mounting From the Command Line

I usually just yank the drive out and then reboot the Pi, as needed, but you may find yourself in situations where you don't want to do this.

If you want to "eject" your drive, like you would on the Mac, you need to issue a command to unmount the drive.

It looks like this:
sudo umount usbdrv
if you want to remount it, i.e. put another drive in, since there is no mounting point setup, you have to use the device info, with the command
sudo mount /dev/sda1

Step 6: Done!

It's that easy. This is a super-short Instructable.

I hope this was helpful!
Scott Kildall

For more on Raspberry Pi code and other projects, you can find me here:
@kildall or


greenpi (author)2015-12-17

Very nice instructable. So simple. Just what i was after. But if you do not put a usb stick in at boot the raspi gets crazy. Also a "Welcome to emergency mode". You get logged in as root and cannot login as pi.

How can this be solved?

britjohnson0100 (author)greenpi2017-06-20

i think if you add the 'nofail' tag to the line in the fstab file, it will boot up just fine without a usb in, like this: /dev/sda1 /home/pi/usbdrv vfat uid=pi,gid=pi,umask=0022,sync,auto,nosuid,rw,nouser,nofail 0 0

hal_cat (author)greenpi2017-06-02

The only fix I've found so far is to back out the changes to fstab. :-(

Carlswanson60 (author)2016-11-30

Excellent write up, easy to follow and implement.

PCSolid (author)2016-09-23

Worked great from beginning to end! Thnx for posting. Big help! Keep up great work!

mang (author)2016-08-11

Hey, look whose tutorial I found :) Nice one!

ccdanieldb (author)2016-06-01

Works very well. Thank you!

Ali3nman (author)2016-02-18

Awesome! Thank you!

DavidB464 (author)2016-01-20

This worked perfectly for me, thanks for the simple straightforward instructions

kkjkearney (author)2015-12-29

This post was written quite a while ago; the picture is an old Pi...

Didn't work for me. Glad I had a back-up image of my SD card. This seems like a pretty basic function that I would have thought Raspbian would handle without trickery or special modifications.

JTB3 (author)2015-12-14

I must have typed something wrong. Now I get "Welcome to emergency mode" with errors pointing to being unable to mount //home/pi/usbdrv. Anyone have any ideas?

greenpi (author)JTB32015-12-17

//home/pi/usbdrv is not a valid path so indeed a typo. It should be /home/pi/usbdrv

greenpi (author)JTB32015-12-17

//home/pi/usbdrv is not a valid path so indeed a typo. It should be /home/pi/usbdrv

james.eberhardt (author)2015-11-26

Thanks! Very helpful!

My only comment is that if you want the drive to be accessible for all users, I wouldn't put the mount folder in /home/pi/, since that's the home directory for the user "pi".

noel.kuck (author)2015-08-01

how did you arrive at an address for your SD card?

rpereira silveira (author)2015-06-21


Shawson (author)2015-05-07

Wworked like a charm! Thank you!

NeilK3 (author)2015-04-13

Can we use an NTFS formatted drive? Is there a limit to the capacity of a FAT formatted driver?

swilson81 (author)NeilK32015-04-23

I don't remember exactly, but I think the major differences between NTFS and FAT drives are a capacity limit with FAT and NTFS drives are a lot more secure than their counter part. Someone want to back me up?

ceterelealtdileyt (author)2015-01-21

This is an awesome instruction for especially who dont know linux commands. I've researched many forums about this subject but only yours solved my problems. Thanks a lot...

durgeshkumargupta made it! (author)2014-12-20

Thanks for the neat and simple instructions

ggauthier1 (author)2014-12-10

You don't actually have to reboot:

root@spencer:~# fdisk -l
Disk /dev/mmcblk0: 31.9 GB, 31914983424 bytes
4 heads, 16 sectors/track, 973968 cylinders, total 62333952 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00090806
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 8192 122879 57344 c W95 FAT32 (LBA)
/dev/mmcblk0p2 122880 62333951 31105536 83 Linux
Disk /dev/sda: 64.0 GB, 64016220160 bytes
255 heads, 63 sectors/track, 7782 cylinders, total 125031680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sda1 2 125031679 62515839 b W95 FAT32
root@spencer:~# df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 30G 2.4G 26G 9% /
/dev/root 30G 2.4G 26G 9% /
devtmpfs 239M 0 239M 0% /dev
tmpfs 49M 220K 49M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 97M 0 97M 0% /run/shm
/dev/mmcblk0p1 56M 9.7M 47M 18% /boot
root@spencer:/# cd /media
root@spencer:/media# ls -la
total 8
drwxr-xr-x 2 root root 4096 Sep 8 19:55 .
drwxr-xr-x 22 root root 4096 Dec 10 07:41 ..
root@spencer:/media# mkdir usbdrive
root@spencer:/media# ls -la
total 12
drwxr-xr-x 3 root root 4096 Dec 10 08:06 .
drwxr-xr-x 22 root root 4096 Dec 10 07:41 ..
drwxr-xr-x 2 root root 4096 Dec 10 08:06 usbdrive
root@spencer:/media# blkid
/dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="787C-2FD4" TYPE="vfat"
/dev/mmcblk0p2: UUID="3d81d9e2-7d1b-4015-8c2c-29ec0875f762" TYPE="ext4"
/dev/sda1: LABEL="UNTITLED" UUID="3B49-0FFE" TYPE="vfat"
root@spencer:/media# vi /etc/fstab [edited as noted above]
root@spencer:/media# mount /dev/sda1
root@spencer:/media# ls -la
total 40
drwxr-xr-x 3 root root 4096 Dec 10 08:06 .
drwxr-xr-x 22 root root 4096 Dec 10 07:41 ..
drwxr-xr-x 5 gmgauthier gmgauthier 32768 Jan 1 1970 usbdrive
root@spencer:/media# cd usbdrive
root@spencer:/media/usbdrive# ls -la
total 164
drwxr-xr-x 5 gmgauthier gmgauthier 32768 Jan 1 1970 .
drwxr-xr-x 3 root root 4096 Dec 10 08:06 ..
drwxr-xr-x 2 gmgauthier gmgauthier 32768 Dec 10 2014 .fseventsd
drwxr-xr-x 4 gmgauthier gmgauthier 32768 Dec 10 2014 .Spotlight-V100
drwxr-xr-x 2 gmgauthier gmgauthier 32768 Dec 10 2014 .Trashes
-rwxr-xr-x 1 gmgauthier gmgauthier 4096 Dec 10 2014 ._.Trashes

This was all done without a reboot of the raspberry.

astral_mage (author)2014-04-16

kool info and first to post.

About This Instructable




Bio: Scott Kildall is an new media artist and researcher. He works at Autodesk, Pier 9 and is an artist-in-residence with the SETI Institute
More by scottkildall:Pier 9 Guide: Fusion 360 to OMAX WaterjetStrewn Fields: Waterjet Etching Into StonePier 9 Resource: Setting up 2D profiles for CNC in Fusion 360
Add instructable to: