AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1118357
Accepted
A Tyshka
A Tyshka
Asked: 2019-02-15 13:54:24 +0800 CST2019-02-15 13:54:24 +0800 CST 2019-02-15 13:54:24 +0800 CST

没有 sudo 无法弹出 USB 驱动器?

  • 772

我正在尝试在命令行中弹出 USB 驱动器,eject /dev/sdg1但出现以下错误:

eject: unable to open `/dev/sdg'

该命令会卸载驱动器,但不会弹出它。但是,使用 sudo 运行就可以了。这是错误还是预期行为?我正在尝试将其合并到 python 应用程序中,所以 sudo 并不是一个真正的选择。请注意,umount没有 sudo 也可以正常工作。

这是一个 USB 闪存驱动器。我认为上面只有一个分区

mount usb sudo unmount udev
  • 2 2 个回答
  • 1748 Views

2 个回答

  • Voted
  1. Best Answer
    Elder Geek
    2019-02-16T10:23:53+08:002019-02-16T10:23:53+08:00

    没有弹出 USB 设备的机制。卸载它(在您的情况下umount /dev/sdg1并手动删除它。(假设 /dev/sdg1 是 /dev/sdg 上唯一安装的分区)。您可以使用类似命令验证设备上安装了哪些分区lsblk以及mount | grep sdXsdX 对应于您的设备的位置(在你的情况下,sdg)。

    eject专门用于可移动介质,例如光驱、软盘、磁带、ZIP、JAZ 驱动器,闪存驱动器根本不支持。

    资料来源:

    man eject

    • 4
  2. sudodus
    2019-02-16T11:55:08+08:002019-02-16T11:55:08+08:00

    我认为在 USB 驱动器的情况下“弹出”意味着卸载和关闭电源,正如某些 GUI 工具(带有弹出符号)所实现的那样。

    您可以查看udisks和工具udisksctl。

    阅读手册

    man udisks
    man udisksctl
    

    例如,你会发现命令

       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]
    

    我觉得

    udisksctl unmount --block-device <device> && \
    udisksctl power-off --block-device <device>
    

    命令可以做你想做的事。在这种情况下,“sdg”中有一个分区<device>是/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.
    
    • 4

相关问题

  • 修复 USB 驱动器自动通知

  • 是否有更好的方式为 /home/userX 构建分区/挂载

  • 当另一个文件系统安装在路径上时是否可以删除文件?

  • 如何从命令行重置 USB 设备?

  • 为什么我需要 root 权限才能在命令行中卸载驱动器,而不是在 Nautilus 中?如何改变它?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve