35

I have a hard disk in my computer that I use to make backups of my data. I do not use this disk otherwise.

How can I stop this disk from spinning once my backup is finished? Also how would I make it spin back up again before the backup takes place later on?

The drive is a regular SATA drive.

slm
  • 369,824
Totor
  • 20,040

6 Answers6

31

Umount the filesystem and then run hdparm -S 1 /dev/sdb to set it to spin down after five seconds (replace /dev/sdb with the actual device for the hard disk). This will minimize the power used and heat generated by the hard disk.

samiam
  • 3,686
  • 3
    With respect to spinning it back up, you shouldn't have to do anything other than access/use the HDD. http://unix.stackexchange.com/questions/10930/spin-up-drive-in-linux/10931#10931 – slm Feb 02 '14 at 06:07
  • 1
    Thanks! How can I restore the default standby timeout value then? I also saw hdparm -Y in the man which seems to set the drive in a deeper sleep mode. Is that not recommended? – Totor Feb 02 '14 at 17:24
  • 2
    This won't always work. For instance Rockstor will do a smart check frequently while using the control panel, regardless of whether the drive is mounted to anything. The best answer is unfortunately to remove it physically... or not use any program that might wake it up, including S.M.A.R.T. monitors. – Ray Foss Feb 21 '18 at 23:32
14

Short lookup in gnome-disk-utility repo code, and:

udisksctl power-off -b /dev/sdX

Works in Ubuntu and Mint. In ArchLinux, /usr/bin/udisksctl is owned by udisks2 package.

Source: Superuser SE answer

Croll
  • 370
  • how to power-on from the terminal? is it possible? @Croll – Akhil Aug 25 '20 at 11:55
  • 1
    udisksctl power-off is mostly used to shut down a device before unplugging/removing it. What I like better with the hdparm -S approach is that it automatically puts the disk in a low-power standby mode after some idle time, and automatically back online again if I try to use it. This is transparent for the user (apart from the waking up delay), and no umount is needed. – Totor Nov 02 '20 at 16:29
  • hdparm -S did not work for me but udisksctl power-off did. My disk was a windows OS that I did not need to access from linux so this solution works perfectly for me. Now my machine does not grind away at night |-o – Timothy C. Quinn Nov 18 '20 at 06:03
  • error no usb device. for usb storage only? but disk seems really stop spinning. and gnome-disks say it in standby mode. (not power off mode, lsblk also list it) – yurenchen Apr 15 '23 at 09:48
11

To further build upon samiam's answer, you can set udev rules to do these things for you.

For this example, you'd have to fill in a file in /etc/udev/rules.d (ideally name it something along the lines of 45-sdX-power.rules to respect the conventions, but it doesn't really matter...), with the following:

ACTION=="add", SUBSYSTEM=="block", KERNEL=="sdX", ATTR{queue/rotational}=="1", RUN+="/path/to/hdparm -S 1 /dev/sdX"

where you will need to fill in sdX and provide the full path to the hdparm binary (which hdparm).

This will automatically stop your drive from spinning after 5 seconds of inactivity whenever your laptop boots.

This is ideal for a dual boot disk (my case), and backup disks you only startup once a week or so (in which case just mounting it before issuing your backup will turn it on and it will be off the rest of the time).

As for hdparm -Y /dev/sdX, it is less useful here as it only stops the disk from spinning once, after which any access to the disk (like mounting it) will re-start it and you will have to issue the command again.

aznashwan
  • 111
1

I want to standby my unused drive. Answers above don't work for me. I create file /etc/rc.local

#!/bin/sh -e
hdparm -y /dev/disk/by-uuid/C40473B40473A856
exit 0

then set execute permissions

sudo chmod +x /etc/rc.local

now my disk standbyed when ubuntu starts

Ilya
  • 11
  • I know the docs have probably not been updated, but -y reads "force an IDE drive to immediately enter low power consumption standby mode"... You could then check the mode by issuing -C to ensure it is in standby. – number9 Jun 17 '21 at 13:05
0

All current answers suggest one variation or other of telling the disk to put itself into an energy-saving standby mode. This has a couple of noted drawbacks, such as disks spinning back up due to some random process talking to the disk, even if the filesystem is unmounted (e.g. SMART).

Also, at least in my particular setup, my HDDs would spin up upon the first I/O request, but they would not spin down again unless I issued the hdparm -S command.


I've had good success removing the device from the block subsystem altogether.

Check out this chapter in Red Hat administration guide, "Removing Devices". Basically boils down to:

  • Remove all processes/uses of a disk. This will vary depending on your environment, but could be:
    • Unmount filesystems on that block device.
    • Export any ZFS storage pools using that block device.
    • Delete/detach the device from any md arrays or lvm groups using it.
  • Determine the [H:C:T:L] tuple that identifies the device. lsscsi works great for this purpose.
  • Remove the device. echo 1 > /sys/class/block/<disk>/device/delete
    • Better yet, use /sys/class/scsi_device/[h:c:t:l]/device/delete which is much less prone to potential destruction than sdX names.
  • Verify that the deivce removal is successful (dmesg).
  • Verify that the device has spun down and ceased activity - should be cold or lukewarm to the touch after 15 minutes.

To attach the disk again issue a re-scan command to the controller the disk is plugged into. If you know the [H:C:T:L] values, simply

echo 'C T L' >/sys/class/scsi_host/hostH/scan

with [H:C:T:L] = [3:0:0:0]:

echo '0 0 0' >/sys/class/scsi_host/host3/scan

Check dmesg and you should see the device appear in /dev. More details in the Adding a Storage Device or Path chapter.

Nubarke
  • 321
0

Just found hd-idle (https://github.com/adelolmo/hd-idle), it is amazing for this. To do a quick test: sudo hd-idle sda to spin down /dev/sda

gnome-disks from gnome-disk-utility also has options for spindown

Andrew
  • 181