首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在断开之前优雅地关闭USB磁盘驱动器

在断开之前优雅地关闭USB磁盘驱动器
EN

Unix & Linux用户
提问于 2018-05-18 13:41:23
回答 1查看 2.5K关注 0票数 6

使用Fedora 27,当断开外部USB磁盘驱动器时,日志记录行如下所示:

代码语言:javascript
复制
May 07 22:29:11 usb 2-3.1: USB disconnect, device number 23
May 07 22:29:11 sd 3:0:0:0: [sdb] Synchronizing SCSI cache
May 07 22:29:11 sd 3:0:0:0: [sdb] Synchronize Cache(10) failed:
                            Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK

一个人该怎么做?

为什么系统/内核在驱动器断开后尝试同步缓存?

是否有可能在断开之前优雅地关闭USB磁盘?例如,使用发出同步缓存命令的命令,然后旋转驱动器。

这也许还会减少驱动器上的机械应力,因为旋转盘的突然功率损失并不一定是最佳的。

编辑:eject /dev/sdb是无效的,即上面的内核消息仍然显示在设备拔出上,磁盘继续旋转。相反,eject命令生成以下内核日志消息:

代码语言:javascript
复制
May 18 17:26:06  ldm_validate_partition_table(): Disk read failed.
May 18 17:26:06  Dev sdb: unable to read RDB block 0
May 18 17:26:06   sdb: unable to read partition table
May 18 17:26:06  ldm_validate_partition_table(): Disk read failed.
May 18 17:26:06  Dev sdb: unable to read RDB block 0
May 18 17:26:06   sdb: unable to read partition table

编辑:用udisksctl power-off --block-device /dev/sdb为磁盘提供电源确实有效:

代码语言:javascript
复制
May 19 08:08:21  udisksd[9447]: Successfully sent SCSI command SYNCHRONIZE CACHE 
                                to /dev/sdb
May 19 08:08:21  udisksd[9447]: Successfully sent SCSI command START STOP UNIT
                                to /dev/sdb
May 19 08:08:21  kernel: sd 3:0:0:0: [sdb] Synchronizing SCSI cache
May 19 08:08:21  udisksd[9447]: Powered off /dev/sdb - successfully wrote
         to sysfs path /sys/devices/pci0000:00/0000:00:14.0/usb2/2-3/2-3.1/remove
May 19 08:08:21  kernel: usb 2-3.1: USB disconnect, device number 60

实际上,磁盘就会关闭。

EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2018-05-19 00:05:26

使用udisksctl关闭驱动器:

代码语言:javascript
复制
   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.

因此,例如。

代码语言:javascript
复制
udisksctl power-off --block-device /dev/sdb

您可以以常规用户的身份运行该命令,不需要根访问。

如果您喜欢gui,gnome disks有一个按钮来“关闭这个磁盘”。

票数 4
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/444611

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档