udisksctl有power-off标志,建议您将其与
unmount
来自man udisksctl:
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
演示版
这是我卸载USB Jumpdrive,然后关闭电源
testdir:$ lsusb
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 009: ID 154b:007a PNY
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
testdir:$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 111.8G 0 disk
└─sda1 8:1 0 111.8G 0 part /
sdb 8:16 1 30G 0 disk
└─sdb1 8:17 1 30G 0 part /media/xieerqi/6A32C4555E1C5B4D
sr0 11:0 1 1024M 0 rom
testdir:$ udisksctl unmount -b /dev/sdb1 && udisksctl power-off -b /dev/sdb1
Unmounted /dev/sdb1.
testdir:$ lsusb
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
testdir:$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 111.8G 0 disk
└─sda1 8:1 0 111.8G 0 part /
sr0 11:0 1 1024M 0 rom
testdir:$