How do I determine if a connected USB device is a USB flash drive?

Boy picture Boy · Apr 3, 2012 · Viewed 20.4k times · Source

how do you determine what kind of media has been attached to the system?

I have Ubuntu, and when I inserted an SD-card, it notices that it is in fact an SD card. Same counts for USB sticks.

But how can I determine on low level when a new device is inserted, what kind of type it is?

There seems to be no information to be found on this at all.

edit: just to be more complete: I said it is a Linux environment, but actually it is Android in an Embedded environment. I tagged it Linux because I am indeed trying to check from command line.

The udevadm command is not available, and lsusb -vv shows:

Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 002: ID 0424:2640
Bus 001 Device 003: ID 0424:4040
Bus 002 Device 001: ID 1d6b:0001

which is very little info.

Answer

hovanessyan picture hovanessyan · Apr 3, 2012

The lsusb command lists the USB devices registered in the system. Try lsusb -vv for more detailed info. You can use the -s flag to target specific device.

UPDATE: It depends on the permissions of your account, some details require higher privileges. For example here's the output for my mouse:

Bus 003 Device 003: ID 04f3:0230 Elan Microelectronics Corp. 
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x04f3 Elan Microelectronics Corp.
  idProduct          0x0230 
  bcdDevice           24.58
  iManufacturer           0 
  iProduct                2 USB+PS/2 Optical Mouse
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      1 Boot Interface Subclass
      bInterfaceProtocol      2 Mouse
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      52
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0004  1x 4 bytes
        bInterval              10
Device Status:     0x0000