quickreference:zfs
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
quickreference:zfs [2019/06/15 16:35] – external edit 127.0.0.1 | quickreference:zfs [2025/03/21 23:39] (current) – rodolico | ||
---|---|---|---|
Line 14: | Line 14: | ||
==== Create a zpool ==== | ==== Create a zpool ==== | ||
- | Now that we have ZFS running, we'll create a zpool, the basic container for all of our stuff. In this case, I want to use the raidz2 for redundancy (two drives are used for checksumming). Since I don't know the correct names for everything, I' | + | Now that we have ZFS running, we'll create a zpool, the basic container for all of our stuff. In this case, I want to use the raidz2 for redundancy (two drives are used for checksumming). Since I don't know the correct names for everything, I' |
+ | |||
+ | **Warning**: | ||
+ | |||
+ | **Note**: I've shown three ways to find the drives on the system. The first three commands give redundant information. If you have smartctl on your system, that is probably the easiest, since it has a scan function built in, but geom is FreeBSD' | ||
<code bash> | <code bash> | ||
- | # find the drives on the system | + | # find the drives on the system. Choose ONE of the following |
+ | geom disk list | grep Geom | rev | cut -d' ' -f1 | rev | sort | ||
egrep ' | egrep ' | ||
+ | smartctl --scan | cut -d' ' -f1 | ||
# we want RAID-6, name it storage, and us /dev/da0 through 7 | # we want RAID-6, name it storage, and us /dev/da0 through 7 | ||
zpool create -f storage raidz2 / | zpool create -f storage raidz2 / | ||
</ | </ | ||
+ | |||
+ | You can add extra functionality by creating //intent//, //dedup// and //cache// vdev's at the same time. Following example shows adding a vdev (mirror) to a pool. | ||
+ | <code bash> | ||
+ | zpool create -f -m /storage storage raidz2 da4 da5 da6 \ | ||
+ | da7 da8 da9 dedup mirror da2 da3 | ||
+ | </ | ||
+ | |||
+ | This will create a pool named storage, mounted (-m) at /storage, forced to ignore most drive errors. The pool will be a raidz2 (aka RAID 6) with 6 drives (4-9), and have a dedup vdev consisting of a mirror from da2 and 3. | ||
+ | |||
+ | ==== Set dataset defaults ==== | ||
+ | |||
+ | Your new dataset may not have the default values you want. It is simple enough to set defaults for all child datasets at this point, then any datasets/ | ||
+ | |||
+ | This is the way I have most set up. Modify it for your own use. Pay particular attention to the dedup=on and compress=gzip-9. | ||
+ | * dedup will use more memory and cpu, but will reduce the amount of disk space required if your data contains duplicates (think 10 Devuan Daedalus installations taking up the same amount of space as 1 for the common blocks) | ||
+ | * compress is fine, but gzip-9 will tear up your processor. I use gzip-9 for backup servers, but for servers actually serving all the time (like iSCSI or NFS), I use ztsd or even lz4 to decrease my server load. See the excellent article at https:// | ||
+ | * volmode=full should really be the default (grumble). It simply takes the block of space and exports it for iSCSI. | ||
+ | |||
+ | <code bash> | ||
+ | zfs set atime=off dedup=on compress=gzip-9 volmode=full storage | ||
+ | </ | ||
+ | |||
+ | ===== Create a Dataset ===== | ||
+ | |||
+ | Datasets are just allocations in the file system for specific purposes. Unlike traditional disks and volume managers, space in ZFS is not preallocated. You can create an allocation with various options (using the -o flag). Anything not set will be inherited from the parent. | ||
+ | |||
+ | <code bash> | ||
+ | zfs create -o quota=150G -o atime=off -o compression=lz4 storage/ | ||
+ | # or | ||
+ | zfs create -o quota=150G -o atime=off -o compression=on storage/ | ||
+ | </ | ||
+ | |||
+ | This allocates 150G of space in the zpool storage, turning off atime, but setting compression to lz4. It will be mounted wherever client1 is mounted. Everything else is inherited from client1, which in turn inherits from backup, which inherits from storage. | ||
===== Use a ZFS Volume for swap space ===== | ===== Use a ZFS Volume for swap space ===== | ||
Line 45: | Line 84: | ||
swapon -aL | swapon -aL | ||
</ | </ | ||
+ | |||
+ | ===== Using a file for swap space ===== | ||
+ | |||
+ | Instead of using a swap partition or zvol, we can simply use a file. In this case, we can add swap space by deleting/ | ||
+ | |||
+ | Following code creates an 8G swap file. Note that after reading https:// | ||
+ | |||
+ | <code bash> | ||
+ | # create an 8G swap file | ||
+ | dd if=/ | ||
+ | # set permissions | ||
+ | chmod 0600 /swap | ||
+ | # look for an unused md device (ie, not listed) | ||
+ | mdconfig -lv | ||
+ | cp /etc/fstab / | ||
+ | # edit /etc/fstab and add the following line, using the correct md## | ||
+ | joe /etc/fstab | ||
+ | md42 none swap sw, | ||
+ | # save your file | ||
+ | # turn on swap | ||
+ | swapon -aq | ||
+ | # look at swap information | ||
+ | swapinfo -k | ||
+ | </ | ||
+ | |||
+ | ===== iSCSI considerations ===== | ||
+ | |||
+ | On FreeBSD, the iSCSI config is / | ||
+ | |||
+ | iSCSI generally uses volumes which are then exported by the target. I have found that it is useful, from a management perspective, | ||
+ | |||
+ | A lot of time, my iSCSI targets are just the operating system, and maybe log files. If I also use it for dynamic data (e-mail repo, databases, web sites), I back up through a different means, though a lot of time I use NFS to store this. | ||
+ | |||
+ | I generally create something like storage/ | ||
+ | |||
+ | <code bash> | ||
+ | zfs create storage/ | ||
+ | zfs create -V 10G storage/ | ||
+ | zfs create -V 10G storage/ | ||
+ | </ | ||
+ | |||
+ | This allows me to snapshot my iSCSI volumes with one command, then send them with one: | ||
+ | <code bash> | ||
+ | zfs snapshot -r storage/ | ||
+ | zfs send -Ri storage/ | ||
+ | </ | ||
+ | |||
+ | Your iSCSI paths will be the same as you would expect; in this case, stored under / | ||
+ | |||
+ | Note: If you have an existing system and want to change, zfs rename is your friend. | ||
+ | - On initiator | ||
+ | - Shut down access to volume on the iSCSI initiator | ||
+ | - detach from iSCSI initiator (not sure if this is required) | ||
+ | - On iSCSI target | ||
+ | - Rename the volume <code bash> zfs rename storage/ | ||
+ | - Edit the config to point to new location (**/ | ||
+ | - reload iscsi service <code bash> | ||
+ | - On initiator | ||
+ | - rescan target | ||
+ | - allow access to volume | ||
+ | |||
+ | |||
===== Getting and setting properties ===== | ===== Getting and setting properties ===== | ||
Line 63: | Line 164: | ||
zfs inherit -r quota storage/ | zfs inherit -r quota storage/ | ||
</ | </ | ||
+ | |||
+ | ===== Deduplication ===== | ||
+ | If you want to see what the effect of deduplication would be, you can use zdb to calculate it. **NOTE** This will take a long time as it must open every block on the disk and build a deduplication table from it. However, it is well worth doing if you are considering adding the additional complexity of deduplication. | ||
+ | |||
+ | <code bash>zdb -S -U / | ||
+ | |||
+ | You can find the name of the cache file (if configured) with <code bash> | ||
+ | |||
+ | Dedup requires 320 bytes per block of memory, so you can take the output of the above command, multiply by 320, and see the amount of RAM which will be required to run dedup. NOTE: This can grow as more unique blocks are allocated. | ||
+ | |||
===== Find differences between two snapshots ===== | ===== Find differences between two snapshots ===== | ||
Line 81: | Line 192: | ||
</ | </ | ||
===== Useful commands ===== | ===== Useful commands ===== | ||
- | List all snapshots in a particular tree. gives USED (space used by snapshot) and REFER (data referred to in original set) | ||
- | <code bash> | ||
- | zfs list -r -t snapshot / | ||
- | </ | ||
- | Remove an existing snapshot (use above command to find the correct name) | + | * Create a snapshot of **path/ |
- | <code bash> | + | * List all snapshots in a particular tree. gives USED (space used by snapshot) and REFER (data referred to in original set)< |
- | zfs destroy -r tank/ | + | * Remove an existing snapshot (use above command to find the correct name)< |
- | </ | + | |
- | + | ||
- | + | ||
- | Get a nice list of stats on every dataset in a tree (does the whole tree). Gives AVAIL, ie amount of space available, USED, USEDSNAP (space used by snapshots), USEDDS (space used by the dataset exclusive of snapshots, ie actual data), USEDREFRESERV (whatever that is) and USEDCHILD (used by children of the dataset). | + | |
- | <code bash> | + | |
- | zfs list -o space -r storage/ | + | |
- | </ | + | |
Line 105: | Line 206: | ||
* https:// | * https:// | ||
* https:// | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
quickreference/zfs.1560634551.txt.gz · Last modified: 2019/06/15 16:35 by 127.0.0.1