Tip: letting your ZFS pool sleep

published Dec 07, 2011, last modified Jun 26, 2013

You may not want to keep those disks rotating all day long, if they're not in use.

If you're using ZFS on Linux as part of a home NAS solution, you might want to make your disks sleep when they are not in use.

Here are the steps:

Keep cron jobs in check

Check your crontab, /etc/cron.hourly and /etc/cron.d directories. Neutralize or modify any cron jobs that take place more than one time a day, so they happen at the same time.

Check for daemons that do periodic scans

Make them defer their scans for later, or configure them so they scan all together at the same time.

Disable unnecessary daemons

Self-explanatory.

Mount all your filesystems noatime

For regular filesystems, you can set mount option noatime in fstab. For ZFS, a zfs set atime=off poolname command will accomplish the same.

Find files modified in the last day or so

Now that you have no reason to worry about access time updates causing disk writes, you can issue this command:

find / -mtime -1

This find command will give you an idea of what files have been modified in the last day. Check for on-disk directories or files that are modified recently (in other words, ignore anything coming from pseudo-filesystems like /dev, /proc or /sys). We'll be moving them to flash storage.

Relocate directories and files to non-rotating media

Get a cheap USB drive (does not need to be big) and format it as ext4 (technically, you could set up another ZFS pool there too). Then, set it to be mounted in /var/volatile on your fstab.

You can now move directories that contain frequently modified files there. After you're done moving those directories, you can symlink them from their original location. So, for example, you would move /var/log to /var/volatile/log, then creating a symbolic link to /var/volatile/log named /var/log.

At this point, it would be wise to make a cron job to nightly back the contents of this USB drive up (think rsync -a) to a backups directory somewhere in your pool.

OK. If you've moved the most frequently modified files to /var/volatile, your disks will be idle unless you are actually using your file server. Now it's time to take advantage of that idleness.

Finally, tell your disks to power off when they're idle

In your /etc/rc.d/rc.local file, you can add one of these commands for each one of your rotating disks (sda, sdb...):

hdparm -S 120 /dev/sda

The -S 120 parameter tells the disk to go to sleep every ten minutes. So, if nothing has read or written to the disk for ten minutes, the disk will enter a non-rotating, very low-power mode.