User Tools

Site Tools


quickreference:zfs

Differences

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

Link to this comparison view

Next revision
Previous revision
quickreference:zfs [2019/06/15 16:35] – external edit 127.0.0.1quickreference:zfs [2024/02/03 23:04] (current) rodolico
Line 22: Line 22:
 zpool create -f storage raidz2 /dev/da[01234567] zpool create -f storage raidz2 /dev/da[01234567]
 </code> </code>
 +
 +===== 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/backups/client1/server.client1
 +# or
 +zfs create -o quota=150G -o atime=off -o compression=on storage/backups/client1/server.client1
 +</code>
 +
 +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 57:
 swapon -aL swapon -aL
 </code> </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>
 +
 +===== 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.
 +
 +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/iscsi, then create the volumes under that.
 +
 +<code bash>
 +zfs create storage/iscsi
 +zfs create -V 10G storage/iscsi/server1.disk0
 +zfs create -V 10G storage/iscsi/server1.disk1
 +</code>
 +
 +This allows me to snapshot my iSCSI volumes with one command, then send them with one:
 +<code bash>
 +zfs snapshot -r storage/iscsi@2022-04-20_22-30
 +zfs send -Ri storage/iscsi@2022-04-20_22-30 | ssh someplace 'zfs recv -Fduv storage/backups/iscsi'
 +</code>
 +
 +Your iSCSI paths will be the same as you would expect; in this case, stored under /dev/zvol/storage/iscsi
 +
 +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/volumename storage/iscsi/volumename</code>
 +    - Edit the config to point to new location (**/etc/ctl.conf** on FreeBSD)
 +    - reload iscsi service <code bash>service ctld reload # on FreeBSD</code>
 +  - On initiator
 +    - rescan target
 +    - allow access to volume
 +
 +
  
 ===== Getting and setting properties ===== ===== Getting and setting properties =====
Line 63: Line 137:
 zfs inherit -r quota storage/varlog zfs inherit -r quota storage/varlog
 </code> </code>
 +
 +===== 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 /path/to/some/cache/file poolname</code>
 +
 +You can find the name of the cache file (if configured) with <code bash>zpool get cachefile poolname</code>
 +
 +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 165:
 </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 105: Line 179:
    * https://www.cyberciti.biz/faq/freebsd-hard-disk-information/    * https://www.cyberciti.biz/faq/freebsd-hard-disk-information/
    * https://www.thegeekdiary.com/how-to-find-the-space-consumed-by-zfs-snapshots/    * https://www.thegeekdiary.com/how-to-find-the-space-consumed-by-zfs-snapshots/
 +   * https://docs.oracle.com/cd/E23824_01/html/E24456/filesystem-6.html
 +   * https://wordpress.morningside.edu/meyersh/2009/11/30/zfs-deduplication/
 +   * https://linuxhint.com/zfs-deduplication/
 +   * https://www.cyberciti.biz/faq/create-a-freebsd-swap-file/
  
  
quickreference/zfs.1560634551.txt.gz · Last modified: 2019/06/15 16:35 by 127.0.0.1