Find USB flash drive device in Linux

Find USB drive in Linux / Unix

Recently I have written a quick “how to” on restoring, formatting a USB flash drive. The “how to” had a lot of hits from different places since then, mostly from GOOGLE, of course, but some from independent bloggers, like my blogging self.

One of such places was www.newlinuxuser.com. Although the guide “saved them” (welcome :)) they had a very constructive critique that one thing the guide missed was how to actually find which device to restore / format.

Hence I decided to write a new little 2 step “how to” that will teach you just that.

Step 1. System Log is your friend, listen to what it has to say…

Imagine you close your eyes, and someone puts an apple in your mouth – would you be able to identify what the heck was put into your mouth? For most people the answer would be “yes”. ( If you’d like to experiment, feel free :). The thing is once you bite on that apple, your brain goes through many lines of code (given that we are written in C), finds that match, and reports:

"The object in your mouth was identified as an Apple - we've had that before.
  I just talked to the stomach, it knows how to digest it."

You would think that your Linux/Unix system is any different? Well, not really.

Right after you insert a USB device into a slot, Linux/Unix will try to read, and identify it. While doing that, it will also assign it to a particular device as “/dev/particular-device”. This device is exactly the information we need, so we can talk to it, and mount it.

Although most people would approach it with running a dmesg, and look at the output, I prefer a more natural OS way to look at things – we’ll look directly in the eye of a System Log!

Let’s use “tail -f”, so we can see real time system log updates:

tail -f /var/log/messages

Now insert your USB drive into a slot and you should see the output similar to:

Dec  5 14:53:19 your-hostname kernel: [81585.308993] usb 4-1: new full speed USB device using uhci_hcd and address 3
Dec  5 14:53:19 your-hostname kernel: [81585.456757] usb 4-1: not running at top speed; connect to a high speed hub
Dec  5 14:53:19 your-hostname kernel: [81585.484884] usb 4-1: configuration #1 chosen from 1 choice
Dec  5 14:53:19 your-hostname kernel: [81585.498817] scsi6 : SCSI emulation for USB Mass Storage devices
Dec  5 14:53:24 your-hostname kernel: [81590.514870] scsi 6:0:0:0: Direct-Access     USB 2.0  USB Flash Drive  0.00 PQ: 0 ANSI: 2
Dec  5 14:53:24 your-hostname kernel: [81590.519874] sd 6:0:0:0: [sdb] 15794175 512-byte hardware sectors (8087 MB)
Dec  5 14:53:24 your-hostname kernel: [81590.522834] sd 6:0:0:0: [sdb] Write Protect is off
Dec  5 14:53:24 your-hostname kernel: [81590.534817] sd 6:0:0:0: [sdb] 15794175 512-byte hardware sectors (8087 MB)
Dec  5 14:53:24 your-hostname kernel: [81590.537814] sd 6:0:0:0: [sdb] Write Protect is off
 
>>>>  Dec  5 14:53:25 your-hostname kernel: [81590.537888]  sdb: sdb1  <---- GOT YOU!
 
Dec  5 14:53:25 your-hostname kernel: [81590.654848] sd 6:0:0:0: [sdb] Attached SCSI removable disk

Note that the USB drive was “connected”, or associated with sdb device

[81590.654848] sd 6:0:0:0: [sdb] 15794175 512-byte hardware sectors (8087 MB)

and more precisely, with sdb1 device

[81590.537888]  sdb: sdb1

And that means we can talk to it! The full name of the guy would be “/dev/sdb1″.

Now let’s greet our friend. Say: “Hi /dev/sdb1″! :)

Step 2. Mount USB drive’s device to the File System.

Just an extra step, in case you need to mount it. If you can’t, and would like to format it, so you can mount it afterwards, read this.

To mount the drive enter this:

sudo mount -t vfat /dev/sdb1 /media/usbdrive/

where “/dev/sdb1″ is the name of the device, we found in the step above. “/media/usbdrive/” is the directory that we are going to mount it to. Make sure this directory exists (otherwise create it “sudo mkdir /media/usbdrive/”). And “-t vfat” is asking your Linux/Unix OS to mount this device as a “vfat” (FAT16, FAT32) device.

Many, if not most, USB devices are VFAT, however if you have an NTFS USB hard drive, for example, you can mount it by entering:

sudo mount -t ntfs-3g /dev/sdb1 /media/usbdrive/ -o force

“sudo” in above couple commands comes from mostly Ubuntu way to “run command as a super user”. If you have any other flavor of Linux/Unix, you may want to just run it as a “root” user.

Eat more apples, and good luck!

