Skip to main content
Skip table of contents

Step 2: Creating a ZFS storage pool

In this step we will take the virtual hard drives that we created in Step 1 and convert them into a ZFS Storage Pool.

  1. Reconnect to the VM:

    From terminal

    BASH
    ./run xnat-21 ssh
  2. Become root:

    BASH
    sudo -i
  3. List disks:

    BASH
    root@xnat-21:~# fdisk -l
    Disk /dev/sda: 68.7 GB, 68719476736 bytes
    255 heads, 63 sectors/track, 8354 cylinders, total 134217728 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x0004f458
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048      499711      248832   83  Linux
    /dev/sda2          501758   134215679    66856961    5  Extended
    /dev/sda5          501760   134215679    66856960   8e  Linux LVM
    Disk /dev/sdb: 25.8 GB, 25769803776 bytes
    255 heads, 63 sectors/track, 3133 cylinders, total 50331648 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    Disk /dev/sdb doesn't contain a valid partition table
    Disk /dev/sdc: 8589 MB, 8589934592 bytes
    255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    Disk /dev/sdc doesn't contain a valid partition table
    Disk /dev/sdd: 8589 MB, 8589934592 bytes
    255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    Disk /dev/sdd doesn't contain a valid partition table
    Disk /dev/sde: 8589 MB, 8589934592 bytes
    255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    Disk /dev/sde doesn't contain a valid partition table
    Disk /dev/mapper/vagrant--vg-root: 67.9 GB, 67922558976 bytes
    255 heads, 63 sectors/track, 8257 cylinders, total 132661248 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    Disk /dev/mapper/vagrant--vg-root doesn't contain a valid partition table
    Disk /dev/mapper/vagrant--vg-swap_1: 536 MB, 536870912 bytes
    255 heads, 63 sectors/track, 65 cylinders, total 1048576 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    Disk /dev/mapper/vagrant--vg-swap_1 doesn't contain a valid partition table
    

    Our new disks are at /dev/sdb/dev/sdc/dev/sdd, and /dev/sde

    /dev/sdb: 25.8 GB

    Disk sdb is larger than the other 3. This is to accommodate non-SSD users. Explanation in the next step.


  4. Create a ZFS pool:

    SSD Users

    BASH
    zpool create -f tank raidz1 sdb sdc sdd sde

    Spinning Disk Users

    BASH
    zpool create -f tank sdb

    Spinning Disk Users

    If your workstation/laptop does not have an SSD, do not use raidz1, this pool will become painfully slow. Your pool will be the same size as the raidz1 setup. In the raidz1 setup only 8GB of the first disk will be used by ZFS.

    If you do not know the disk type of your workstation used the spinning disk command.

  5. Confirm the pool is created:

    BASH
    root@xnat-21:~# zpool list
    NAME   SIZE  ALLOC   FREE  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
    tank  31.8G   112K  31.7G         -     0%     0%  1.00x  ONLINE  -
    
    The size of the pool may not be exactly the same.

    ZFS Redundancy

    We have created a virtual pool with raidz1 redundancy. However, this redundancy is virtual and still on a single disk. So why bother? We have actually protected our data from bit rot on a single disk. Should a sector become bad ZFS will detect it and repair it with the redundant virtual disks. Raidz1 is similar to RAID5, there is one parity sector for each stripe. However, raidz is not laid out like typical raid5, it does not always write to all the disks in a stripe. If there is only one sector it will write one data sector and one parity sector. A more detailed explanation is on Wikipedia: https://en.wikipedia.org/wiki/ZFS#RAID

  6. Set some pool defaults:

    BASH
    zfs set compression=lz4 tank
    zfs set sync=disabled tank                # Typically, we would not do this for a production pool.  It risks about 5 seconds of data loss.
    zfs set primarycache=metadata tank        # This VM doesn't have much memory, let's cache what's most important.

    ZFS Compression

    We are using lz4 compression on all of our data. LZ4 is a light weight compression that is typically about 80-90% as effective at compressing data as gzip. However, it is very easy on the CPU and in almost all cases our pool will actually perform faster with LZ4 compression than no compression at all. XNAT data typically will get compressed about 20% with LZ4 compression.

  7. Limit ZFS memory usage.
    This is only necessary on a system with limited RAM such as our xnatdev VM.   Typically ZFS will be run a dedicated server and be allowed to use all available RAM.   In this case we are allocating 1/4 of our total RAM to ZFS.  If you've given your VM more RAM adjust as you like.
    Production ZFS servers typically start at 16gb RAM and in some cases over 1TB RAM.   With only small fraction of that RAM, ZFS will not perform anywhere near its potential on this VM.   

    BASH
    echo "options zfs zfs_arc_max=536870912" >> /etc/modprobe.d/zfs.conf
    echo "536870912" > /sys/module/zfs/parameters/zfs_arc_max

 

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.