Short Reference on ZFS Commands

Warning

These are my very short notes about using ZFS. Be sure check manpages zfs(8) and zpool(8) and consult additional documentation in case anything is unclear. Commands may need to be changed for your systems etc.

Installation

For unattended processes it is recommended to setup zfs-dkms first and only afterwards do zfsutils-linux because otherwise the utils may want to start some services while the modules are not loaded yet. All of the packages are in Debian contrib repository.

# In case it works
aptitude install zfs-dkms zfs-zed zfsutils-linux

# Safe for automation (to be verified/from memory)
apt-get install zfs-dkms
modprobe zfs
apt-get install zfsutils-linux

On live systems and other systems which are not using ZFS yet, issue

modprobe zfs

before using any of the ZFS commands.

Introspection

At any time, consult the status of ZFS as follows:

zpool status      # list pools and report degraded info
zpool list        # list pools short
zpool iostat 10   # display I/O stats every 10 sec.
zfs list          # list file systems on pools

Creating ZFS Pools and Volumes

Create a Pool

# zpool create ... <pool> mirror <dev0> <dev1>
zpool create -m none -o ashift=12 masysmahdd6t mirror \
                    ata-TOSHIBA_... ata-TOSHIBA_...
-m none
Avoid creating a mountpoint for the pool as-is. It is recommended to create zfs inside the pool instead!
-o ashift=12
Recommended setting for advanced format devices (4K physical sectors, 212 = 4096). Recommended value for Intel P4510 SSDs is also 12. See https://wiki.lustre.org/Optimizing_Performance_of_SSDs_and_Advanced_Format_Drives and https://zfsonlinux.topicbox.com/groups/zfs-discuss/T9839aba9fccf2954-M602d366a6f37bcc2f2c6523b/zfs-optimisation-for-nvme-and-shared-hosting-scenario

Create a File System

# zfs create ... <pool>/<name>
zfs create -o reservation=300g -o quota=400g -o mountpoint=/data \
                        masysmahdd6t/data
-o reservation=300g
Attempt to guarantee that this FS can hold 300 GiB (?) of data.
-o quota=400g
Cap the size of this FS. This is what df -h will display as “free”.
-o mountpoint=/data
Mount this ZFS. Note: /etc/fstab is not used and the mountpoint directory is created if not already existent.

ZFS for Swap?

Using a ZFS volume for swap is not directly advised against by the manpage, but may result in system lockups, see https://github.com/openzfs/zfs/issues/7734.

Current idea is to use MDADM for swap which loses the ability to use whole devices rather than partitions but may otherwise be the most practical variant.

Regular Maintenance

Run zfs scrubs. Like mdadm RAID resync?

# zpool scrub <pool>
zpool scrub masysmahdd6t

Follow the progress with zpool status.

Move ZFS to Other System

Before removing disks from previous server.

# zpool export <pool>
zpool export masysmahdd6t

After inserting disks into new server.

# zpool import ... [pool]
zpool import -d /dev/disk/by-id masysmahdd6t

If pool name is left out, it will display the pools available for importing.

Replace a Failed Disk

(!) WARNING: This has not been verified yet (!) Quoted command from https://www.unixsheikh.com/articles/battle-testing-data-integrity-verification-with-zfs-btrfs-and-mdadm-dm-integrity.html:

# zpool replace <pool-name> <failed-disk-id> <new-disk-id>
zpool replace pool1 ata-ST31000340NS_9QJ0EQ1V ata-ST31000340NS_9QJ0DVN2

As per zpool replace manpage, one could als replace a device “by itself” after failure:

zpool replace pool1 sda sda

This may also be the command to use in case of “failure” after an intermittent drive connection issue?

Note that the ZFS term for resync in case of new/replaced disks is “resilver”.


Ma_Sys.ma Website 5 (1.0.0) – no Flash, no JavaScript, no Webfont, no Copy Protection, no Mobile First. No bullshit. No GUI needed. Works with any browser.

Created: 2020/10/24 23:56:40 | Revised: 2020/10/25 00:49:31 | Tags: zfs, linux, kb | Version: 1.0.0 | SRC (Pandoc MD) | GPL

Copyright (c) 2020 Ma_Sys.ma. For further info send an e-mail to Ma_Sys.ma@web.de.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.