Linux HDD Sleep

Hi everyone,

I have a Debian server that I’m using for backup purposes. I have an external drive connected to the server that is only used for about 30-60 minutes a day. I want to make it sleep and stop spinning at other times to save energy and reduce wear and tear.

I’ve tried using the hdparm command to achieve this, but it doesn’t seem to be working. Additionally, I’m looking for a command that will give me the current status of the drivers, but I haven’t found anything that provides accurate results.

Does anyone have any tips on how to accomplish this? Thanks in advance.

1 Like

Nice to see questions on here. I’m always scanning for unanswered stuff.

For managing your external drive’s sleep settings on a Debian server, using hdparm (nice wiki entry) is usually the right approach, but it can be a bit tricky. If hdparm isn’t working as expected, ensure that you’re using it with the correct parameters and that the drive itself supports the commands you’re trying to use.

To set your drive to enter standby mode after a period of inactivity, you can use:

hdparm -S [value] /dev/sdX

Here, [value] is the time in seconds you want the drive to wait after the last access before going to sleep, and /dev/sdX is your drive. The value is encoded in a special way, so check man hdparm for the exact value to use.

If you’re having trouble with hdparm or if it doesn’t seem to work, it might be that your external drive doesn’t fully support the commands, or it might require a firmware update. Also, make sure you’re running hdparm with root.

For checking the status of your drive, smartctl from the smartmontools package can be really handy. Install it if you haven’t yet, and then you can use:

smartctl -a /dev/sdX

This command will give you a detailed report of your drive’s status, including power-on hours, error rates, and more. It’s a great way to get info about the health and status of your drives.

Keep us posted!

great reply and you can do also the following: add a cron in the /etc/fstab and it will automatically run. If you dont know how to configure a cron, then you can generate a cron tab at website.

alles gut,

Are you saying to add a line for cron scheduled jobs in the system config file for mounting drives and partitions?

Sorry. Can you clarify this. I’ve not heard of this before.

Unless I’m missing something this will prevent your system from booting!

@devdev yes you can add the drive mount in the etc/fstab and it will mount automatically. this will not prevent the system from booting. Check out this 5.9.5. Mounting File Systems Automatically with /etc/fstab Red Hat Enterprise Linux 4 | Red Hat Customer Portal. You can mount the drives. The only thing that can prevent your system booting is that you dont mess with the grub loader. So before you mount the drives please check that they are formatted using the fdisk and also that they are mount enabled.

alles gut,

Thanks for the answers!

I think I’ve solved my own problem. The cause of my problem that I was using hdparm with partition, not the disk itself. I also totally miss the following information on the documentation:

-B 	Set the Advanced Power Management feature. 
    Possible values are between 1 and 255, low values mean 
    more aggressive power management and higher values
    mean better performance. Values from 1 to 127 permit spin-
    down, whereas values from 128 to 254 do not. A value of 
    255 completely disables the feature.

The previous command was like this:

hdparm -B 150 -S 36 /dev/sdb1

I changed it with this:

hdparm -B 120 -S 36 /dev/sdb

And now, it is working as expected. I also found a command that shows the current state of the drivers:

$ ps aux | grep hd-idle | grep -v grep | cut -c 66- ; for f in [a-d] ; do hdparm -C /dev/sd$f | grep -v "^$" ; done

 drive state is:  standby
 drive state is:  standby
1 Like

In case, another person encounters a challenge such as this. These are additional options you can explore alongside the solution proffered here.

  1. Check if there is an issue with USB enclosures: Some enclosures tend to override the settings of the drive. Be sure to check if the USB enclosure supports power management.
  2. Check Kernel Modules: This is actually very rare but it happens. There are possibilities of certain kernels meddling with the power management of a disk. You should check if relevant modules are loaded.

If you want to power off the drive so it is safe to remove power
from be sure you are not in it’s folder. Do a “cd /” then umount
it using “umount DEVICENAME” like “umount /dev/sdc1” then
power it off using “udisksctl power-off -b DEVICENAME”. Note
that not all external drives/drive cases support this. You will see
this by an error message.

You may need to install “sudo apt get install udisks2”.

1 Like