2

I want to write data to a USB stick plugged into a specific USB port on the PI.

I know I can write to a specific USB device by using its UUID, and I know I can find the address for the USB port using lsusb however, I do not know how to then write to that port.

Is there any way of finding the UUID of a device plugged into a specific port to then address to? Or of simply addressing a specific port?

EDIT: It can be assumed that the device plugged in will only have a single partition, and it will be known which USB port it will be plugged in to.

EDIT2: Would it help if I named each drive the same?

  • 1
    A device does not have a UUID, see this - a partition MAY have one, but that is not guaranteed. What should happen if you insert a flash drive with multiple partitions? how would your device know which one to write to? – user2813274 Aug 26 '14 at 16:16
  • Possibly enumerate devices in all USB ports and search for a serial number or something uniquely identified by the device. – Piotr Kula Aug 26 '14 at 18:03
  • Thanks for the comments so far. In my specific case, it can be assumed that the drive will not have multiple partitions, as I have some control over that. It can be assumed that I will know which port the device will be plugged into too. The only idea I've had so far is to search the UUID's present, plug the device in, and then check for the added device, but this is a bit clunky. – Doragan Aug 27 '14 at 11:06
1

Easy. Create a udev rule for your usb stick in order to link your device to a unique /dev/sdX and put a entry in /etc/fstab to automount.

Use this if you run raspbian.

Use this if you run arch.

  • Thanks. This could potentially work... But could any suitable stick be used, or only those 'registered'? – Doragan Aug 28 '14 at 9:48
  • The rules contains vendor and model id. So if you want to use more than one stick, buy identical ones. Same brand, same model, same capacity. – Willian Paixao Aug 28 '14 at 14:24
  • Hmm, I can't guarantee that would happen. Thanks for your help so far though. – Doragan Aug 28 '14 at 14:44
1

Expanding on Willian Paxio's answer:

Create a udev rule for a stick (by using the KERNEL parameter with a match on sd*) that is plugged in to a specific port (by using the the KERNELS parameter to enumerate the bus/hub/port path to the device).

In addition to Willian's references, see this answer and this FAQ entry for details on how ports are enumerated in the KERNELS parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.