ZFS

Aus Info-Theke
Zur Navigation springen Zur Suche springen

Links

Kommandos

# RAM-Belegung von ZFS Anzeigen:
echo $(( `cat /proc/spl/kmem/slab | tail -n +3 | awk '{ print $3 }' | tr "\n" "+" | sed "s/$/0/"` ))
# RAID1 einrichten:
zpool create my-samsung-mirror1 mirror /dev/sda1 /dev/db1
# RAID10 einrichten:
zpool create my-samsung-mirror2 mirror /dev/DISK1 /dev/disk/DISK2 mirror /dev/DISK3 /dev/DISK4
# RAID5 einrichten:
zpool create meinRAIDZ raidz /dev/disk/by-id/DISK1 /dev/disk/by-id/DISK2 /dev/disk/by-id/DISK3

zpool list
zpool status
# Pool testen:
zpool scrub mypool

# ZFS-Dateisystem einrichten:
mkdir -p /media/db/mysql /media/db/pg
zfs create -o acltype=posixacl -o compression=zstd-3 -o dnodesize=auto -o normalization=formD -o relatime=on -o mountpoint=/media/db/mysql db/mysql
zfs create -o acltype=posixacl -o compression=zstd-3 -o dnodesize=auto -o normalization=formD -o relatime=on -o mountpoint=/media/db/pg db/pg
zfs list

# Quota:
zfs set quota=10G meinPool/FS1

zfs get atime
# readonly: available compressratio creation guid mounted snapshot_count type used written
zfs set compression=zlib-3
# rw: atime checksum compression dedup mountpoint quota readonly relatime utf8only 

Mounten

zfs get mountpoint meinPool/FS1
zfs set mountpoint=/media/meinPool_FS1 meinPool/FS1
# Wenn man mount/umount verwenden will:  Legacy-Einhängepunkte
zfs set mountpoint=legacy meinPool/FS1
  • ZFS-Dateisysteme können nur mit Legacy-Dienstprogrammen verwaltet werden (indem Sie die Eigenschaft „mountpoint“ auf „legacy“ setzen)
  • Dann sind die Befehle mount und umount sowie die Datei /etc/vfstab relevant.
  • ZFS hängt Legacy-Dateisysteme beim Systemstart nicht automatisch ein, die ZFS-Befehle zfs mount und zfs umount funktionieren nicht!

Snapshots

zfs list -t snapshot
# Sortiert nach Name, Erzeugung
zfs list -t snapshot -o name,creation -s creation
# Erzeugen:
zfs snapshot -r meinPool/FS1@snapshot1
zfs rollback -r meinPool/FS1@snapshot1
zfs destroy meinPool/FS1@snapshot1
zfs diff meinPool/FS1@snapshot1 meinPool/FS1@snapshot2
  • im normalen Mountverzeichnis gibt es den unsichtbaren Ordner .zfs. Auch wenn dieser Ordner auch mit ls -la nicht sichtbar ist, so kann dennoch hinein gewechselt werden. Dieses Verhalten ist praktisch damit tools wie rsync nicht versehentlich snapshots mitkopieren.

Snapshots übertragen

# Initial:
zfs send meinPool/FS1@snap1 | ssh root@$Zielhost zfs recv meinBACKUPPool/FS1
# Ändern:
dd if=/dev/zero bs=1024000 count=1024 >> /meinPool/FS1/test2
# Snapshot anlegen:
zfs snapshot -r meinPool/FS1@snap2
# Snapshot inkrementell senden (lt. ifconfig werden 1G übertragen):
zfs send -i meinPool/FS1@snap1 meinPool/FS1@snap2 | ssh root$Zielhost zfs recv meinBACKUPPool/FS1

ZFS Clones

Ein ZFS clone ist eine schreibbare Kopie eines Snapshots. Der Snapshot kann so lange nicht gelöscht werden wie der Clone besteht.

