You are not logged in.

#1 2018-09-18 02:54:44

chr0mag
Member
From: Vancouver, Canada
Registered: 2017-02-02
Posts: 94

[Solved] Can't spin down HDD when filesystem mounted

I have a LUKS encrypted USB 3.0 drive connected to a headless Arch system. The drive is used only periodically for backups so I'd like to spin down the disk when its idle, which is >95% of the time.

I'm using hd-idle to spin the disk down and this works fine. The problem is that the disk gets immediately woken up if its mounted. It doesn't seem to matter whether the disk is mounted manually or through an entry in /etc/fstab. The disk will stay asleep if its decrypted (ie. entry exists in /dev/mapper) but not mounted.

Auto-mounting with systemd (https://wiki.archlinux.org/index.php/Fs … th_systemd) might be a solution. I could set an idle timeout on the mount and systemd would automatically unmount which would theoretically allow the disk to spin down.

However, I'm wondering if there is a better way? I've had this working on an OpenWrt system and could spin down the disk just fine even if mounted, so I suspect there is a simpler solution that I'm not seeing.

Last edited by chr0mag (2018-09-26 22:36:52)

Offline

#2 2018-09-19 13:00:44

The Loko
Member
From: Spain
Registered: 2014-07-23
Posts: 103

Re: [Solved] Can't spin down HDD when filesystem mounted

Does the disk spin down when mounted and idle after being woken up?

You can check with hdparm the power management values on the disk, and try to specify the standby time with it.

Offline

#3 2018-09-19 16:26:38

ua4000
Member
Registered: 2015-10-14
Posts: 566

Re: [Solved] Can't spin down HDD when filesystem mounted

Which filesystem ? Which mount options ? Please post your fstab and mount output.
Are there programs, scripts, cron jobs running, who maybe access the drive in read mode ? Maybe the smartd ? Some indexing job ?

Offline

#4 2018-09-19 17:17:19

chr0mag
Member
From: Vancouver, Canada
Registered: 2017-02-02
Posts: 94

Re: [Solved] Can't spin down HDD when filesystem mounted

The Loko wrote:

Does the disk spin down when mounted and idle after being woken up?

Its the fact that the disk is mounted that makes it unable to be put to sleep. It seems its never deemed idle when mounted. When I force it to spin down (hd-idle -t /dev/sdX) it immediately spins up again. When the disk is not mounted, it spins down and stays asleep as expected.

The Loko wrote:

You can check with hdparm the power management values on the disk, and try to specify the standby time with it.

I'd be surprised if spinning down the disk a different way would help, but I will look into this.

Offline

#5 2018-09-19 17:28:54

chr0mag
Member
From: Vancouver, Canada
Registered: 2017-02-02
Posts: 94

Re: [Solved] Can't spin down HDD when filesystem mounted

ua4000 wrote:

Which filesystem ? Which mount options ? Please post your fstab and mount output.

/etc/crypttab

nas	UUID=e9d22d09-6b8c-47f9-b199-6d12809b990b	/path/to/keyfile luks,noauto,nofail,x-systemd.device-timeout=5

/etc/fstab (relevant line only)

/dev/mapper/nas	/mnt/nas	ext4	noauto,x-systemd.automount,x-systemd.idle-timeout=5min,nofail,x-systemd.device-timeout=20	0 2

mount

proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sys on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
dev on /dev type devtmpfs (rw,nosuid,relatime,size=2006412k,nr_inodes=501603,mode=755)
run on /run type tmpfs (rw,nosuid,nodev,relatime,mode=755)
/dev/sda1 on / type ext4 (rw,relatime,data=ordered)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup2 on /sys/fs/cgroup/unified type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/rdma type cgroup (rw,nosuid,nodev,noexec,relatime,rdma)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=26,pgrp=1,timeout=0,minproto=5,maxproto=5,direct)
systemd-1 on /mnt/nas type autofs (rw,relatime,fd=27,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
mqueue on /dev/mqueue type mqueue (rw,relatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev)
configfs on /sys/kernel/config type configfs (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=402564k,mode=700,uid=1000,gid=1000)
/dev/mapper/nas on /mnt/nas type ext4 (rw,relatime,data=ordered,x-systemd.automount)
ua4000 wrote:

Are there programs, scripts, cron jobs running, who maybe access the drive in read mode ? Maybe the smartd ? Some indexing job ?

I don't think so. Running lsof | grep /mnt/nas returns nothing. Is there better way to confirm this?

As mentioned, it seems that its just the fact that its mounted that makes it impossible to idle the disk.

Offline

#6 2018-09-19 17:31:48

chr0mag
Member
From: Vancouver, Canada
Registered: 2017-02-02
Posts: 94

Re: [Solved] Can't spin down HDD when filesystem mounted

chr0mag wrote:

Auto-mounting with systemd (https://wiki.archlinux.org/index.php/Fs … th_systemd) might be a solution. I could set an idle timeout on the mount and systemd would automatically unmount which would theoretically allow the disk to spin down.

For the record, this works -- with the /etc/crypttab and /etc/fstab configured as above.

The question remains though, is it possible to spin down a disk while mounted?

Offline

#7 2018-09-19 17:59:29

ua4000
Member
Registered: 2015-10-14
Posts: 566

Re: [Solved] Can't spin down HDD when filesystem mounted

chr0mag wrote:

/dev/mapper/nas on /mnt/nas type ext4 (rw,relatime,data=ordered,x-systemd.automount)

To minimze writes to the disk replace relatime (default) with noatime in fstab - see "atime" section  in https://wiki.archlinux.org/index.php/fstab
Maybe this helps.

Offline

#8 2018-09-19 18:58:05

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,839

Re: [Solved] Can't spin down HDD when filesystem mounted

"relatime,lazytime" is more robust (there're few but there *are* programs that rely on atime)

In general you can spin down a mounted device, but of course as soon as it's mounted, some über-smart indexer or so might access it.
You could use inotifywait to see whether something accesses the mounted path (while spun down)

Online

#9 2018-09-26 22:36:22

chr0mag
Member
From: Vancouver, Canada
Registered: 2017-02-02
Posts: 94

Re: [Solved] Can't spin down HDD when filesystem mounted

ua4000 wrote:

To minimze writes to the disk replace relatime (default) with noatime in fstab - see "atime" section  in https://wiki.archlinux.org/index.php/fstab
Maybe this helps.

seth wrote:

"relatime,lazytime" is more robust (there're few but there *are* programs that rely on atime)

Thanks for the atime pointers. Neither noatime nor lazytime stopped my disk from being woken up but I've settled on lazytime in the event I end up installing something that still uses atime. My fstab entry now looks like this:

/dev/mapper/nas	/mnt/nas	ext4	noauto,lazytime,x-systemd.automount,x-systemd.idle-timeout=5min,nofail,x-systemd.device-timeout=20	0 2
seth wrote:

In general you can spin down a mounted device, but of course as soon as it's mounted, some über-smart indexer or so might access it.
You could use inotifywait to see whether something accesses the mounted path (while spun down)

After revisiting this today, I no longer have the issue and am able to spin down my drive and have it stay asleep even if mounted. The notable change in software since my original post is that I've removed nfs-utils and its dependencies. There are quite a few services that get started when you start nfs-server.service so I suspect one of these was the culprit.  It is still odd that I didn't have this issue with OpenWrt even with NFS running, but there are likely significant differences in the NFS versions being used in OpenWrt and Arch. NFS is overkill for my needs anyway; I can get what I need from rsync + ssh.

Offline

Board footer

Powered by FluxBB