ZFS: basic usage
Learn all the essential commands to manage ZFS filesystems.
Table of Contents
- Install ZFS utilities
- Create a pool
- Add disks to an existing pool
- Create a dataset
- Set a quota for a dataset
- Create a snapshot of a dataset or pool
- List snapshots
- Roll a dataset or pool back to snapshot
- Restore a file from snapshot
- Export a snapshot
- Remove a snapshot
- Destroy a dataset
- Destroy a pool
Install ZFS utilities
You can find out how to install required packages in these links:
Ubuntu: you can install them by typing
apt install zfsutils-linux as root or with sudo.
Arch Linux: check https://wiki.archlinux.org/title/ZFS#Automatic_Start about enabling services to mount ZFS at boot.
You may need to manually enable
zfs kernel module (
/sbin/modprobe zfs) and enable the module at boot by creating a
.conf file inside
/etc/modules.load.d/ and adding
Create a pool
zpool create [<options>] <pool name> [mirror|raidz|raidz2|raidz3] <device name> [<device name> ...] # zpool create p1 virtio-pci-0000:08:00.0 # zpool create p1 mirror virtio-pci-0000:08:00.0 virtio-pci-0000:09:00.0
mirroris similar to RAID1 (1:1 redundancy),
raidzgives 1 disk of parity (with a minimum of 3 disks),
raidz22 disks of parity (with a minimum of 4 disks), and so on.
<device-name>can be device IDs (check
ls -l /dev/disk/by-id/), device paths (check
ls -l /dev/disk/by-path/) or device names like
sdb1, etc. (not recommended because the naming could change on every start). You can use GPT partition labels as well.
- You can add the option
-m <mount-point>to specify a mount point (by default creates a mount point inside
/). You can find more
Add disks to an existing pool
zpool add <pool name> <device-name> # zpool add p1 virtio-pci-0000:09:00.0
Create a dataset
Datasets are like partitions. You can create filesystems inside them.
zfs create <pool name>/<dataset name> # zfs create p1/main
Set a quota for a dataset
You can define disk quotas (it’s like defining the partition size) on a dataset.
zfs set quota=<size> <pool name>/<dataset name> # zfs set quota=20G p1/main
Create a snapshot of a dataset or pool
zfs snapshot <pool name>/<dataset name>@<tag> # zfs snapshot p1/[email protected]
- You can use any name for the
zfs list -t snapshot
Roll a dataset or pool back to snapshot
zfs rollback <pool name>/<dataset name>@<tag> # zfs rollback p1/[email protected]
Restore a file from snapshot
Snapshots are located under
<pool mount point>/<dataset>/.zfs/snapshot/ (or
<pool mount point>/.zfs/snapshot/). First, check if that folder is visible, if not, type:
zfs set snapdir=visible <pool>/<dataset name> # or zfs set snapdir=visible <pool>
You can copy a file from the snapshot to restore it.
cp /p1/main/.zfs/snapshot/2021-11-01/debian.iso /p1/main/
Export a snapshot
Remove a snapshot
zfs destroy <pool name>/<dataset name>@<tag>
Destroy a dataset
zfs destroy <pool name>/<dataset name> # zfs destroy p1/main
Destroy a pool
zpool destroy <pool name> # zpool destroy p1
- You will need to add
-rif there are snapshots.
In Debian/Ubuntu systems, you can use
dpkg-reconfigureto reconfigure an installed package using intuitive dialogs. I will show you how to use this command to change some system settings.
If you have a scanned PDF and you want to be able to search and copy text from it, in this tutorial I will show you how to do it.
If you want to do X11 forwarding from your container to your host, you can type these simple commands.
If you don’t have a Graphical User Interface (GUI) on your Linux device, or you need a simple text-based web browser, I will show you a couple of great programs.
A comprehensive list of Linux-related websites sorted by categories.