Jun 022012
 

How to mount a USB flash drive on Raspberry Pi

(or any other linux device)

First we need to find out where our system locates the device. With the USB device not plugged in, type…
tail -f /var/log/messages

Then plug in your USB device and, looking in the new lines which appear, make a note of the ID – it will be something like sda1, sdb1, sda2, sdb2 etc.

finding the ID of USB device

Then CTRL-C To stop the tail command.

In this case the usb stick id is sda1. That means the device is located in /dev/sda1.

Next, we need to create a directory under /media, so you will be able to mount your drive.

sudo mkdir /media/usbstick usbstick can be whatever you want to call it

Then we mount the usb stick with…

If you are logged in as root…
mount -t vfat -o rw /dev/sda1 /media/usbstick/

…where sda1 is its id from the tail command and usbstick is the directory you just made.

If you are logged in as the default Raspberry Pi debian user, pi, you will need to use…

sudo mount -t vfat -o uid=pi,gid=pi /dev/sda1 /media/usbstick/

…or you won’t get read/write access (the -o stands for options, uid is user id and gid is group id).

Then you can go there and have a look…
cd /media/usbstick
ls -l

result of ls -l command

…and you should get a listing of what’s on the USB stick you just mounted.

All Done?

When you want to detach the stick, unmount it with…

sudo umount /media/usbstick

And then you can unplug it safely. If the umount command says the stick is in use, you may have to close any programs using the stick or, if the current directory is /media/usbstick, simply change it to another directory, then unmount the stick…

cd /home

