Wiki/Filesystems/Zfs.md

224 lines
5.5 KiB
Markdown
Raw Normal View History

2023-12-20 16:30:40 +01:00
# ZFS cheat sheet (EN)
---
## **Check the health of the pool's**
```
zpool status
```
DiskID's can be retrieved with ls -l /dev/disk/by-id/ or ls -l /dev/disk/by-path/ alternativ you can use sdb and sdc
# Create Pool
### mirror pool
(similar to raid-1, ≥ 2 disks, 1:1 redundancy)
```
zpool create tank mirror scsi-35000cca2735cbc38 scsi-35000cca266cc4b3c
```
### raidz1 pool
(similar to raid-5, ≥ 3 disks, 1 disk redundancy)
```
zpool create tank raidz scsi-35000cca2735cbc38 scsi-35000cca266cc4b3c scsi-35000cca26c108480
```
### raidz2 pool
(similar to raid-6, ≥ 4 disks, 2 disks redundancy)
```
zpool create tank raidz2 scsi-35000cca2735cbc38 scsi-35000cca266cc4b3c scsi-35000cca26c108480 scsi-35000cca266ccbdb4
```
### stripe pool
(similar to raid-0, no redundancy)
```
zpool create tank scsi-35000cca2735cbc38 scsi-35000cca266cc4b3c
```
### single disk stripe pool
```
zpool create tank scsi-35000cca26c108480
```
### 5 mirror
(like raid-10, 1:1 redundancy)
```
zpool create tank mirror scsi-35000cca2735cbc38 scsi-35000cca266cc4b3c\
mirror scsi-35000cca26c108480 scsi-35000cca266ccbdb4\
mirror scsi-35000cca266c75c74 scsi-35000cca26c0e84dc\
mirror scsi-35000cca266cda748 scsi-35000cca266cd14b4\
mirror scsi-35000cca266cb8ae4 scsi-35000cca266cbad80
```
### 2 raidz
(like raid-50, 2 disks redundancy in total)
```
zpool create tank raidz scsi-35000cca2735cbc38 scsi-35000cca266cc4b3c scsi-35000cca26c108480 scsi-35000cca266ccbdb4 scsi-35000cca266c75c74\
raidz scsi-35000cca26c0e84dc scsi-35000cca266cda748 scsi-35000cca266cd14b4 scsi-35000cca266cb8ae4 scsi-35000cca266cbad80
```
### ZFS can make use of fast SSD as second level cache (L2ARC) after RAM (ARC)
```
zpool add tank cache nvme-MT001600KWHAC_S3M0NA0K700264
```
# Mount
## mount a full pool
```
mkdir -p /data
zfs create -o mountpoint=/data tank/data
```
## mount only a ZVOL of a Pool
```
zfs create -s -V 4GB tank/vol
mkfs.ext4 /dev/zvol/tank/vol
mount /dev/zvol/tank/vol /mnt
```
## destroy previously created file systems and ZVOL
```
# ZFS will handle mounts that are managed by it
zfs destroy tank/data
# Need to umount first, because this mount is user managed
umount /dev/zvol/tank/vol
zfs destroy tank/vol
```
# Replace
You can replace a device in a storage pool by using the `zpool replace` command.
If you are physically replacing a device with another device in the same location in a redundant pool, then you might only need to identify the replaced device. ZFS recognizes that the device is a different disk in the same location on some hardware. For example, to replace a failed disk (c1t1d0) by removing the disk and replacing it in the same location, use the following syntax:
```
zpool replace tank c1t1d0
```
If you are replacing a device in a storage pool with a disk in a different physical location, you will need to specify both devices. For example:
```
zpool replace tank c1t1d0 c1t2d0
```
If you are replacing a disk in the ZFS root pool, see How to Replace a Disk in the ZFS Root Pool.
The following are the basic steps for replacing a disk:
Offline the disk, if necessary, with the `zpool offline` command.
Remove the disk to be replaced.
Insert the replacement disk.
Run the `zpool replace` command. For example:
```
zpool replace tank c1t1d0
```
- Bring the disk online with the `zpool online` command.
# CIFS shares
CIFS is a dialect of Server Message Block (SMB) Protocol and could be used on Windows, VMS, several versions of Unix, and other operating systems. To share a dataset through CIFS, samba package needs to be installed:
```
apt install samba
```
Because Microsoft Windows is not case sensitive, it is recommended to set casesensitivity=mixed to the dataset to be shared, and this property can only be set on creation time:
```
zfs create -o casesensitivity=mixed -o xattr=sa -o dnodesize=auto tank/data
```
Configure a very simiple CIFS share (read/write to 192.168.0.0/24, read only to 10.0.0.0/8):
```
zfs set mountpoint=/data tank/data
zfs set sharesmb=on tank/data
zfs share tank/data
```
Verify the share is exported successfuly:
```
smbclient -U guest -N -L localhost
```
Stop the CIFS share:
```
zfs unshare tank/data
# If you want to disable the share forever, do the following
zfs sharesmb=off tank/data
```
Replacing Devices in a Storage Pool If you are physically replacing a device with another device in the same location in a redundant pool, then you might only need to identify the replaced device. ZFS recognizes that the device is a different disk in the same location on some hardware. For example, to replace a failed disk (c1t1d0 or sdb) by removing the disk and replacing it in the same location, use the following syntax:
```
zpool replace tank {c1t1d0 or sdb/sdc}
```
If you are replacing a device in a storage pool with a disk in a different physical location, you will need to specify both devices. For example:
```
zpool replace tank {c1t1d0 or sdb/sdc} {c1t2d0 or sdd/sde}
```
If you are replacing a disk in the ZFS root pool, see How to Replace a Disk in the ZFS Root Pool.
The following are the basic steps for replacing a disk: Offline the disk, if necessary, with the zpool offline command. Remove the disk to be replaced. Insert the replacement disk. Run the zpool replace command. For example:
```
zpool replace tank {c1t1d0 or sdb/sdc}
```
## Quelle
- https://wiki.debian.org/ZFS#Creating_the_Pool
- https://docs.oracle.com/cd/E19253-01/819-5461/gazgd/index.html