2

So I'm trying to get a working code in Python that will eject/unmount all USB flash drives attached to the Pi (Running Raspbian) - so that they can be removed safely. The final code will be run from within the python program.

Additionally, I'd like to eject/unmount the USB flash drive even if it's in use.

I've looked around and can't see how to do this. Thanks.


udisks --detach /media/pi/DOCS/ - 'Blocked device... Resource temporarily available'...

udisks --detach /media/pi/ - 'Blocked device...Resource temporarily available'...

udisks --detach /media/ - 'Blocked device...Resource temporarily available'...

sudo udisks --detach /media/pi/DOCS/ - still blocked...

sudo umount /path/to/devicename - command not found...

eject /media/pi/DOCS/ - Unable to open '/dev/sda'

(DOCS is the name if my USB flash drive. - though I want to eject all USB flash drives - not just my one)


So I'm going to ask the user in Python to select their USB flash drive from a list, which is pretty easy (just read in the folder) - so I will have the pathway to the USB. I'm still not sure which code can safely disconnect the USB flash drive - Maybe more research is the answer. Thanks for your help so far.

3
  • 1
    What have you tried so far? Edit your post with things you have done. Commented Nov 21, 2017 at 16:37
  • What does this have to do with tkinter? Commented Nov 21, 2017 at 16:49
  • sorry, Nae - nothing really - the button's written in tkinter. I removed the tag. Commented Nov 21, 2017 at 16:53

2 Answers 2

2

For udisks --detach the parameter should be the device, not the mounting point. For example, if the USB Disk is /dev/sdb the command would be udisks --detach /dev/sdb

If the command still doesn't work you could try udiskctl power-off -b <device> which should also work.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the answer - so the pathway that appears on my Pi is /media/pi/DOCS - not /dev/sdb. Any idea what path I should use?
@DavidW.Beck /media/pi/DOCS is the Mount pount, but not the device. What Output do you get from mount | grep /media/pi/DOCS?
/dev/sda1 on /media/pi/DOCS type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0077,codepage=437,iocharset=ascii,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)
Okay, so your USB Device is found under /dev/sda. So, for ejecting you should use udisks --detach /dev/sda.
Thanks for your help! Unfortunately, I'm getting 'one or more partitions are busy on /dev/sda' - I think this is the correct command however it's being automated.
2

so I found the answer:

sudo eject /dev/sda1

-This disconnects the USB flash drive on a Raspberry Pi.

Thank you very much to everyone who helped!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.