30 comments

  1. You also might looking into mounting the stick by UUID or label, which saves you the hassle of finding the device (all but the first time, anyway).

  2. @Matt,

    Although it seems to me to be a bit easier for non “sysadmin” :) people to check the syslog – thanks for the tip.

    – Toly

  3. Thanks for the update. This is helpful :)

  4. Useful tip! Ubuntu can do that automatically, but I love the complicated way… Thanks!

  5. @Esteban,

    Ubuntu does it “automatically” most of the time. However there are times (mostly hardware related) where Ubuntu can’t/don’t mount the USB drive.

    – Toly

  6. Great series of posts, this saved several flash drives I had inadvertently screwed up. Thanks much!

  7. You’re right Toly! …even when Ubuntu can sometimes do it “automatically” I prefer the manual way, that’s why I liked your tip… very useful tip indeed! Thanks so much! :)

  8. David J. Heinrich

    I have one that says sdb:sdb1 when I plug it in; but i have no /dev/sdb1 device:

    # mount -t vfat /dev/sdb1 /media/”USB Drive”
    mount: special device /dev/sdb1 does not exist

    Navigating to /dev and using MAKEDEV doesn’t help:

    # cd /dev
    # sudo ./MAKEDEV sdb1
    .udevdb or .udev presence implies active udev. Aborting MAKEDEV invocation.

    What do I do?

  9. @David,

    Can you inject your usb drive, run “dmesg”, and post 10-20 lines where it identifies your drive? This might help to resolve your problem.

    Thank you,
    – Toly

  10. I use the command
    fdisk -l (small L)
    Shows all storage devices.

  11. useful article. i have a fileserver with no desktop and this helped me identify a couple of dead usb connections. eventually found a live one at the rear of the server. much quicker than moving big files across the network. thanks

  12. Hi,

    I was trying to mount a USB in linux kernel of Chromium OS using your directions. I am able to find a usb but when I try to mount it, it gives me an error: “unknown filesystem type ‘ntfs’ “. which probably means that this flavor of linux doesnt recognize ntfs? do you know of a way to fix that?

  13. Thanks. This was very helpful in tracking down the device names for two USB flash media readers.

  14. To be precise /dev/sda is the device and /dev/sda1 is a partition =)

  15. sudo fdisk -l
    would give the list of all the devices in your computer. No need to look for it in log.

  16. Very useful information and guide. Thanks so much for this nice guide.
    I looked to many websites and blogs to find the guide with such a details but cant find it expect here. You have done a great job.

  17. Aug 18 13:59:23 localhost kernel: sd 5:0:0:0: Attached scsi generic sg1 type 0
    Aug 18 13:59:25 localhost gconfd (root-17454): Failed to flush client add to saved state file: No space left on device
    Aug 18 13:59:25 localhost gconfd (root-17454): Failed to log addition of listener gnome-mount (Failed: Failed to log addition of listener to gconfd logfile; won\\\’t be able to re-add the listener if gconfd exits or shuts down (No space left on device));will not be able to restore this listener on gconfd restart, resulting in unreliable noti

  18. worked for me.. nice tutorial :)

  19. how can i edi ip address in a file system

  20. I followed the instructions to mount a NTFS drive, and for some reason RHEL 6 is refusing to recognise that I have NTFS-3G installed…has anyone else encountered this error?

    Also, do you have a guide on how to add entries to the /etc/fstab file?

  21. Thanks for the tip ! I’m having some trouble copying my files to the device though, it says that I do not have permission to copy files (that I’m not “the owner”). Help?

  22. Great, thanks !

  23. Hi

    You have a great tutorial. Could you please help me a little further.

    I’m completely new to Linux. I’ve downloaded Ubuntu , then using Linux Live CD , I’ve created a bootable USB drive

    Ubuntu is just smply great…works beautifully on the USB boot … just imagine a complete linux NOOB going about browsing, creating spread sheets etc on Linux …its just great

    However, while I can read the hard disks on my machine, I cannot seem to detect the USB itself, i,.e. the one on which this linux is installed

    Of course I am dead sure the USB is plugged in as I am physically in front of the machine

    How do I detect / locate my usb

    How do I download stuff to my USB ?

    Thanks in advance
    Best regards

    Linux noobie

  24. Hi: command not found :D

  25. Richard Bronosky

    @max, yes and fdisk -l gets it’s info from /proc/partitions ;-) so, if you want to find your drive via a script, that would be the way to go.

  26. Great tutorial! In step 2, I would use “mount – t auto” and let mount utility try to determine the correct file system type instead of me trying to guess.

    Example:
    sudo mount -t auto /dev/sdb1 /media/usbdrive/

tell me something...
  1. (required)
  2. (valid email - optional)
  3. Captcha
  4. (required)