如何在 Ubuntu 中关闭硬盘?

Ahm*_*lal 31 dual-boot usb-drive power-management hard-drive external-hdd

我正在从外部硬盘驱动器运行 Kubuntu。我的内置硬盘上装有 Windows。我不想在 Ubuntu 上使用它,并且想关闭它以减少热量以及消耗更少的电池。我认为降低硬盘驱动器对我来说不是一个选择。因为,它会磨损硬盘驱动器,我不打算在 HDD 上花钱 :)

ear*_*Lon 34

sudo hdparm -Y /dev/sdX
Run Code Online (Sandbox Code Playgroud)

其中/dev/sdX是您要关闭的设备。您还可以运行sudo blkid以确定设备的“指纹”(UUID),这将使您能够更可靠地控制正在关闭的设备。

在这种情况下,您将运行:

sudo hdparm -Y /dev/disk/by-uuid/DEVICE-IDENT-HERE
Run Code Online (Sandbox Code Playgroud)

男人 hdparm

   -Y     Force  an  IDE  drive  to  immediately  enter  the  lowest power
          consumption sleep mode, causing it to shut down  completely.   A
          hard  or soft reset is required before the drive can be accessed
          again (the Linux IDE driver will automatically handle issuing  a
          reset  if/when  needed).   The  current power mode status can be
          checked using the -C option.
Run Code Online (Sandbox Code Playgroud)


Tom*_*liy 11

您可以使用以下内容(这里sdc是相应的感兴趣块设备的名称):

sync
echo 1 > /sys/block/sdc/device/delete
Run Code Online (Sandbox Code Playgroud)

或(来自非 root 用户):

sync
echo 1 | sudo tee /sys/block/sdc/device/delete
Run Code Online (Sandbox Code Playgroud)

  • 我认为使用 `sudo` 也是可行的:`sudo bash -c 'echo 1 > /sys/block/sdc/device/delete'`。 (4认同)
  • +1 这按预期工作,以防止安装程序根本检测到硬盘驱动器。必须以 root 身份运行命令(不是 sudo)。 (3认同)

小智 9

您可能已经udisks2安装了该软件包;您可以使用

udisksctl power-off -b /dev/sdX
Run Code Online (Sandbox Code Playgroud)

/dev/sdX您要关闭的设备在哪里。

udisksctl手册页(版本 2.7.6):

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.
Run Code Online (Sandbox Code Playgroud)