How to turn off one of SATA HDDs installed in the computer to save power?

I have bought an SSD to replace my HDD to make my Xubuntu 16.10 laptop faster but there is hardly too much of space on it so I've decided to keep the old big HDD as a second drive replacing the DVD+RW drive with it.

I am going to store big, rarely needed files like distros, backups, movies etc on the HDD, so I am not going to need access to it 100% of time.

Is there a way to power it off to save the battery when I am not using it?


Solution 1:

What you're looking for is the hdparm utility.

It allows you to control your hard drives' power settings, apart from benchmarking and other stuff.

With hdparm -y /dev/sdX you put the disk into standby mode. This way, whenever you access the disk, it should automatically wake up and work back again.

There's an even deeper resting mode, which can be set with -Y instead of -y, but you may need to restart your computer in order to make the HDD work again, depending on the device.

Since manually having to put it to sleep is a bit of a hassle, you can set a timer to do it after a specific amount of time with the -S option.

From ArchWiki:

A device which is rarely needed can be put to sleep directly at the end of the boot process. This does not work with the above udev rule because it happens too early. In order to issue the command when the boot is completed, just create a systemd service.

/etc/systemd/system/hdparm.service

[Unit]
Description=hdparm sleep

[Service]
Type=oneshot
ExecStart=/usr/bin/hdparm -q -S 120 -y /dev/sdb

[Install]
WantedBy=multi-user.target

Then enable it.