zfs snapshot -r meinPool/FS1@snapshot1
zfs clone meinPool/FS1@snapshot1 meinPool/FS2

ZFS Shares

  • Shares sind NFS oder SMB-Freigaben
zfs create rpool/fs1
zfs set share=name=fs1,path=/rpool/fs1,prot=nfs rpool/fs1
zfs set share=name=pp,path=/pub,prot=nfs,sec=sys,rw=*,public rpool/public
zfs set sharenfs=on rpool/fs1
cat /etc/dfs/sharetab
# /rpool/fs1      fs1     nfs     sec=sys,rw
  • Optionen:
    • description=string rw=host1:host2:host3 rw=* ro=host1:host2 root=root
  • prot: nfs|smb
  • sec: sys|dh|krb5
  • NFS-Optionen (zwischen prot= ... und sec=...:
    • anon=user-name|uid nosub=true|false nosuid=true|false aclok=true|false
    • public=true|false index=filename log=TYPE_LOGTAG cksum=TYPE_STRINGSET
  • SMB-Optionen:
    • ad-container=string abe=[true|false] csc=[disabled|manual|auto|vdo]
    • catia=[true|false] guestok=[true|false] ro=access-list rw=access-list none=access-list
  • Infos:
zfs get sharenfs rpool/fs1
zfs get share rpool/fs1
  • Entfernen:
# Namen ermitteln:
zfs get share
# rpool/ds     share     name=ds,path=/ds,prot=nfs  local
# Entfernen:
zfs set -c share=name=ds rpool/ds

ZFS Volumes

Statt Dateisystemen kann ZFS auch volumes anlegen, das sind Blockgeräte die z.B. in virtualisierten Gästen verwendet werden können.

Aufruf ist wie beim Dateisystem anlegen, nur zusätzlich mit dem Parameter „-V $Größe“:

zfs create -V 2G tank/volumes/v2

Das Volume steht dann unter /dev/tank/volumes/v2 zur Verfügung und kann normal wie blockdevice verwendet werden.

Pool zu RAID1 umwandeln

# Pool ohne RAID anlegen:
zpool create pdata /dev/nvme0n1p6
zfs create -o acltype=posixacl -o compression=zstd-3 -o dnodesize=auto -o normalization=formD \
  -o relatime=on -o mountpoint=/media/fs.many data/fs.many
...
# Pool erweitern:
zpool attach pdata /dev/nvme0n1p6 /dev/sda6
  • Wenn die Meldung kommt: new device has a different optimal sector size; use the option '-o ashift=N'...
zdb pdata | grep -i ashift
# ashift: 9
zpool attach pdata /dev/nvme0n1p6 /dev/sda6 -o ashift=9

Konfiguration

  • /etc/modprobe.d/zfs.conf
# RAM auf 8 G beschränken:
options zfs zfs_arc_max=8589934592

Fehlerfall

zpool status
# ===
  pool: rpool
 state: ONLINE
  scan: ...
config:
	NAME                                                 STATE     READ WRITE CKSUM
	rpool                                                ONLINE       0     0     0
	  mirror-0                                           ONLINE       0     0     0
	    nvme-eui.0000000001000000e4d25c68508e5101-part3  ONLINE       0     0     0
	    ata-CT1000MX500SSD1_2009E2901DCE-part6           ONLINE       0     0     0
# ===
zpool detach rpool /dev/disk/by-id/ata-CT1000MX500SSD1_2009E2901DCE-part3
# Platte tauschen, dann:
zpool attach rpool /dev/disk/by-id/nvme-eui.0000000001000000e4d25c68508e5101-part3 /dev/disk/by-id/ata-SAMSUNGxxxx_3B99E2901D77-part6
# Danach Kontrolle des "Resilver"-Status mit:
zpool status rpool
...
scan: resilvered 1.07G in 0 days 00:00:03 with 0 errors on Sat Feb 19 06:20:02 2022