Introduction: 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.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
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
Open the Terminal window and on the command line, type:
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 updateThen the upgrade:
sudo apt-get upgradeYou'll see a spool of package updates, which will take several minutes.
Step 3: Set Up a "mounting Point" for the USB Drive
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 firstname.lastname@example.orgWhat we then type in;
mkdir usbdrvWhat 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 blkidcheck 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.
/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
sudo nano /etc/fstabHere 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.
sudo rebootIf 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
cd usbdrvcreate a simple text file
sudo nano test.txtin 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
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 usbdrvif 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!
1 Person Made This Project!
- durgeshkumargupta made it!