256 lines
9.2 KiB
Markdown
256 lines
9.2 KiB
Markdown
## ZFS
|
||
|
||
### Update / Upgrade
|
||
|
||
```bash
|
||
sudo apt update && sudo apt upgrade -y
|
||
```
|
||
|
||
### Enable the contrib repository
|
||
|
||
```bash
|
||
sudo nano /etc/apt/sources.list
|
||
```
|
||
|
||
```bash
|
||
#deb cdrom:[Debian GNU/Linux 13.3.0 _Trixie_ - Official amd64 NETINST with firmware 20260110-10:59]/ trixie contrib main non-free-firmware
|
||
|
||
deb http://deb.debian.org/debian/ trixie main contrib non-free-firmware
|
||
deb-src http://deb.debian.org/debian/ trixie main contrib non-free-firmware
|
||
|
||
deb http://security.debian.org/debian-security trixie-security main contrib non-free-firmware
|
||
deb-src http://security.debian.org/debian-security trixie-security main contrib non-free-firmware
|
||
|
||
# trixie-updates, to get updates before a point release is made;
|
||
# see https://www.debian.org/doc/manuals/debian-reference/ch02.en.html#_updates_and_backports
|
||
deb http://deb.debian.org/debian/ trixie-updates main contrib non-free-firmware
|
||
deb-src http://deb.debian.org/debian/ trixie-updates main contrib non-free-firmware
|
||
|
||
# This system was installed using removable media other than
|
||
# CD/DVD/BD (e.g. USB stick, SD card, ISO image file).
|
||
# The matching "deb cdrom" entries were disabled at the end
|
||
# of the installation process.
|
||
# For information about how to configure apt package sources,
|
||
# see the sources.list(5) manual.
|
||
```
|
||
|
||
### Refresh package index and install ZFS
|
||
|
||
```bash
|
||
sudo apt update && sudo apt install linux-headers-$(uname -r) zfsutils-linux -y
|
||
|
||
sudo modprobe zfs
|
||
|
||
sudo reboot
|
||
```
|
||
|
||
### Verify ZFS Installation
|
||
|
||
```bash
|
||
lsmod | grep zfs
|
||
zfs --version
|
||
zpool --version
|
||
```
|
||
|
||
### Creating and Using a ZFS Pool & Datasets
|
||
Once ZFS is installed, you can create pools (zpools) and datasets. Below is a typical example.
|
||
|
||
#### Identify disks / partitions
|
||
List available block devices:
|
||
|
||
```bash
|
||
lsblk
|
||
sudo blkid
|
||
```
|
||
|
||
Create a mirrored pool named *tank* using /dev/sda and /dev/sdb:
|
||
|
||
```bash
|
||
sudo zpool create \
|
||
-o ashift=12 \
|
||
-o autotrim=on \
|
||
tank mirror /dev/sda /dev/sdb
|
||
```
|
||
|
||
Explanation:
|
||
|
||
ashift=12 sets a 4KiB sector alignment (useful for modern drives/SSDs).
|
||
|
||
autotrim=on enables automatic trimming (on SSDs).
|
||
|
||
mirror defines redundancy — you could also use raidz, raidz2, etc.
|
||
|
||
You can also check pool properties:
|
||
|
||
```bash
|
||
sudo zpool get all tank
|
||
```
|
||
|
||
Within the pool, create datasets:
|
||
|
||
```bash
|
||
sudo zfs create tank/cloud
|
||
# sudo zfs create tank/data
|
||
# sudo zfs create tank/data/projects
|
||
# sudo zfs create tank/data/backups
|
||
```
|
||
|
||
Datasets behave like sub-filesystems; you can set properties on each.
|
||
|
||
Example: enable compression and disable atime:
|
||
|
||
```bash
|
||
sudo zfs set compression=lz4 tank/data
|
||
sudo zfs set atime=off tank/data
|
||
```
|
||
|
||
#### Mountpoints
|
||
> By default, datasets are mounted under /tank/..., but you can set mountpoint property:
|
||
|
||
```bash
|
||
sudo mkdir -p /mnt/cloud
|
||
sudo zfs set mountpoint=/mnt/cloud tank/cloud
|
||
```
|
||
|
||
To list datasets and their mountpoints:
|
||
|
||
```bash
|
||
zfs list
|
||
```
|
||
|
||
#### Using snapshots & rollbacks
|
||
|
||
```bash
|
||
sudo zfs snapshot tank/data@before-update
|
||
```
|
||
|
||
Roll back:
|
||
|
||
```bash
|
||
sudo zfs rollback tank/data@before-update
|
||
```
|
||
|
||
Send/receive snapshots for backups:
|
||
|
||
```bash
|
||
sudo zfs send tank/data@before-update | ssh user@backuphost "zfs receive backup/data"
|
||
```
|
||
|
||
#### Mounting, Autostart, and Integration
|
||
|
||
> ZFS datasets are managed by ZFS itself; the mount/unmount is handled automatically by the ZFS service at boot (once ZFS is loaded). Ensure that ZFS mounting is enabled via systemd or init scripts:
|
||
|
||
```bash
|
||
sudo systemctl enable zfs-zed
|
||
sudo systemctl enable zfs-mount
|
||
sudo systemctl enable zfs-import-cache
|
||
```
|
||
|
||
PS : on Debian, the installation of zfs-zed may already set up the necessary services.
|
||
|
||
You can configure /etc/zfs/zfs-list.cache (automatically generated) for faster mounting.
|
||
|
||
---
|
||
|
||
### Querying ZFS File System Information
|
||
|
||
The zfs list command provides an extensible mechanism for viewing and querying dataset information. Both basic and complex queries are explained in this section.
|
||
|
||
#### Listing Basic ZFS Information
|
||
|
||
You can list basic dataset information by using the zfs list command with no options. This command displays the names of all datasets on the system and the values of their used, available, referenced, and mountpoint properties. For more information about these properties, see [Introducing ZFS Properties](https://docs.oracle.com/cd/E18752_01/html/819-5461/gazsu.htmlgazss.html).
|
||
|
||
For example:
|
||
|
||
```
|
||
# <b>zfs list</b>
|
||
NAME USED AVAIL REFER MOUNTPOINT
|
||
pool 476K 16.5G 21K /pool
|
||
pool/clone 18K 16.5G 18K /pool/clone
|
||
pool/home 296K 16.5G 19K /pool/home
|
||
pool/home/marks 277K 16.5G 277K /pool/home/marks
|
||
pool/home/marks@snap 0 - 277K -
|
||
pool/test 18K 16.5G 18K /test
|
||
```
|
||
|
||
You can also use this command to display specific datasets by providing the dataset name on the command line. Additionally, use the \-r option to recursively display all descendents of that dataset. For example:
|
||
|
||
```
|
||
# <b>zfs list -r pool/home/marks</b>
|
||
NAME USED AVAIL REFER MOUNTPOINT
|
||
pool/home/marks 277K 16.5G 277K /pool/home/marks
|
||
pool/home/marks@snap 0 - 277K -
|
||
```
|
||
|
||
You can use the zfs list command with the mount point of a file system. For example:
|
||
|
||
```
|
||
# <b>zfs list /pool/home/marks</b>
|
||
NAME USED AVAIL REFER MOUNTPOINT
|
||
pool/home/marks 277K 16.5G 277K /pool/home/marks
|
||
```
|
||
|
||
The following example shows how to display basic information about tank/home/chua and all of its descendent datasets:
|
||
|
||
```
|
||
# <b>zfs list -r tank/home/chua</b>
|
||
NAME USED AVAIL REFER MOUNTPOINT
|
||
tank/home/chua 26.0K 4.81G 10.0K /tank/home/chua
|
||
tank/home/chua/projects 16K 4.81G 9.0K /tank/home/chua/projects
|
||
tank/home/chua/projects/fs1 8K 4.81G 8K /tank/home/chua/projects/fs1
|
||
tank/home/chua/projects/fs2 8K 4.81G 8K /tank/home/chua/projects/fs2
|
||
```
|
||
|
||
For additional information about the zfs list command, see [zfs(1M)](https://docs.oracle.com/cd/E18752_01/html/819-5461/gazsu.html../816-5166/zfs-1m.html#REFMAN1Mzfs-1m).
|
||
|
||
#### Creating Complex ZFS Queries
|
||
|
||
The zfs list output can be customized by using the \-o, \-t, and \-H options.
|
||
|
||
You can customize property value output by using the \-o option and a comma-separated list of desired properties. You can supply any dataset property as a valid argument. For a list of all supported dataset properties, see [Introducing ZFS Properties](https://docs.oracle.com/cd/E18752_01/html/819-5461/gazsu.htmlgazss.html). In addition to the properties defined, the \-o option list can also contain the literal name to indicate that the output should include the name of the dataset.
|
||
|
||
The following example uses zfs list to display the dataset name, along with the sharenfs and mountpoint property values.
|
||
|
||
```
|
||
# <b>zfs list -o name,sharenfs,mountpoint</b>
|
||
NAME SHARENFS MOUNTPOINT
|
||
tank off /tank
|
||
tank/home on /tank/home
|
||
tank/home/ahrens on /tank/home/ahrens
|
||
tank/home/bonwick on /tank/home/bonwick
|
||
tank/home/chua on /tank/home/chua
|
||
tank/home/eschrock on legacy
|
||
tank/home/moore on /tank/home/moore
|
||
tank/home/tabriz ro /tank/home/tabriz
|
||
```
|
||
|
||
You can use the \-t option to specify the types of datasets to display. The valid types are described in the following table.
|
||
|
||
**Table 6-2 Types of ZFS Datasets**
|
||
|
||
<table border="0" cellpadding="0" cellspacing="0" class="dkgrey1" width="100%"><tbody><tr><td><table border="0" cellpadding="0" cellspacing="1" width="100%" class="vatop"><colgroup><col width="29%"><col width="70%"></colgroup><tbody><tr><th class="columncaption" align="left" valign="top"><div class="headerpadding">Type</div></th><th class="columncaption" align="left" valign="top"><div class="headerpadding">Description</div></th></tr><tr class="yellow2"><td align="left" valign="top"><div class="pad5x10"><tt>filesystem</tt></div></td><td align="left" valign="top"><div class="pad5x10">File systems and clones</div></td></tr><tr class="yellow2"><td align="left" valign="top"><div class="pad5x10"><tt>volume</tt></div></td><td align="left" valign="top"><div class="pad5x10">Volumes</div></td></tr><tr class="yellow2"><td align="left" valign="top"><div class="pad5x10"><tt>snapshot</tt></div></td><td align="left" valign="top"><div class="pad5x10">Snapshots</div></td></tr></tbody></table></td></tr></tbody></table>
|
||
|
||
The \-t options takes a comma-separated list of the types of datasets to be displayed. The following example uses the \-t and \-o options simultaneously to show the name and used property for all file systems:
|
||
|
||
```
|
||
# <b>zfs list -t filesystem -o name,used</b>
|
||
NAME USED
|
||
pool 476K
|
||
pool/clone 18K
|
||
pool/home 296K
|
||
pool/home/marks 277K
|
||
pool/test 18K
|
||
```
|
||
|
||
You can use the \-H option to omit the zfs list header from the generated output. With the \-H option, all white space is replaced by the Tab character. This option can be useful when you need parseable output, for example, when scripting. The following example shows the output generated from using the zfs list command with the \-H option:
|
||
|
||
```
|
||
# <b>zfs list -H -o name</b>
|
||
pool
|
||
pool/clone
|
||
pool/home
|
||
pool/home/marks
|
||
pool/home/marks@snap
|
||
pool/test
|
||
```
|