That’s all there is to it.

  48 Responses to “mount a USB flash drive on raspberry pi”

  1. […] To mount a USB flash drive/memory stick or other device click here for the procedure […]

  2. […] some sort of external storage to your Raspberry Pi’s USB port. We’ve already seen how to identify and mount a USB flash drive / memory stick. The procedure for mounting and using an external USB hard disk is very similar and equally easy. […]

  3. Excellent, worked first time! Thank you .
    Regards
    John

  4. Question!
    I can copy files to the stick ,from Pi.
    When I copy WAV files from my laptop to the stick I cannot ‘see’ them when I do a list ( ls -l) on the Pi.
    What am I doing wrong?
    Thanks in advance for any and all replies!
    John

    • This is puzzling and I haven’t a clue without knowing more about how you are doing it. How are you copying the files from your laptop? Are you unplugging and replugging the stick or are you using some sort of ftp from your laptop? If you are unplugging and replugging, you have remembered to mount it again after plugging in the second time? If not, you’d see an empty directory.

  5. When I plug my USB in the light sometimes flashes, but it is rarely detected on the terminal. Just now it said sda: but then nothing… Any help?

    • Firstly: Are you running a raspberry pi with Debian (squeeze or wheezy)?

      Secondly: Before plugging in your USB stick, are you running the tail -f /var/log/messages

      Thirdly: If you are getting erratic behaviour, I would suspect an inadequate power supply. You would need to sort that out before anything else really.

      What kind of usb stick is it? (Make and size)

  6. If you are incredibly lazy, you could also “sudo apt-get install usbmount” one time.

    You will then end up with a bunch of entries in /media/ starting with usb0. As you connect usb drives, they will get mounted there automatically.

  7. […] To mount a USB flash drive/memory stick or other device click here for the procedure […]

  8. […] If you’re not sure what your SD card’s identifier is you can use the tail command as we did in the attaching a USB stick post. […]

  9. Hi,
    I don’t get any change on the tail -f /var/log/messages output, just constant lines about eth0 failed to read register index. Nothing comes up about the USB card. Nothing like sda /sda1 etc or similar. I’m using raspbian wheezy dstro and a hub for USB drive and keyboard and mouse.

    I’m a total beginner with this but I thought it ought to be easier than this!!!

    Cheers, thanks for the tutorial!
    Jules

    • If you’re using Raspbian I suspect that the USB stick might be automatically mounted. Not quite sure where exactly as you’re using a hub, but on mine, directly connected, it mounts a memory stick that’s called KINGSTON at…
      /media/KINGSTON

      try df -h
      you should get something like this…
      Filesystem Size Used Avail Use% Mounted on
      rootfs 7.1G 1.6G 5.2G 24% /
      /dev/root 7.1G 1.6G 5.2G 24% /
      tmpfs 19M 224K 19M 2% /run
      tmpfs 5.0M 0 5.0M 0% /run/lock
      tmpfs 37M 4.0K 37M 1% /tmp
      tmpfs 10M 0 10M 0% /dev
      tmpfs 37M 0 37M 0% /run/shm
      /dev/mmcblk0p1 56M 34M 23M 61% /boot
      /dev/sda1 7.4G 4.7G 2.8G 63% /media/KINGSTON

      That will show you all storage devices attached to your system.

      • I am having the same problem as Jules. I have a 750gb toshiba usb hardrive i am trying to connect via usb hub. total beginner here. I tried ( df -h ) like you said and it does not give me the last line like your’s says “KINGSTON”. When I have my USB harddrive plugged it during initial boot up I get an error where it attempts to “loading kernel modules” but it fails to do so. it recognizes my toshiba external USB harddrive as being plugged into it but times out. it does some other stuff for a few minutes before it just shuts down. the toshiba harddrive is powered by the USB cable and the light turns on when I power up the raspberry pi. PLEASE HELP
        ! getting frustrated…

        • If it’s shutting down, that’s almost certainly a power issue. I’m assuming you’re using a hub with its own power supply? What about your raspberry pi’s power supply? Is it adequate? Are you using Raspbian or one of the other distros like squeeze or wheezy beta?

  10. just in case one forgets to tell mount the user and group ids, it’s not necessary to unmount and mount again.
    just type:

    sudo mount -o remount,rw,uid=pi,gid=pi /media/usbstick (or whatever your directory's name is)

    HTH, Michael.

  11. interestingly it all worked, but I can’t then copy files to the usbstick which have a colon in the filename!! everything else is fine…so my file 533-pipe-car_diagnostics-Thu_Oct__4_12:57:31_BST_2012-32604 can’t be written without taking out the colons first!

    (works everywhere else on the filesystem)

    • Is that because it’s a VFAT formatted stick and they don’t allow colons in DOS format? I just tried to put a colon in a file on my Win7 machine and it told me to get lost. I expect it’s OK in linux EXT4 but not in DOS/WINDOWS.

  12. I’m using a regular 16gb flash drive

    The example shows sda: sda1
    But what I get is sda:

    Which makes the rest a bit difficult. I can’t find any verboten flash drives, the GUI can see it and see files on it and display a .jpg that’s on it. But the right click ‘mount device’ in File Manager is greyed out. And fdisk gives the correct capacity but complains that something doesn’t look like a partition table.

    • Sorry, while Windows is OK with the stick RPi doesn’t like it for some reason. Procedure worked (or so it appears) with the other stick.

      • It seems to be seeing the drive but not any partitions on it. /dev/sda is the device and the number 1,2,3 etc is the partition number. Something is up with it that it can’t see the partition. But I’m afraid I don’t know what it is. :(

        Have you tried it with just sda to see what happens?

  13. […] blog สอนการต่อ (mount) USB drive ภาษาอังกฤษ http://raspi.tv/2012/mount-a-usb-flash-drive-on-raspberry-pi เลยอยากลองและสาธิตให้ดูบ้าง เอา USB […]

  14. Excelent ! Thank you for your amazing tutorial, all worked just fine. Greetings from New-Caledonia!!

  15. […] Quellen: http://raspi.tv/2012/mount-a-usb-flash-drive-on-raspberry-pi; https://help.ubuntu.com/community/Fstab Hat dir diesen Beitrag geholfen oder gefallen? […]

  16. […] cela fonctionne ! J’ai placé mes fichiers musicaux sur une clé USB (montée grâce à ces conseils en anglais). Pour contrôler MPD, j’utilise le client Droid MPD Client que j’ai installé sur mon […]

  17. Using the version of Debian supplied by Maplin the USB stick is detected when you insert it and you are asked if you want to mount it. It mounts the USB in \media . There does not appear to be an easy way of unmounting it except from the terminal or shutting the RaspberryPi down.

    • If it’s mounted already, you can just use it as it is. You don’t have to do it my way. :) I noticed recently that Raspbian seems to automount some of my media now, but it’s still useful to know how to do it in case the process fails or something.

      If you really want to unmount it when the system has mounted it you can just umount /media/name_of_stick and then remount it my way wherever you like :)
      If that doesn’t work, stick a sudo in front of it.

  18. it works, had to change the mount name. In raspbian the usb is automatically mounted at /dev/sda
    you can then use the mount to command to access it in the home/media/usb
    still Thanks as it helped out.
    From Pakistan

  19. […] might not be sda1! You will need to find out what device it is! I found a good tutorial about this here the gist of it is as […]

  20. This is great! Worked beautifully. Thanks for the nice tutorial.

  21. Worked first time through. I am not used to that, but I certainly did like it.

    Terrific tutorial. Thanks.

  22. Really helpful – thank you.

  23. Is this to mount storage, or to mount RAM?

      • I believe the the flash drive is mounted as storage but it has several advantages. SD cards do not last as anywhere near as long. It is extremely annoying to set up a pi for a particular purpose and have the drive get fouled up. Of course the storage available is significantly greater. The jump drives are quite a bit faster in delivering information to the CPU. I have six RPis, and only one flash drive has failed, though SD card I have had has had a short life (except in cameras and GPSs.)

    • It is to mount fast, reliable storage. A USB hard drive can also be mounted this way, though they tend to be somewhat slower than either a flash drive or an SD card.

  24. How can I actually move the files? I got to the listing, now what?

    • You move files using
      mv source target
      where source is the path to your file and target is the destination path you want to put the files in

      e.g. mv /media/USBSTICK/movie.mp4 /home/pi/movie.mp4
      or mv /media/USBSTICK/*.mp4 /home/pi/*.mp4

  25. Thanks for a great tutorial! Worked great.

    If I always leave my usb stick plugged-in, is there some sort of configuration file that I can modify to automatically re-mount when I power-up the PI again?

    I assume that after I issue a sudo poweroff command, the unmount occurs automatically. When I power back up, the files on my stick don’t appear until after I type the mounting instructions again. That’s why I thought some sort of configuration file that gets executed at power-up would be great.

    Any thoughts?

  26. Hi,

    I have an Android cell phone and I´d like to transfer some files to it. When I connect the phone to RB, RB see it as a camera (GT-S5310B). I can see the “camera” files in RB File Manager, and even copy files to and from the phone.

    When I look for the device using tail -f /var/log/messages, I see the camera as usb 1-1.2: Product: GT-S5310B, however It´s not in /dev, so the mount command didn´t work.

    Do you know how could I copy a file to the device?

    Tks in advance,

    Mauro Assos

Leave a Reply