1

I'm hoping this is a very simple issue with a simple solution.

I have a raspberry pi and an external hard drive that I am writing data to. I would like to know if there is a way in python, to programmatically determine the name of a connected drive in order to switch to the proper directory.

Right now my program is hard coded, but I would like to have the pi determine the name of the drive in order to account for the drives name possibly getting changed (which has already happened).

The drive always appears in the /media/pi directory. My solution right now is to just fetch the names in that directory, disregard certain folders already there, then assign my drive variable to the (hopefully) only remaining one. I don't like this idea but its my only one right now.

Does the community have a more robust solution to my problem? If so how should I go about doing this?

  • What kind of drive? How is it connected? Why does the name change - is it "modified" by some external entity. – Milliways Nov 24 '15 at 3:23
  • Look into partition UUIDs and using udev or fstab to set a persistent mount point. The automounter (which attaches things in /media) may get in the way of this, but it is not necessary that you use it. – goldilocks Nov 24 '15 at 4:34
  • Have a look in /dev/disk/by-label/ There's actually several ways to find a device in that area. by-id, by-label, by-path and by-uuid. If you know the drive' UUID, you can find it directly and never care what the label is. Or use UUID to determine label and then use that. The drive is likely mounted at /media/pi/LABEL_HERE/, right? Poke around in /dev/disk/by-*. – lornix Nov 24 '15 at 14:36

Your Answer

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

Browse other questions tagged or ask your own question.