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.
Mounting a USB Thumb Drive with the Raspberry Pi
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

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 10.0.1.62. Your IP address may be different ā€” just change the address accordingly.Open the Terminal window and on the command line, type:
ssh [email protected] you are running directly hooked into the monitor, you can skip this step.

Run the latest package update and upgrades, just to make s

ure 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

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 [email protected]

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 d

rive 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).

Mounting a USB Thumb Drive with the Raspberry Pi

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.

 

 

For more detail: Mounting a USB Thumb Drive with the Raspberry Pi


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top