init
This commit is contained in:
commit
c5cd492449
475 changed files with 27928 additions and 0 deletions
177
technology/linux/filesystems/ZFS.md
Normal file
177
technology/linux/filesystems/ZFS.md
Normal file
|
@ -0,0 +1,177 @@
|
|||
---
|
||||
arch-wiki: https://wiki.archlinux.org/title/ZFS
|
||||
website: https://openzfs.org/wiki/Main_Page
|
||||
repo: https://github.com/openzfs/zfs
|
||||
obj: filesystem
|
||||
---
|
||||
#refactor
|
||||
# ZFS
|
||||
[ZFS](https://en.wikipedia.org/wiki/ZFS "wikipedia:ZFS") is an advanced filesystem.
|
||||
|
||||
## ZPool
|
||||
**Create a pool***
|
||||
```shell
|
||||
zpool create -f -m <mount> <pool> [raidz(2|3)|mirror] <ids>
|
||||
```
|
||||
|
||||
**Pool Status**
|
||||
```shell
|
||||
zpool status -v
|
||||
```
|
||||
|
||||
**Import Pool**
|
||||
```shell
|
||||
zpool import -l -d /dev/disk/by-id <pool> # Import pool
|
||||
zpool import -a # Import all available pools
|
||||
zpool import -a -f # Import all available pools with force option
|
||||
```
|
||||
|
||||
**Export Pool**
|
||||
```shell
|
||||
zpool export <pool>
|
||||
```
|
||||
|
||||
**Extend Pool**
|
||||
```shell
|
||||
zpool add <pool> <device-id>
|
||||
```
|
||||
|
||||
**Destroy pool / dataset**
|
||||
```shell
|
||||
zpool destroy <pool>
|
||||
zfs destroy <pool>/<dataset>
|
||||
```
|
||||
|
||||
**Rename a pool**
|
||||
```shell
|
||||
zpool export oldname
|
||||
zpool import oldname newname
|
||||
```
|
||||
|
||||
**Upgrade pool**
|
||||
```shell
|
||||
zpool upgrade <pool>
|
||||
```
|
||||
|
||||
### Automount
|
||||
Specify this for `zfs-import-cache.service` to pick up the pool
|
||||
```shell
|
||||
zpool set cachefile=/etc/zfs/zpool.cache <pool>
|
||||
```
|
||||
|
||||
## Datasets
|
||||
### Creation
|
||||
**Create Dataset**
|
||||
```shell
|
||||
zfs create <nameofzpool>/<nameofdataset>
|
||||
```
|
||||
|
||||
**Create encrypted dataset:**
|
||||
```shell
|
||||
dd if=/dev/random of=/path/to/key bs=1 count=32 # Generate key
|
||||
|
||||
zfs create -o encryption=on -o keyformat=raw -o keylocation=file://$KEYLOCATION "$DATASET"
|
||||
```
|
||||
**Load all encryption keys**
|
||||
```shell
|
||||
zfs load-key -a
|
||||
```
|
||||
|
||||
**Load all keys at boot with systemd**
|
||||
__/etc/systemd/system/zfs-load-key.service__:
|
||||
``` ini
|
||||
[Unit]
|
||||
Description=Load encryption keys
|
||||
DefaultDependencies=no
|
||||
After=zfs-import.target
|
||||
Before=zfs-mount.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/bin/zfs load-key -a
|
||||
StandardInput=tty-force
|
||||
|
||||
[Install]
|
||||
WantedBy=zfs-mount.service
|
||||
```
|
||||
|
||||
### Snapshots
|
||||
**Create snapshot:**
|
||||
```shell
|
||||
zfs snapshot <pool>/<dataset>@<snapshot>
|
||||
```
|
||||
|
||||
**Send and receive:**
|
||||
```shell
|
||||
zfs send -v -w <pool>/<dataset>@<snapshot> | zfs recv <pool>/<newdataset>
|
||||
```
|
||||
|
||||
### Properties
|
||||
**Get properties:**
|
||||
```shell
|
||||
zfs get <property> <pool>/<dataset>
|
||||
```
|
||||
|
||||
**Set properties**
|
||||
```shell
|
||||
zfs set <property>=<value> <pool>/<dataset>
|
||||
```
|
||||
|
||||
### Available Properties
|
||||
- `compressratio` : Shows information on compression
|
||||
- `creation` : Get creation date
|
||||
- `mounted` : Status on mount
|
||||
- `used` : Information on usage
|
||||
- `canmount` : Forbid or enable mounting
|
||||
- `casesensitivity` : Choose sensitivity
|
||||
- `compression` : Choose compression method
|
||||
- `encryption` : Encryption Information
|
||||
- `mountpoint` : Specify the mountpoint
|
||||
- `quota` : Filesystem Quota
|
||||
- `readonly` : Readonly or Readwrite
|
||||
- `reservation` : Reserved Space
|
||||
|
||||
### Scrub
|
||||
Like [Btrfs](Btrfs.md) ZFS can heal itself with scrubbing
|
||||
|
||||
**Start a scrub:**
|
||||
```shell
|
||||
zpool scrub <pool>
|
||||
```
|
||||
|
||||
**Cancel a scrub:**
|
||||
```shell
|
||||
zpool scrub -s <pool>
|
||||
```
|
||||
|
||||
**Autoscrubbing with systemd:**
|
||||
|
||||
__/etc/systemd/system/zfs-scrub@.timer__
|
||||
```ini
|
||||
[Unit]
|
||||
Description=Monthly zpool scrub on %i
|
||||
|
||||
[Timer]
|
||||
OnCalendar=monthly
|
||||
AccuracySec=1h
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
||||
|
||||
__/etc/systemd/system/zfs-scrub@.service__
|
||||
```ini
|
||||
[Unit]
|
||||
Description=zpool scrub on %i
|
||||
|
||||
[Service]
|
||||
Nice=19
|
||||
IOSchedulingClass=idle
|
||||
KillSignal=SIGINT
|
||||
ExecStart=/usr/bin/zpool scrub %i
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue