在 Linux / Ubuntu 上,关闭 usb 硬盘的电源 (**)/ 在 win 出现 “磁盘存在问题” 的提示。

107 篇文章 0 订阅

udisksctl 用法

在 Ubuntu 上,关闭 usb 硬盘的电源

---------------------------------------------------------------

参考:

What is the Command Line Equivalent of "Safely Remove Drive"? 

https://askubuntu.com/questions/532586/what-is-the-command-line-equivalent-of-safely-remove-drive

在断开连接之前正常关闭 USB 磁盘驱动器  https://qa.1r1g.com/unix/ask/31122801/

移动硬盘在 win 和 Liunx 之间共用时,操作系统总是会对磁盘的某个公共扇区进行改写?

造成插入到 win 后,是不是就会出现 “磁盘存在问题” 的提示。

====================================

在 Ubuntu 上,关闭 usb 硬盘的电源

命令行方式

https://unix.stackexchange.com/questions/444611/gracefully-shutting-down-usb-disk-drives-before-disconnect

弹出:

eject /dev/sdb

udisksctl unmount -b /dev/sdb1

udisksctl power-off -b /dev/sdb

  

udisksctl power-off --block-device /dev/sdb

图形界面方式

If you prefer a gui, gnome disks has a button to "power off this disk".

udisksctl 用法

udisksctl — The udisks command line tool

  http://storaged.org/doc/udisks2-api/latest/udisksctl.1.html

SYNOPSIS

udisksctl status

udisksctl info { --object-path OBJECT | --block-device DEVICE | --drive DRIVE }

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 unlock { --object-path OBJECT | --block-device DEVICE } [--no-user-interaction] [--key-file PATH] [--read-only]

udisksctl lock { --object-path OBJECT | --block-device DEVICE } [--no-user-interaction]

udisksctl loop-setup --file PATH [--read-only] [--offset OFFSET] [--size SIZE] [--no-user-interaction]

udisksctl loop-delete { --object-path OBJECT | --block-device DEVICE } [--no-user-interaction]

udisksctl power-off { --object-path OBJECT | --block-device DEVICE } [--no-user-interaction]

udisksctl smart-simulate --file PATH { --object-path OBJECT | --block-device DEVICE } [--no-user-interaction]

udisksctl monitor

udisksctl dump

udisksctl help

DESCRIPTION

udisksctl is a command-line program used to interact with the udisksd(8) daemon process.

COMMANDS

status

Shows high-level information about disk drives and block devices.

info

Shows detailed information about OBJECT, DEVICE or DRIVE.

mount

Mounts a device. The device will be mounted in a subdirectory in the /run/media hierarchy - upon successful completion, the mount point will be printed to standard output.

unmount

Unmounts a device. This only works if the device is mounted. The option --force can be used to request that the device is unmounted even if active references exists.

unlock

Unlocks an encrypted device. The passphrase will be requested from the controlling terminal and upon successful completion, the cleartext device will be printed to standard output.

lock

Locks a device. This only works if the device is a cleartext device backed by a cryptotext device.

loop-setup

Sets up a loop device backed by FILE.

loop-delete

Tears down a loop device.

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.

smart-simulate

Sets SMART data from the libatasmart blob given by FILE - see /usr/share/doc/libatasmart-devel-VERSION/ for blobs shipped with libatasmart. This is a debugging feature used to check that applications act correctly when a disk is failing.

monitor

Monitors the daemon for events.

dump

Prints the current state of the daemon.

help

Prints help and exit.

DEVICE SPECIFICATION

For commands that require a device as an argument following options can be used to specify it.

-b, --block-device=DEVICE

Specify a device by its device file path. For example /dev/sda.

-p, --object-path=OBJECT

Specify a device by the UDisks internal object path without the /org/freedesktop/UDisks2 prefix. For example block_devices/sda for the /dev/sda disk.

-d, --drive=DRIVE

Specify a drive by name, for example VirtIO_Disk. This can be currently used only together with the info command.

COMMON OPTIONS

The option --no-user-interaction can be used to request that no interaction (such as the user being presented with an authentication dialog) must occur when checking with polkit(8) whether the caller is authorized to perform the requested action.

AUDIENCE

This program does not assume that the caller is the super user - it is intended to be used by unprivileged users and authorizations are checked by the udisks daemon using polkit(8). Additionally, this program is not intended to be used by scripts or other programs - options/commands may change in incompatible ways in the future even in maintenance releases. See the “API STABILITY” section of udisks(8) for more information.

BASH COMPLETION

udisksctl ships with a bash completion script to complete commands, objects, block devices and some options.

AUTHOR

This man page was originally written for UDisks2 by David Zeuthen <zeuthen@gmail.com> with a lot of help from many others.

BUGS

Please send bug reports to either the distribution bug tracker or the upstream bug tracker at Issues · storaged-project/udisks · GitHub.

SEE ALSO

udisks(8), udisksd(8), umount.udisks2(8), polkit(8)

:https://askubuntu.com/questions/532586/what-is-the-command-line-equivalent-of-safely-remove-drive

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值