Commit 7522b99532
Unsigned
Layout: unified · split
content/blog/2024-02-06-zfs.md +101 −1
| @@ -35,7 +35,8 @@ zfs-kmod-2.1.5-1ubuntu6~22.04.1 | ||
| 35 | 35 | Now that ZFS is installed, we can create and configure the pool. |
| 36 | 36 | |
| 37 | 37 | You have various options for configuring ZFS pools that all come different pros |
| 38 | and cons. | |
| 38 | and cons. I suggest visiting the links at the top of this post or searching | |
| 39 | online for the best configuration for your use-case. | |
| 39 | 40 | |
| 40 | 41 | - Striped VDEVs (Raid0) |
| 41 | 42 | - Mirrored VDEVs (Raid1) |
| @@ -133,6 +134,13 @@ existing `tank` pool. | ||
| 133 | 134 | sudo zpool add tank mirror /dev/sdX /dev/sdY |
| 134 | 135 | ``` |
| 135 | 136 | |
| 137 | If you're adding disks of different sizes, you'll need to use the `-f` flag. | |
| 138 | Keep in mind that the max size will be limited to the smallest disk added. | |
| 139 | ||
| 140 | ```sh | |
| 141 | sudo zpool add -f tank mirror /dev/sdX /dev/sdY | |
| 142 | ``` | |
| 143 | ||
| 136 | 144 | I added two 8TB hard drives and this process took around 10 seconds to complete. |
| 137 | 145 | |
| 138 | 146 | When viewing the pool again, you can see that the pool has now doubled in size. |
| @@ -147,6 +155,98 @@ tank/cloud 145G 14.3T 145G /tank/cloud | ||
| 147 | 155 | tank/media 96K 14.3T 96K /tank/media |
| 148 | 156 | ``` |
| 149 | 157 | |
| 158 | #### Converting Disks | |
| 159 | ||
| 160 | Some disks, such as NTFS-formatted drives, will need to be partitioned and | |
| 161 | formatted prior to being added to the pool. | |
| 162 | ||
| 163 | Start by identifying the disks you want to format and add to the pool. | |
| 164 | ||
| 165 | ```sh | |
| 166 | sudo fdisk -l | grep /dev | |
| 167 | ``` | |
| 168 | ||
| 169 | I am going to format my `/dev/sdc` and `/dev/sdd` disks with the `fdisk` | |
| 170 | command. | |
| 171 | ||
| 172 | See below for instructions on how to use `fdisk`. Here's what I did to create | |
| 173 | basic Linux formatted disks: | |
| 174 | ||
| 175 | - `g` : Create GPT partition table | |
| 176 | - `n` : Create a new partition, hit Enter for all default options | |
| 177 | - `t` : Change partition type to `20` for `Linux filesystem` | |
| 178 | - `w` : Write the changes to disk and exit | |
| 179 | ||
| 180 | I repeated this process for both disks. | |
| 181 | ||
| 182 | ```sh | |
| 183 | > sudo fdisk /dev/sdc | |
| 184 | ||
| 185 | Welcome to fdisk (util-linux 2.37.2). | |
| 186 | Changes will remain in memory only, until you decide to write them. | |
| 187 | Be careful before using the write command. | |
| 188 | ||
| 189 | This disk is currently in use - repartitioning is probably a bad idea. | |
| 190 | It's recommended to umount all file systems, and swapoff all swap | |
| 191 | partitions on this disk. | |
| 192 | ||
| 193 | ||
| 194 | Command (m for help): m | |
| 195 | ||
| 196 | Help: | |
| 197 | ||
| 198 | GPT | |
| 199 | M enter protective/hybrid MBR | |
| 200 | ||
| 201 | Generic | |
| 202 | d delete a partition | |
| 203 | F list free unpartitioned space | |
| 204 | l list known partition types | |
| 205 | n add a new partition | |
| 206 | p print the partition table | |
| 207 | t change a partition type | |
| 208 | v verify the partition table | |
| 209 | i print information about a partition | |
| 210 | ||
| 211 | Misc | |
| 212 | m print this menu | |
| 213 | x extra functionality (experts only) | |
| 214 | ||
| 215 | Script | |
| 216 | I load disk layout from sfdisk script file | |
| 217 | O dump disk layout to sfdisk script file | |
| 218 | ||
| 219 | Save & Exit | |
| 220 | w write table to disk and exit | |
| 221 | q quit without saving changes | |
| 222 | ||
| 223 | Create a new label | |
| 224 | g create a new empty GPT partition table | |
| 225 | G create a new empty SGI (IRIX) partition table | |
| 226 | o create a new empty DOS partition table | |
| 227 | s create a new empty Sun partition table | |
| 228 | ``` | |
| 229 | ||
| 230 | Once the drives are formatted, we can add these disks to the pool. | |
| 231 | ||
| 232 | ```sh | |
| 233 | sudo zpool add tank mirror /dev/sdc /dev/sdd | |
| 234 | ``` | |
| 235 | ||
| 236 | When we list the pool again, we can see that our size is now updates to | |
| 237 | approximately 22TB. This represents my hard drives totalling 45.6TB when | |
| 238 | shown with `fdisk -l`, with a Raid10 configuration using 22TB for mirroring | |
| 239 | and 22TB of useable space. | |
| 240 | ||
| 241 | ```sh | |
| 242 | > zfs list | |
| 243 | ||
| 244 | NAME USED AVAIL REFER MOUNTPOINT | |
| 245 | tank 145G 21.7T 104K /tank | |
| 246 | tank/cloud 145G 21.7T 145G /tank/cloud | |
| 247 | tank/media 145GT 21.7T 96K /tank/media | |
| 248 | ``` | |
| 249 | ||
| 150 | 250 | ### Creating Datasets |
| 151 | 251 | |
| 152 | 252 | According to [ZFS |