# [Solved] HDD spins up on shutdown

## avx

So I've got two disks in my Macbook, an SSD as sda hosting the OS and a normal drive as sdb for bigger data. /dev/sdb isn't used often, thus I'm putting it to sleep with `hdparm -Y`.

Now, when I turn of the system and the disk is sleeping, it first spins up and as soon as it's accessable, the system powers down completly. That surely ain't perfect for the health of the disk and it slows down shutdown for about 3s.

So I'm wondering, is this just a misconfiguration on my part and can I fix it? Running ~amd64 with openrc and the disk usually isn't even mounted.

----------

## PaulBredbury

This seems to work, in a shutdown script:

```
# http://superuser.com/questions/173622/hdparm-checking-if-a-drive-is-spun-down

smartctl -i -n standby -q silent /dev/sdb

if [[ $? -eq 2 ]] ; then

    # Don't pointlessly start up the drive during shutdown

    # https://bbs.archlinux.org/viewtopic.php?id=61301

    # find /sys -name manage_start_stop

    # /usr/src/linux/drivers/scsi/sd.c - manage_start_stop

    echo 0 > "/sys/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/scsi_disk/1:0:0:0/manage_start_stop"

fi
```

However, the drive must be put to sleep using hdparm -y (lower-case) rather than -Y, otherwise smartctl would wake it up during the querying.

----------

## avx

Thanks, but since -Y saves noticable more power than -y, what do you think about this?

 */etc/local.d/001_unmanage_sdb_startstop.start wrote:*   

> #!/bin/sh
> 
> # by default, the kernel wants to manage drives spinning up/down,
> 
> # which produces the odd situation of spinning a disk up right before
> ...

 

 */etc/local.d/002_put_sdb_to_sleep.start wrote:*   

> #!/bin/sh
> 
> # the 2nd (/dev/sdb) drive is a classical HDD which is only used
> 
> # every so often. To save some power, put it to sleep right at
> ...

 

In my theory, the disk will be put to deep-sleep right of the start, but when it ever gets accessed goes to normal idle after 5min of inactivity.

Not yet tested, but should work I guess?!

Regarding the `find`-command, is there an easy way to translate /dev/sdX to it's path in /sys? I'd like to be the script somewhat portable and only give it a few /dev/sdX entries, depending on the number of disks per machine and which shut be put to sleep.

----------

## PaulBredbury

I suppose that should be OK, as long as:

The shutdown initscript runs "sync", and unmounts partitions.

The hard drive isn't stupid, or on a stupid caching controller which caches when it shouldn't.

But I'm only going to do this with the one drive  :Wink: 

----------

## avx

 *PaulBredbury wrote:*   

> The shutdown initscript runs "sync", and unmounts partitions.

 Am I reading this correct, as it's not guaranteed that all data gets written to disk before it enters sleep-mode?

Anyway, so far it works, thanks for your help.

----------

