将外部硬盘设置为关机模式

将外部硬盘设置为关机模式

我用udisks --detach /dev/sdb它来安全移除硬盘。此命令的作用类似于右键单击外部硬盘时 nautilus 中的安全移除菜单。问题是,2 秒后硬盘会自动安装,然后 nautilus 窗口会弹出。

我知道udev如何管理这些内核事件,所以我搜索了一个命令来监视这些事件。这是 的输出udevadm monitor --udev

UDEV  [67744.241650] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host7/target7:0:0/7:0:0:0/bsg/7:0:0:0 (bsg)
UDEV  [67744.242272] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host7/target7:0:0/7:0:0:0/scsi_device/7:0:0:0 (scsi_device)
UDEV  [67744.242308] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host7/target7:0:0/7:0:0:0/scsi_disk/7:0:0:0 (scsi_disk)
UDEV  [67744.243365] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host7/target7:0:0/7:0:0:0/scsi_generic/sg2 (scsi_generic)
UDEV  [67744.243399] remove   /devices/virtual/bdi/8:16 (bdi)
UDEV  [67744.243545] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host7/target7:0:0/7:0:0:0/block/sdb/sdb1 (block)
UDEV  [67744.248425] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host7/target7:0:0/7:0:0:1/bsg/7:0:0:1 (bsg)
UDEV  [67744.248520] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host7/target7:0:0/7:0:0:0/block/sdb (block)
UDEV  [67744.248566] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host7/target7:0:0/7:0:0:0 (scsi)
UDEV  [67744.248596] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host7/target7:0:0/7:0:0:1/enclosure/7:0:0:1 (enclosure)
UDEV  [67744.248625] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host7/target7:0:0/7:0:0:1/scsi_device/7:0:0:1 (scsi_device)
UDEV  [67744.248660] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host7/target7:0:0/7:0:0:1/scsi_generic/sg3 (scsi_generic)
UDEV  [67744.248689] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host7/scsi_host/host7 (scsi_host)
UDEV  [67744.252526] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host7/target7:0:0/7:0:0:1 (scsi)
UDEV  [67744.252563] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host7/target7:0:0 (scsi)
UDEV  [67744.252594] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host7 (scsi)
UDEV  [67744.317378] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0 (usb)
UDEV  [67744.339889] remove   /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3 (usb)
UDEV  [67751.203840] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3 (usb)
UDEV  [67751.205913] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0 (usb)
UDEV  [67751.207203] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host8 (scsi)
UDEV  [67751.208287] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host8/scsi_host/host8 (scsi_host)
UDEV  [67752.183035] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host8/target8:0:0 (scsi)
UDEV  [67752.183988] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host8/target8:0:0/8:0:0:0 (scsi)
UDEV  [67752.184022] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host8/target8:0:0/8:0:0:1 (scsi)
UDEV  [67752.184944] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host8/target8:0:0/8:0:0:0/scsi_device/8:0:0:0 (scsi_device)
UDEV  [67752.184959] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host8/target8:0:0/8:0:0:1/scsi_device/8:0:0:1 (scsi_device)
UDEV  [67752.185348] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host8/target8:0:0/8:0:0:0/scsi_generic/sg2 (scsi_generic)
UDEV  [67752.185365] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host8/target8:0:0/8:0:0:1/scsi_generic/sg3 (scsi_generic)
UDEV  [67752.185381] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host8/target8:0:0/8:0:0:0/bsg/8:0:0:0 (bsg)
UDEV  [67752.185392] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/host8/target8:0:0/8:0:0:0/scsi_disk/8:0:0:0 (scsi_disk)
UDEV  [67755.138374] add      /devices/virtual/bdi/8:16 (bdi)
UDEV  [67755.140810] add      /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3/2-1.

如您所见,HDD 从系统中分离出来,然后又返回到系统中。在我移除它之后,内核添加了此设备。

我不想让 HDD 回来。我想将外部 HDD 设置为关机模式。

任何命令、脚本和想法都值得赞赏。

答案1

USB 设备应该是即插即用的。因此,拔下后它会再次连接,除非您拔掉插头。这就是即插即用的整个理念,不是吗?

如果您不使用 HDD,则应卸载 /dev/sdb。设备本身仍可检测到,但由于未安装,因此不会发生任何 IO 操作。

相关内容