Can't eject USB drive without sudo?
I'm trying to eject a USB drive in the command line with eject /dev/sdg1
but I get the following error:
eject: unable to open `/dev/sdg'
The command unmounts the drive but does not eject it. However, running with sudo works just fine. Is this a bug or expected behavior? I'm trying to incorporate this into a python application so sudo isn't really an option. Note that umount
works just fine without sudo.
This is a usb flash drive. I think there's only a single partition on it
usb mount sudo udev unmount
add a comment |
I'm trying to eject a USB drive in the command line with eject /dev/sdg1
but I get the following error:
eject: unable to open `/dev/sdg'
The command unmounts the drive but does not eject it. However, running with sudo works just fine. Is this a bug or expected behavior? I'm trying to incorporate this into a python application so sudo isn't really an option. Note that umount
works just fine without sudo.
This is a usb flash drive. I think there's only a single partition on it
usb mount sudo udev unmount
Welcome to AskUbuntu! What type of device is /dev/sdg? eject is specifically for removeable media such as Optical, Floppy, tape, ZIP, JAZ drives and is not supported by all devices. Further /dev/sdg1 indicates a partition, not a device.
– Elder Geek
Feb 14 at 22:16
@ElderGeek this is a usb flash drive. I think there's only a single partition on it
– A Tyshka
Feb 15 at 2:30
1
As described by @ElderGeek, it is 'enough' to unmount all mounted partitions on a USB drive to be able to unplug it safely. This does not turn off the power, and it can be mounted again. This is what I have been doing for years and it works well. - I think 'ejecting' in the case of USB drives means unmounting and poweroff, as implemented by some GUI tools (with the eject symbol). In this case it is not straight-forward to mount it again without unplugging and replugging. Is this what you want?
– sudodus
Feb 15 at 19:09
@sudodus yes, that is what I want
– A Tyshka
Feb 15 at 19:41
add a comment |
I'm trying to eject a USB drive in the command line with eject /dev/sdg1
but I get the following error:
eject: unable to open `/dev/sdg'
The command unmounts the drive but does not eject it. However, running with sudo works just fine. Is this a bug or expected behavior? I'm trying to incorporate this into a python application so sudo isn't really an option. Note that umount
works just fine without sudo.
This is a usb flash drive. I think there's only a single partition on it
usb mount sudo udev unmount
I'm trying to eject a USB drive in the command line with eject /dev/sdg1
but I get the following error:
eject: unable to open `/dev/sdg'
The command unmounts the drive but does not eject it. However, running with sudo works just fine. Is this a bug or expected behavior? I'm trying to incorporate this into a python application so sudo isn't really an option. Note that umount
works just fine without sudo.
This is a usb flash drive. I think there's only a single partition on it
usb mount sudo udev unmount
usb mount sudo udev unmount
edited Feb 15 at 19:23
Elder Geek
27.4k954127
27.4k954127
asked Feb 14 at 21:54
A TyshkaA Tyshka
1053
1053
Welcome to AskUbuntu! What type of device is /dev/sdg? eject is specifically for removeable media such as Optical, Floppy, tape, ZIP, JAZ drives and is not supported by all devices. Further /dev/sdg1 indicates a partition, not a device.
– Elder Geek
Feb 14 at 22:16
@ElderGeek this is a usb flash drive. I think there's only a single partition on it
– A Tyshka
Feb 15 at 2:30
1
As described by @ElderGeek, it is 'enough' to unmount all mounted partitions on a USB drive to be able to unplug it safely. This does not turn off the power, and it can be mounted again. This is what I have been doing for years and it works well. - I think 'ejecting' in the case of USB drives means unmounting and poweroff, as implemented by some GUI tools (with the eject symbol). In this case it is not straight-forward to mount it again without unplugging and replugging. Is this what you want?
– sudodus
Feb 15 at 19:09
@sudodus yes, that is what I want
– A Tyshka
Feb 15 at 19:41
add a comment |
Welcome to AskUbuntu! What type of device is /dev/sdg? eject is specifically for removeable media such as Optical, Floppy, tape, ZIP, JAZ drives and is not supported by all devices. Further /dev/sdg1 indicates a partition, not a device.
– Elder Geek
Feb 14 at 22:16
@ElderGeek this is a usb flash drive. I think there's only a single partition on it
– A Tyshka
Feb 15 at 2:30
1
As described by @ElderGeek, it is 'enough' to unmount all mounted partitions on a USB drive to be able to unplug it safely. This does not turn off the power, and it can be mounted again. This is what I have been doing for years and it works well. - I think 'ejecting' in the case of USB drives means unmounting and poweroff, as implemented by some GUI tools (with the eject symbol). In this case it is not straight-forward to mount it again without unplugging and replugging. Is this what you want?
– sudodus
Feb 15 at 19:09
@sudodus yes, that is what I want
– A Tyshka
Feb 15 at 19:41
Welcome to AskUbuntu! What type of device is /dev/sdg? eject is specifically for removeable media such as Optical, Floppy, tape, ZIP, JAZ drives and is not supported by all devices. Further /dev/sdg1 indicates a partition, not a device.
– Elder Geek
Feb 14 at 22:16
Welcome to AskUbuntu! What type of device is /dev/sdg? eject is specifically for removeable media such as Optical, Floppy, tape, ZIP, JAZ drives and is not supported by all devices. Further /dev/sdg1 indicates a partition, not a device.
– Elder Geek
Feb 14 at 22:16
@ElderGeek this is a usb flash drive. I think there's only a single partition on it
– A Tyshka
Feb 15 at 2:30
@ElderGeek this is a usb flash drive. I think there's only a single partition on it
– A Tyshka
Feb 15 at 2:30
1
1
As described by @ElderGeek, it is 'enough' to unmount all mounted partitions on a USB drive to be able to unplug it safely. This does not turn off the power, and it can be mounted again. This is what I have been doing for years and it works well. - I think 'ejecting' in the case of USB drives means unmounting and poweroff, as implemented by some GUI tools (with the eject symbol). In this case it is not straight-forward to mount it again without unplugging and replugging. Is this what you want?
– sudodus
Feb 15 at 19:09
As described by @ElderGeek, it is 'enough' to unmount all mounted partitions on a USB drive to be able to unplug it safely. This does not turn off the power, and it can be mounted again. This is what I have been doing for years and it works well. - I think 'ejecting' in the case of USB drives means unmounting and poweroff, as implemented by some GUI tools (with the eject symbol). In this case it is not straight-forward to mount it again without unplugging and replugging. Is this what you want?
– sudodus
Feb 15 at 19:09
@sudodus yes, that is what I want
– A Tyshka
Feb 15 at 19:41
@sudodus yes, that is what I want
– A Tyshka
Feb 15 at 19:41
add a comment |
2 Answers
2
active
oldest
votes
There is no mechanism for ejecting a USB device. Unmount it with (in your case umount /dev/sdg1
and manually remove it. (Assuming /dev/sdg1 is the only mounted partition on /dev/sdg). You can verify what partitions are mounted on a device with commands like lsblk
and mount | grep sdX
where sdX corresponds to your device (in your case sdg).
eject
is specifically for removeable media such as Optical, Floppy, tape, ZIP, JAZ drives and is not supported by flash drives at all.
Sources:
man eject
Alright thanks. Just confused since sudo does properly eject the usb. I’ll just use unmount
– A Tyshka
Feb 15 at 19:43
add a comment |
I think 'ejecting' in the case of USB drives means unmounting and poweroff, as implemented by some GUI tools (with the eject symbol).
You can look into udisks
and the tool udisksctl
.
Read the manuals
man udisks
man udisksctl
For example, you will find the commands
udisksctl mount {--object-path OBJECT | --block-device DEVICE}
[--filesystem-type TYPE] [--options OPTIONS...]
[--no-user-interaction]
udisksctl unmount {--object-path OBJECT | --block-device DEVICE} [--force]
[--no-user-interaction]
udisksctl power-off {--object-path OBJECT | --block-device DEVICE}
[--no-user-interaction]
I think the
udisksctl unmount --block-device <device> &&
udisksctl power-off --block-device <device>
commands can do what you want. In this case with one partition in 'sdg' <device>
is /dev/sdg1
power-off
Arranges for the drive to be safely removed and powered off. On the OS
side this includes ensuring that no process is using the drive, then
requesting that in-flight buffers and caches are committed to stable
storage. The exact steps for powering off the drive depends on the
drive itself and the interconnect used. For drives connected through
USB, the effect is that the USB device will be deconfigured followed by
disabling the upstream hub port it is connected to.
Note that as some physical devices contain multiple drives (for example
4-in-1 flash card reader USB devices) powering off one drive may affect
other drives. As such there are not a lot of guarantees associated with
performing this action. Usually the effect is that the drive disappears
as if it was unplugged.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1118357%2fcant-eject-usb-drive-without-sudo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
There is no mechanism for ejecting a USB device. Unmount it with (in your case umount /dev/sdg1
and manually remove it. (Assuming /dev/sdg1 is the only mounted partition on /dev/sdg). You can verify what partitions are mounted on a device with commands like lsblk
and mount | grep sdX
where sdX corresponds to your device (in your case sdg).
eject
is specifically for removeable media such as Optical, Floppy, tape, ZIP, JAZ drives and is not supported by flash drives at all.
Sources:
man eject
Alright thanks. Just confused since sudo does properly eject the usb. I’ll just use unmount
– A Tyshka
Feb 15 at 19:43
add a comment |
There is no mechanism for ejecting a USB device. Unmount it with (in your case umount /dev/sdg1
and manually remove it. (Assuming /dev/sdg1 is the only mounted partition on /dev/sdg). You can verify what partitions are mounted on a device with commands like lsblk
and mount | grep sdX
where sdX corresponds to your device (in your case sdg).
eject
is specifically for removeable media such as Optical, Floppy, tape, ZIP, JAZ drives and is not supported by flash drives at all.
Sources:
man eject
Alright thanks. Just confused since sudo does properly eject the usb. I’ll just use unmount
– A Tyshka
Feb 15 at 19:43
add a comment |
There is no mechanism for ejecting a USB device. Unmount it with (in your case umount /dev/sdg1
and manually remove it. (Assuming /dev/sdg1 is the only mounted partition on /dev/sdg). You can verify what partitions are mounted on a device with commands like lsblk
and mount | grep sdX
where sdX corresponds to your device (in your case sdg).
eject
is specifically for removeable media such as Optical, Floppy, tape, ZIP, JAZ drives and is not supported by flash drives at all.
Sources:
man eject
There is no mechanism for ejecting a USB device. Unmount it with (in your case umount /dev/sdg1
and manually remove it. (Assuming /dev/sdg1 is the only mounted partition on /dev/sdg). You can verify what partitions are mounted on a device with commands like lsblk
and mount | grep sdX
where sdX corresponds to your device (in your case sdg).
eject
is specifically for removeable media such as Optical, Floppy, tape, ZIP, JAZ drives and is not supported by flash drives at all.
Sources:
man eject
edited Feb 15 at 19:26
answered Feb 15 at 18:23
Elder GeekElder Geek
27.4k954127
27.4k954127
Alright thanks. Just confused since sudo does properly eject the usb. I’ll just use unmount
– A Tyshka
Feb 15 at 19:43
add a comment |
Alright thanks. Just confused since sudo does properly eject the usb. I’ll just use unmount
– A Tyshka
Feb 15 at 19:43
Alright thanks. Just confused since sudo does properly eject the usb. I’ll just use unmount
– A Tyshka
Feb 15 at 19:43
Alright thanks. Just confused since sudo does properly eject the usb. I’ll just use unmount
– A Tyshka
Feb 15 at 19:43
add a comment |
I think 'ejecting' in the case of USB drives means unmounting and poweroff, as implemented by some GUI tools (with the eject symbol).
You can look into udisks
and the tool udisksctl
.
Read the manuals
man udisks
man udisksctl
For example, you will find the commands
udisksctl mount {--object-path OBJECT | --block-device DEVICE}
[--filesystem-type TYPE] [--options OPTIONS...]
[--no-user-interaction]
udisksctl unmount {--object-path OBJECT | --block-device DEVICE} [--force]
[--no-user-interaction]
udisksctl power-off {--object-path OBJECT | --block-device DEVICE}
[--no-user-interaction]
I think the
udisksctl unmount --block-device <device> &&
udisksctl power-off --block-device <device>
commands can do what you want. In this case with one partition in 'sdg' <device>
is /dev/sdg1
power-off
Arranges for the drive to be safely removed and powered off. On the OS
side this includes ensuring that no process is using the drive, then
requesting that in-flight buffers and caches are committed to stable
storage. The exact steps for powering off the drive depends on the
drive itself and the interconnect used. For drives connected through
USB, the effect is that the USB device will be deconfigured followed by
disabling the upstream hub port it is connected to.
Note that as some physical devices contain multiple drives (for example
4-in-1 flash card reader USB devices) powering off one drive may affect
other drives. As such there are not a lot of guarantees associated with
performing this action. Usually the effect is that the drive disappears
as if it was unplugged.
add a comment |
I think 'ejecting' in the case of USB drives means unmounting and poweroff, as implemented by some GUI tools (with the eject symbol).
You can look into udisks
and the tool udisksctl
.
Read the manuals
man udisks
man udisksctl
For example, you will find the commands
udisksctl mount {--object-path OBJECT | --block-device DEVICE}
[--filesystem-type TYPE] [--options OPTIONS...]
[--no-user-interaction]
udisksctl unmount {--object-path OBJECT | --block-device DEVICE} [--force]
[--no-user-interaction]
udisksctl power-off {--object-path OBJECT | --block-device DEVICE}
[--no-user-interaction]
I think the
udisksctl unmount --block-device <device> &&
udisksctl power-off --block-device <device>
commands can do what you want. In this case with one partition in 'sdg' <device>
is /dev/sdg1
power-off
Arranges for the drive to be safely removed and powered off. On the OS
side this includes ensuring that no process is using the drive, then
requesting that in-flight buffers and caches are committed to stable
storage. The exact steps for powering off the drive depends on the
drive itself and the interconnect used. For drives connected through
USB, the effect is that the USB device will be deconfigured followed by
disabling the upstream hub port it is connected to.
Note that as some physical devices contain multiple drives (for example
4-in-1 flash card reader USB devices) powering off one drive may affect
other drives. As such there are not a lot of guarantees associated with
performing this action. Usually the effect is that the drive disappears
as if it was unplugged.
add a comment |
I think 'ejecting' in the case of USB drives means unmounting and poweroff, as implemented by some GUI tools (with the eject symbol).
You can look into udisks
and the tool udisksctl
.
Read the manuals
man udisks
man udisksctl
For example, you will find the commands
udisksctl mount {--object-path OBJECT | --block-device DEVICE}
[--filesystem-type TYPE] [--options OPTIONS...]
[--no-user-interaction]
udisksctl unmount {--object-path OBJECT | --block-device DEVICE} [--force]
[--no-user-interaction]
udisksctl power-off {--object-path OBJECT | --block-device DEVICE}
[--no-user-interaction]
I think the
udisksctl unmount --block-device <device> &&
udisksctl power-off --block-device <device>
commands can do what you want. In this case with one partition in 'sdg' <device>
is /dev/sdg1
power-off
Arranges for the drive to be safely removed and powered off. On the OS
side this includes ensuring that no process is using the drive, then
requesting that in-flight buffers and caches are committed to stable
storage. The exact steps for powering off the drive depends on the
drive itself and the interconnect used. For drives connected through
USB, the effect is that the USB device will be deconfigured followed by
disabling the upstream hub port it is connected to.
Note that as some physical devices contain multiple drives (for example
4-in-1 flash card reader USB devices) powering off one drive may affect
other drives. As such there are not a lot of guarantees associated with
performing this action. Usually the effect is that the drive disappears
as if it was unplugged.
I think 'ejecting' in the case of USB drives means unmounting and poweroff, as implemented by some GUI tools (with the eject symbol).
You can look into udisks
and the tool udisksctl
.
Read the manuals
man udisks
man udisksctl
For example, you will find the commands
udisksctl mount {--object-path OBJECT | --block-device DEVICE}
[--filesystem-type TYPE] [--options OPTIONS...]
[--no-user-interaction]
udisksctl unmount {--object-path OBJECT | --block-device DEVICE} [--force]
[--no-user-interaction]
udisksctl power-off {--object-path OBJECT | --block-device DEVICE}
[--no-user-interaction]
I think the
udisksctl unmount --block-device <device> &&
udisksctl power-off --block-device <device>
commands can do what you want. In this case with one partition in 'sdg' <device>
is /dev/sdg1
power-off
Arranges for the drive to be safely removed and powered off. On the OS
side this includes ensuring that no process is using the drive, then
requesting that in-flight buffers and caches are committed to stable
storage. The exact steps for powering off the drive depends on the
drive itself and the interconnect used. For drives connected through
USB, the effect is that the USB device will be deconfigured followed by
disabling the upstream hub port it is connected to.
Note that as some physical devices contain multiple drives (for example
4-in-1 flash card reader USB devices) powering off one drive may affect
other drives. As such there are not a lot of guarantees associated with
performing this action. Usually the effect is that the drive disappears
as if it was unplugged.
edited Feb 16 at 11:35
answered Feb 15 at 19:55
sudodussudodus
25.2k32977
25.2k32977
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1118357%2fcant-eject-usb-drive-without-sudo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Welcome to AskUbuntu! What type of device is /dev/sdg? eject is specifically for removeable media such as Optical, Floppy, tape, ZIP, JAZ drives and is not supported by all devices. Further /dev/sdg1 indicates a partition, not a device.
– Elder Geek
Feb 14 at 22:16
@ElderGeek this is a usb flash drive. I think there's only a single partition on it
– A Tyshka
Feb 15 at 2:30
1
As described by @ElderGeek, it is 'enough' to unmount all mounted partitions on a USB drive to be able to unplug it safely. This does not turn off the power, and it can be mounted again. This is what I have been doing for years and it works well. - I think 'ejecting' in the case of USB drives means unmounting and poweroff, as implemented by some GUI tools (with the eject symbol). In this case it is not straight-forward to mount it again without unplugging and replugging. Is this what you want?
– sudodus
Feb 15 at 19:09
@sudodus yes, that is what I want
– A Tyshka
Feb 15 at 19:41