{"id":6207,"date":"2021-05-02T22:28:06","date_gmt":"2021-05-02T22:28:06","guid":{"rendered":"https:\/\/linuxways.net\/?p=6207"},"modified":"2021-05-02T22:28:06","modified_gmt":"2021-05-02T22:28:06","slug":"how-to-configure-zfs-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-configure-zfs-on-ubuntu-20-04\/","title":{"rendered":"How to Configure ZFS on Ubuntu 20.04"},"content":{"rendered":"<p>ZFS commonly known as Z file system is mainly based on storage and redundancy. The concept of ZFS was developed with file servers in mind where high availability and data integrity are the most crucial factors. ZFS uses virtual storage pools commonly known as zpools to deal with the storage and management of large amounts of data. In this article, we will get to know about how to install zfs and its common uses in the technical environment.<\/p>\n<h2>Prerequisites<\/h2>\n<p>Fresh Ubuntu 20.04 server<\/p>\n<p>Sudo privileged non-root user account<\/p>\n<h2>Installation<\/h2>\n<p>Installation of ZFS is a straightforward process. You can use the command line terminal application to install the ZFS file system. Lunch the command line terminal tool and execute the following command.<\/p>\n<pre>$ sudo apt update<\/pre>\n<pre>$ sudo apt install zfsutils-linux<\/pre>\n<p>During the installation, you may be prompted for the password, provide sudo password and continue.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1081\" height=\"369\" class=\"wp-image-6208\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-437.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-437.png 1081w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-437-300x102.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-437-1024x350.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-437-768x262.png 768w\" sizes=\"auto, (max-width: 1081px) 100vw, 1081px\" \/><\/p>\n<p>Once running the above command, you will be asked for confirmation if you want to continue with installation or not. Press \u2018y\u2019 and enter. Now the software package will be installed on your system.<\/p>\n<p>To verify the installation of ZFS on your system, use the following command.<\/p>\n<pre>$ zfs --version<\/pre>\n<p>You will get the output similar as:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"679\" height=\"95\" class=\"wp-image-6209\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-438.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-438.png 679w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-438-300x42.png 300w\" sizes=\"auto, (max-width: 679px) 100vw, 679px\" \/><\/p>\n<h2>ZFS Basic usage and commands<\/h2>\n<p>Once the ZFS is installed, now you can use hard drives with ZFS. When the new hard drives are inserted into your system, ZFS addresses them by their device name. For instance something similar as the lines of <strong>\/dev\/sda<\/strong> or similar. You can use <strong>fdisk<\/strong> command line utility to check available hard drives.<\/p>\n<pre>$ sudo fdisk -l<\/pre>\n<p>You will find output similar as:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"923\" height=\"550\" class=\"wp-image-6210\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-439.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-439.png 923w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-439-300x179.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-439-768x458.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-439-501x300.png 501w\" sizes=\"auto, (max-width: 923px) 100vw, 923px\" \/><\/p>\n<h2>How to create and destroy zpools<\/h2>\n<p>ZFS works with the concept of pooling disks together. Various Raid levels can be used while creating pools. The first pool we will be creating is RAID 0 . RAID level 0 works by striping your data across a number of disks. When a file is written to or read from the storage pool all the disks will come in action to present the portion of data. This level of RAID provides you a speed boost for your read and write operation speed however it lacks data redundancy. Any critical issue on the disk or disk malfunction in the pool will cost complete loss of data.<\/p>\n<p>In this example, I have used two hard drives <strong>\/dev\/sdb<\/strong> and <strong>\/dev\/sdd<\/strong> for creating the pool named<strong> test-pool<\/strong>. You can have your own assumption on disk and pool name selection. Run the following command to create zpool.<\/p>\n<pre>$ sudo zpool create test-pool \/dev\/sdb \/dev\/sdd<\/pre>\n<p>If any error appears, you can run the command using <strong>-f <\/strong>option after the <strong>zpool create<\/strong> command which forces the command to be executed.<\/p>\n<pre>$ sudo zpool create -f test-pool \/dev\/sdb \/dev\/sdd<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"702\" height=\"104\" class=\"wp-image-6211\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-440.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-440.png 702w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-440-300x44.png 300w\" sizes=\"auto, (max-width: 702px) 100vw, 702px\" \/><\/p>\n<p>Once created, you can find out the mount point using the following command:<\/p>\n<pre>$ df -h<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"948\" height=\"293\" class=\"wp-image-6212\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-441.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-441.png 948w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-441-300x93.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-441-768x237.png 768w\" sizes=\"auto, (max-width: 948px) 100vw, 948px\" \/><\/p>\n<p>From the output, we can see that the pool is mounted at <strong>\/test-pool . <\/strong>You can change the mount point for the pool, use the following syntax.<\/p>\n<pre>$ sudo zfs set mountpoint =&lt;path&gt; &lt;pool_name&gt;<\/pre>\n<p>In this example, I have used <strong>\/var\/www<\/strong> as the new mount point. You can have your own consideration for the mount point.<\/p>\n<pre>$ sudo zfs set mountpoint=\/var\/www test-pool<\/pre>\n<p>Verify the new point using the following command.<\/p>\n<pre>$ df -h<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"962\" height=\"272\" class=\"wp-image-6213\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-442.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-442.png 962w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-442-300x85.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-442-768x217.png 768w\" sizes=\"auto, (max-width: 962px) 100vw, 962px\" \/><\/p>\n<p>You can create the directories under the storage pool. In this example, I have created the directory named MySQL under the storage pool test-tool.<\/p>\n<pre>$ sudo zfs create test-pool\/mysql<\/pre>\n<p>Run the following command to view all the ZFS storage pools on the system.<\/p>\n<pre>$ zpool list<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"904\" height=\"107\" class=\"wp-image-6214\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-443.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-443.png 904w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-443-300x36.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-443-768x91.png 768w\" sizes=\"auto, (max-width: 904px) 100vw, 904px\" \/><\/p>\n<p>To find the configuration and status of each device in the ZFS pool, use the following command.<\/p>\n<pre>$ zpool status<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"831\" height=\"267\" class=\"wp-image-6215\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-444.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-444.png 831w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-444-300x96.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-444-768x247.png 768w\" sizes=\"auto, (max-width: 831px) 100vw, 831px\" \/><\/p>\n<p>To troubleshoot ZFS storage pool in case of any issue, execute the following command which shows the zpool events. Replace pool_name with your ZFS storage pool.<\/p>\n<pre>$ sudo zpool events pool_name -v<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1280\" height=\"317\" class=\"wp-image-6216\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-445.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-445.png 1280w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-445-300x74.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-445-1024x254.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-445-768x190.png 768w\" sizes=\"auto, (max-width: 1280px) 100vw, 1280px\" \/><\/p>\n<p>If you want to add another hard disk in the ZFS storage pool, you can use the following command. In this example I have used a new hard disk <strong>\/dev\/sdc<\/strong> to add in the previously created ZFS storage pool test-pool. You can select your hard disk and zpool name accordingly.<\/p>\n<pre>$ sudo zpool add test-pool \/dev\/sdc<\/pre>\n<p>Once the disk is added verify the pool using the command:<\/p>\n<pre>$ zpool status<\/pre>\n<p>To destroy the ZFS storage pool, run the following command with your valid pool name.<\/p>\n<pre>$ sudo zpool destroy pool_name<\/pre>\n<p>For example,<\/p>\n<pre>$ sudo zpool destroy test-pool<\/pre>\n<h2>How to use encryption with ZFS<\/h2>\n<p>After creating a ZFS storage pool, you can enable encryption on it with the following command. For this example, I have used a previously created ZFS pool named \u201ctest-pool\u201d for encryption. You can select your ZFS pool accordingly.<\/p>\n<pre>$ sudo zfs create -o encryption=on -o keylocation=prompt -o keyformat=passphrase test-pool\/encrypted<\/pre>\n<p>You will be asked to enter the passphrase twice. Enter your passphrase and continue.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1172\" height=\"167\" class=\"wp-image-6217\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-446.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-446.png 1172w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-446-300x43.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-446-1024x146.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-446-768x109.png 768w\" sizes=\"auto, (max-width: 1172px) 100vw, 1172px\" \/><\/p>\n<p>A new directory will be created under the storage mount point and anything under this directory will be encrypted. Whenever the system is a reboot, you may need to manually mount the dataset. Remember to use the -l flag when mounting the encrypted dataset. You will be prompted for the passphrase, supply the passphrase you have used to encrypt the pool, and continue.<\/p>\n<pre>$ sudo zfs mount -l test-pool\/encrypted<\/pre>\n<pre>$ df -hT | grep zfs<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"817\" height=\"183\" class=\"wp-image-6218\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-447.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-447.png 817w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-447-300x67.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-447-768x172.png 768w\" sizes=\"auto, (max-width: 817px) 100vw, 817px\" \/><\/p>\n<h2>How to take, roll back and destroy ZFS snapshots<\/h2>\n<h3>Taking the snapshot<\/h3>\n<p>Creating the snapshot in ZFS is quite an easy and straightforward process. You can use the <strong>zfs snapshot<\/strong> command followed by the name of the snapshot as an argument to create a snapshot. In this example, I have used <strong>test-pool\/mysql<\/strong> to create a snapshot. You can choose your pool name and data set accordingly.<\/p>\n<pre>$ sudo zfs snapshot test-pool\/mysql@friday<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"671\" height=\"129\" class=\"wp-image-6219\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-448.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-448.png 671w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-448-300x58.png 300w\" sizes=\"auto, (max-width: 671px) 100vw, 671px\" \/><\/p>\n<p>Verify the snapshot taken using the following command:<\/p>\n<pre>$ zfs list -t snapshot<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"845\" height=\"144\" class=\"wp-image-6220\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-449.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-449.png 845w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-449-300x51.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-449-768x131.png 768w\" sizes=\"auto, (max-width: 845px) 100vw, 845px\" \/><\/p>\n<h3>Renaming the snapshot<\/h3>\n<p>You can also rename the snapshot name using <strong>zfs rename<\/strong> command followed by snapshot name. In this example, snapshot named \u201c<strong>test-tool\/mysql@friday<\/strong>\u201d is renamed to \u201c<strong>test-pool\/mysql@today<\/strong>\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"912\" height=\"161\" class=\"wp-image-6221\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-450.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-450.png 912w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-450-300x53.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-450-768x136.png 768w\" sizes=\"auto, (max-width: 912px) 100vw, 912px\" \/><\/p>\n<h3>Snapshot Rollback<\/h3>\n<p>Snapshot can be rolled back using command <strong>zfs rollback <\/strong>with snapshot name to revert all the changes made since a specific snapshot. In this example, <strong>the test-pool\/mysql<\/strong> file system is rolled back to the sunday snapshot.<\/p>\n<pre>$ sudo zfs rollback test-pool\/mysql@sunday<\/pre>\n<p>Once the rollback is completed, you can verify the files present in the directory.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, I have covered the basic explanation of zfs. We have learned how to create ZFS storage pools, how to destroy the pool, and specify the mount point. Also, we got some basic ideas about zfs pool encryption, the process of taking a snapshot and rolling back the snapshot to the earliest version. Thank you for reading this article. Feedbacks and suggestions will be highly appreciated.<\/p>","protected":false},"excerpt":{"rendered":"<p>ZFS commonly known as Z file system is mainly based on storage and redundancy. The concept of ZFS was developed with file servers in mind where high availability&hellip;<\/p>","protected":false},"author":1,"featured_media":6244,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[100,309],"class_list":["post-6207","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-ubuntu-20-04","tag-zfs"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/6207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=6207"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/6207\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/6244"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=6207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=6207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=6207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}