Commit 300cdf0772

300cdf07720daebd5764f3b0a2dd311e771eb006

parent: 7cdecfad5f

Unsigned

cmc <hello@cleberg.net> · 2024-02-10 04:14 UTC

add zfs post

Layout: unified · split

content/blog/2024-02-06-zfs.md added +219
@@ -0,0 +1,219 @@
1+++
2date = 2024-02-06
3title = "How to Create a ZFS Pool on Ubuntu Linux"
4description = "Learn how to create a simple ZFS pool on Ubuntu Linux."
5+++
6
7This post details the process I used to create ZFS pools, datasets, and
8snapshots on Ubuntu Server.
9
10I found the following pages very helpful while going through this process:
11
12- [Setup a ZFS storage pool](https://ubuntu.com/tutorials/setup-zfs-storage-pool)
13- [Kernel/Reference/ZFS](https://wiki.ubuntu.com/Kernel/Reference/ZFS)
14- [ZFS for Dummies](https://blog.victormendonca.com/2020/11/03/zfs-for-dummies/)
15
16## Installation
17
18To start, I installed the ZFS package with the following command:
19
20```sh
21sudo apt install zfsutils-linux
22```
23
24Once installed, you can check the version to see if it installed correctly.
25
26```sh
27> zsf --version
28
29zfs-2.1.5-1ubuntu6~22.04.2
30zfs-kmod-2.1.5-1ubuntu6~22.04.1
31```
32
33## ZFS Configuration
34
35Now that ZFS is installed, we can create and configure the pool.
36
37You have various options for configuring ZFS pools that all come different pros
38and cons.
39
40- Striped VDEVs (Raid0)
41- Mirrored VDEVs (Raid1)
42- Striped Mirrored VDEVs (Raid10)
43- RAIDz (Raid5)
44- RAIDz2 (Raidd6)
45- RAIDz3
46- Nested RAIDz (Raid50, Raid60)
47
48I will be using Raid10 in this guide. However, the majority of the steps are the
49same regardless of your chosen pool configuration.
50
51### Creating the Pool
52
53To start, let's list the disks available to use. You can use `fdisk` command to
54see all available disks.
55
56```sh
57sudo fdisk -l
58```
59
60Or, if you currently have them mounted, you can use the `df` command to view
61your disks.
62
63```sh
64> sudo df -h
65
66Filesystem Size Used Avail Use% Mounted on
67...
68/dev/sda1 7.3T 28K 6.9T 1% /mnt/red-01
69/dev/sdb1 7.3T 144G 6.8T 3% /mnt/red-02
70/dev/sdc1 7.3T 5.5T 1.9T 75% /mnt/white-02
71/dev/sdd1 9.1T 8.7T 435G 96% /mnt/white-01
72```
73
74If you're going to use mounted disks, make sure to umount them before creating
75the pool.
76
77```sh
78sudo umount /dev/sda1
79sudo umount /dev/sdb1
80```
81
82Now that I've identified the disks I want to use and have them unmounted, let's
83create the pool. For this example, I will call it `tank`.
84
85```sh
86sudo zpool create -f -m /mnt/pool tank mirror /dev/sda /dev/sdb
87```
88
89See below for the results of the new ZFS pool named `tank`, with a vdev
90automatically named `mirror-0`.
91
92```sh
93> zfs list
94
95NAME USED AVAIL REFER MOUNTPOINT
96tank 396K 7.14T 96K /tank
97```
98
99```sh
100> zpool status
101
102 pool: tank
103 state: ONLINE
104config:
105
106 NAME STATE READ WRITE CKSUM
107 tank ONLINE 0 0 0
108 mirror-0 ONLINE 0 0 0
109 sda ONLINE 0 0 0
110 sdb ONLINE 0 0 0
111
112errors: No known data errors
113```
114
115We can also look at the mounted filesystem to see where the pool is mounted and
116some quick stats.
117
118```sh
119> df -h
120
121Filesystem Size Used Avail Use% Mounted on
122...
123tank 7.2T 128K 7.2T 1% /tank
124```
125
126### Expanding the Pool
127
128If you want to expand this pool, you will need to add a new VDEV to the pool.
129Since I am using 2 disks per VDEV, I will need to add a new 2-disk VDEV to the
130existing `tank` pool.
131
132```sh
133sudo zpool add tank mirror /dev/sdX /dev/sdY
134```
135
136I added two 8TB hard drives and this process took around 10 seconds to complete.
137
138When viewing the pool again, you can see that the pool has now doubled in size.
139We have 14.3 TB useable space and the same space used for mirroring.
140
141```sh
142> zfs list
143
144NAME USED AVAIL REFER MOUNTPOINT
145tank 145G 14.3T 104K /tank
146tank/cloud 145G 14.3T 145G /tank/cloud
147tank/media 96K 14.3T 96K /tank/media
148```
149
150### Creating Datasets
151
152According to [ZFS
153Terminology](https://docs.oracle.com/cd/E18752_01/html/819-5461/ftyue.html), a
154`dataset` can refer to "clones, file systems, snapshots, and volumes.
155
156For this guide, I will use the `dataset` term to refer to file systems created
157under a pool.
158
159Within my `tank` pool, I am going to create some datasets to help organize my
160files. This will give me location to store data rather than simply dumping
161everything at the `/tank/` location.
162
163```sh
164sudo zfs create tank/cloud
165sudo zfs create tank/media
166```
167
168Once created, you can see these datasets in the output of your pool list:
169
170```sh
171> zfs list
172NAME USED AVAIL REFER MOUNTPOINT
173tank 752K 7.14T 104K /tank
174tank/cloud 96K 7.14T 96K /tank/cloud
175tank/media 96K 7.14T 96K /tank/media
176```
177
178### Creating Snapshots
179
180Next, let's create our first snapshot. We can do this by calling the `snapshot`
181command and give it an output name. I will be throwing the current date and time
182into my example.
183
184```sh
185sudo zfs snapshot tank@$(date '+%Y-%m-%d_%H-%M')
186```
187
188We can list the snapshots in our pool with the following command:
189
190```sh
191> zfs list -t snapshot
192NAME USED AVAIL REFER MOUNTPOINT
193tank@2024-02-06_19-41 0B - 104K -
194```
195
196### Destroy Snapshots
197
198You can always destroy snapshots that are no longer needed:
199
200```sh
201sudo zfs destroy tank@2024-02-06_19-41
202```
203
204Once deleted, they will no longer appear in the list:
205
206```sh
207> zfs list -t snapshot
208no datasets available
209```
210
211## My Thoughts on ZFS So Far
212
213- I sacrificed 25TB to be able to mirror my data, but I feel more comfortable
214 with the potential to save my data by quickly replacing a disk if I need to.
215- The set-up was surprisingly easy and fast.
216- Disk I/O is fast as well. I was worried that the data transfer speeds would be
217 slower due to the RAID configuration.
218- Media streaming and transcoding has seen no noticeable drop in performance.
219- My only limitation really is the number of HDD bays in my server HDD cage.