title: Find which drive corresponds to which USB mass storage device in Linux
body: <p>I have several USB mass storage flash drives connected to a Ubuntu Linux computer (Ubuntu 10.04.1, kernel 2.6.32-25-386), and I need to tell them apart programatically (from bash if possible, but I'm not afraid of compiling either) - I need to find which block device corresponds to which <em>physical</em> device (e.g. <code>/dev/sdb1</code> -> device in USB port 1; in my case, one device ~ one volume). </p>
  
  <p>In other words, I know that I have three hardware devices plugged into USB ports; each of them shows up in the system as a USB mass storage device (as seen with lsusb), is created as a block device (<code>/dev/sdb1</code>) and automounted by UUID (<code>/media/1234-5678</code>).</p>
  
  <pre><code>USB device               block device    mountpoint
  USB device in port 2.2 &lt;-&gt; /dev/sdb1   &lt;-&gt; /media/1234-5678
  </code></pre>
  
  <p>I'm <em>not</em> trying to find the relationship between block device and mountpoint; <strong>I'm trying to find the relationship between block device and USB device, is there a way?</strong></p>
  
  <p>Why? There will be some writes on the disks, with unpredictable time of completion. I need to give the operator some indication like "you can now remove the disk in port 2 (which is second from the left)". I have found which physical port corresponds to which port number on that specific machine, and finding block devices from mountpoints is simple; now I'm stuck mapping the logical USB ports to block devices.</p>
  
  <p>I can see the disks with lsusb :</p>
  
  <pre><code>Bus 001 Device 058: ID 067b:2517 Prolific Technology, Inc. Mass Storage Device
  Bus 001 Device 060: ID 067b:2517 Prolific Technology, Inc. Mass Storage Device
  Bus 001 Device 061: ID 067b:2517 Prolific Technology, Inc. Mass Storage Device
  </code></pre>
  
  <p>and I can see them mounted (by their UUID):</p>
  
  <pre><code>/dev/sdb1 on /media/BC88-15C4 type vfat
  /dev/sdc1 on /media/AE54-65AA type vfat
  /dev/sdd1 on /media/58D2-FED1 type vfat
  </code></pre>
  
  <p>Now, all the drives are the same model from the same manufacturer, so I can't distinguish them by that, and I can't guarantee they'll be plugged in a particular order.</p>
  
  <p>I have found <code>/sys/bus/usb/devices</code> (a list of USB devices), but it seems to be the same data that I get from lsusb - I don't see a mapping to disks there.</p>
  
  <p>There's also <code>/sys/block/sdb</code> and <code>/sys/block/sdb/sdb1</code> (the block device and its first partition; similarly for <code>sdc</code> and <code>sdd</code>), but again, I see no mapping to devices.</p>