29

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.

27

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.

3
  • 3
    With respect to spinning it back up, you shouldn't have to do anything other than access/use the HDD. unix.stackexchange.com/questions/10930/spin-up-drive-in-linux/…
    – slm
    Feb 2 '14 at 6:07
  • 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 2 '14 at 17:24
  • 1
    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
12

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

3
  • how to power-on from the terminal? is it possible? @Croll
    – Akhil
    Aug 25 '20 at 11:55
  • 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 2 '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 Nov 18 '20 at 6:03
10

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.

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

1
  • 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 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.