magicBanan3
Posts: 4
Joined: Thu Mar 19, 2020 2:57 pm

Safe ejecting of random USB-Drive

Thu Mar 19, 2020 3:12 pm

Hello Folks,

I'm new in the Raspberry Pi World and need your help.
I try to eject some USB-drives of my PI with a Pythonsketch, therefore I use those Codes:

Code: Select all

sudo eject /dev/sda1

Code: Select all

sudo umount /media/pi/*

Code: Select all

sudo eject /dev/sda
In my opinion those codes are working, because after I use the code I can't find the USB-driver I my path, but after I remove a USB-drive I get the following message: "Drive was removed without ejecting. Pleas use menu to eject before removal."

So is it just a message or is my sketch not working right?

Thank you for your help!

jahboater
Posts: 5759
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Safe ejecting of random USB-Drive

Thu Mar 19, 2020 3:42 pm

Please avoid "sudo", it is not needed to unmount your own disk.

I just do:

Code: Select all

sync
umount /media/<user>/xxxx
The sync is probably not needed, but does no harm.
Pi4 8GB running PIOS64

W. H. Heydt
Posts: 12655
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Safe ejecting of random USB-Drive

Fri Mar 20, 2020 1:36 am

magicBanan3 wrote:
Thu Mar 19, 2020 3:12 pm
Hello Folks,

I'm new in the Raspberry Pi World and need your help.
I try to eject some USB-drives of my PI with a Pythonsketch, therefore I use those Codes:

Code: Select all

sudo eject /dev/sda1

Code: Select all

sudo umount /media/pi/*

Code: Select all

sudo eject /dev/sda
I think that's your problem. You're unmounting the device *partition* and then ejecting the entire *device*.

magicBanan3
Posts: 4
Joined: Thu Mar 19, 2020 2:57 pm

Re: Safe ejecting of random USB-Drive

Fri Mar 20, 2020 6:28 am

jahboater wrote:
Thu Mar 19, 2020 3:42 pm
Please avoid "sudo", it is not needed to unmount your own disk.

I just do:

Code: Select all

sync
umount /media/<user>/xxxx
The sync is probably not needed, but does no harm.

Thank you for your answer!
What do you mean with "<user>"?

magicBanan3
Posts: 4
Joined: Thu Mar 19, 2020 2:57 pm

Re: Safe ejecting of random USB-Drive

Fri Mar 20, 2020 6:31 am

W. H. Heydt wrote:
Fri Mar 20, 2020 1:36 am
magicBanan3 wrote:
Thu Mar 19, 2020 3:12 pm
Hello Folks,

I'm new in the Raspberry Pi World and need your help.
I try to eject some USB-drives of my PI with a Pythonsketch, therefore I use those Codes:

Code: Select all

sudo eject /dev/sda1

Code: Select all

sudo umount /media/pi/*

Code: Select all

sudo eject /dev/sda
I think that's your problem. You're unmounting the device *partition* and then ejecting the entire *device*.
Ahh alright and how do I unmount the device in the right way?
Thank you for your answer!

PiGraham
Posts: 3939
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Safe ejecting of random USB-Drive

Fri Mar 20, 2020 7:50 am

magicBanan3 wrote:
Fri Mar 20, 2020 6:28 am

What do you mean with "<user>"?
It means the name of the user account. The default for Rasbian is "pi"

So in the example:

Code: Select all

umount /media/pi/*
<user> = pi

magicBanan3
Posts: 4
Joined: Thu Mar 19, 2020 2:57 pm

Re: Safe ejecting of random USB-Drive

Fri Mar 20, 2020 9:46 am

PiGraham wrote:
Fri Mar 20, 2020 7:50 am
magicBanan3 wrote:
Fri Mar 20, 2020 6:28 am

What do you mean with "<user>"?
It means the name of the user account. The default for Rasbian is "pi"

So in the example:

Code: Select all

umount /media/pi/*
<user> = pi
Ah okay, I tried in this way: "umount /media/pi/nameOfUsb" and it works, but I still getting the same message.

Return to “General discussion”