User Tools

Site Tools


quickreference:zfs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
quickreference:zfs [2022/10/20 02:48] rodolicoquickreference: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'll egrep /var/run/dmesg.boot to find them+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'll use geom to find them. 
 + 
 +**Warning**: The following will find all drives on the system, including your boot drives, so remove the boot drives before proceeding with the zpool creation. 
 + 
 +**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's way to do it.
  
 <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 'da[0-9]|cd[0-9]' /var/run/dmesg.boot | sort egrep 'da[0-9]|cd[0-9]' /var/run/dmesg.boot | sort
 +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 /dev/da[01234567] zpool create -f storage raidz2 /dev/da[01234567]
 +</code>
 +
 +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
 +</code>
 +
 +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/volumes you create will default to the following values.
 +
 +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://www.zfshandbook.com/docs/advanced-zfs/compression/ for a comparison.
 +  * 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
 </code> </code>
  
Line 56: Line 83:
 # turn swap back on (could also use swapon /dev/zvol/storage/swap, but I'm lazy) # turn swap back on (could also use swapon /dev/zvol/storage/swap, but I'm lazy)
 swapon -aL swapon -aL
 +</code>
 +
 +===== 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/recreating the swap file (after turning swap off), but a simpler way if you need more swap space is to simply add a second swap file.
 +
 +Following code creates an 8G swap file. Note that after reading https://www.cyberciti.biz/faq/create-a-freebsd-swap-file/, I modified my old way of doing this.
 +
 +<code bash>
 +# create an 8G swap file
 +dd if=/dev/zero of=/swap bs=1G count=8
 +# set permissions
 +chmod 0600 /swap
 +# look for an unused md device (ie, not listed)
 +mdconfig -lv 
 +cp /etc/fstab /etc/fstab.save
 +# edit /etc/fstab and add the following line, using the correct md##
 +joe /etc/fstab
 +md42 none swap sw,file=/swap 0 0
 +# save your file
 +# turn on swap
 +swapon -aq
 +# look at swap information
 +swapinfo -k
 </code> </code>
  
 ===== iSCSI considerations ===== ===== iSCSI considerations =====
 +
 +On FreeBSD, the iSCSI config is /etc/ctl.conf, and the service is ctld <code bash>service ctld reload # reread iscsi exports on FreeBSD</code>
  
 iSCSI generally uses volumes which are then exported by the target. I have found that it is useful, from a management perspective, to place them under a dataset strictly for them, since I back up iSCSI volumes on a different timeline than I do other stuff. iSCSI generally uses volumes which are then exported by the target. I have found that it is useful, from a management perspective, to place them under a dataset strictly for them, since I back up iSCSI volumes on a different timeline than I do other stuff.
Line 68: Line 121:
 <code bash> <code bash>
 zfs create storage/iscsi zfs create storage/iscsi
-zfs -V 10G storage/iscsi/server1.disk0 +zfs create -V 10G storage/iscsi/server1.disk0 
-zfs -V 10G storage/iscsi/server1.disk1+zfs create -V 10G storage/iscsi/server1.disk1
 </code> </code>
  
Line 85: Line 138:
     - detach from iSCSI initiator (not sure if this is required)     - detach from iSCSI initiator (not sure if this is required)
   - On iSCSI target   - On iSCSI target
-    - edit config +    - Rename the volume <code bash> zfs rename storage/volumename storage/iscsi/volumename</code> 
-    - <code zfs rename storage/volumename storage/iscsi/volumename +    - Edit the config to point to new location (**/etc/ctl.conf** on FreeBSD) 
-    - reload iscsi service+    - reload iscsi service <code bash>service ctld reload # on FreeBSD</code>
   - On initiator   - On initiator
     - rescan target     - rescan target
     - allow access to volume     - allow access to volume
  
-I have **NOT** done this yet. This is based on some research I have done, and a little testing, so use at your own risk.+
  
 ===== Getting and setting properties ===== ===== Getting and setting properties =====
Line 139: Line 192:
 </code> </code>
 ===== 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 /storage/varlog 
-</code> 
  
-Remove an existing snapshot (use above command to find the correct name) +  * Create a snapshot of **path/to/base** named **snapshotname**<code bash>zfs snapshot path/to/base@snapshotname</code> 
-<code bash> +  * 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 /storage/varlog</code> 
-zfs destroy -r tank/storage/varlog/@20181026_054020 +  * Remove an existing snapshot (use above command to find the correct name)<code bash>zfs destroy -r tank/storage/varlog/@20181026_054020</code> 
-</code> +  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/varlog</code>
- +
- +
-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/varlog +
-</code>+
  
  
Line 166: Line 209:
    * https://wordpress.morningside.edu/meyersh/2009/11/30/zfs-deduplication/    * https://wordpress.morningside.edu/meyersh/2009/11/30/zfs-deduplication/
    * https://linuxhint.com/zfs-deduplication/    * https://linuxhint.com/zfs-deduplication/
 +   * https://www.cyberciti.biz/faq/create-a-freebsd-swap-file/
  
  
quickreference/zfs.1666252093.txt.gz · Last modified: 2022/10/20 02:48 by rodolico