s35. Prepare new or pre-used drives for ZFS use

What follows is valid also for non ZFS filesystems. Only, we do not want to deal with non-ZFS.

New drives sometimes fail immediately (DOA = Dead on arrival), sometimes they fail after a few weeks, or months of usage.

Since it is quite laborious to install, prepare and resilver them, it would be better to stress-test each new drive.

If a new drive will fail the stress-test, it should be sent back.

Stress-test app can be found also on OS X: just use diskutil, or, better, Drive Genius.


# Erase old partition scheme
############################
# Always makes sure any old info is erased, as ZFS could pick up something,
# and try really hard to recover it.

# On FreeBSD, use gpart and remove the partition table.
# On Linux:

$ ll /dev/disk/by-id

[…]
lrwxrwxrwx 1 root root   9 Dec 20 17:29 ata-WDC_WD60EFRX-68L0BN1_WD-WX41D95PAHV2 -> ../../sdc
lrwxrwxrwx 1 root root   9 Dec 20 17:29 ata-WDC_WD60EFRX-68L0BN1_WD-WX41D95PASRY -> ../../sdb
lrwxrwxrwx 1 root root   9 Dec 20 17:29 ata-WDC_WD60EFRX-68MYMN1_WD-WX11D557YNXY -> ../../sda
lrwxrwxrwx 1 root root   9 Dec 20 17:25 ata-WDC_WD60EFRX-68MYMN1_WD-WX41D94RNKXL -> ../../sde
$ sudo dd if=/dev/zero of=/dev/sda bs=1G count=1
$ sudo dd if=/dev/zero of=/dev/sdb bs=1G count=1
$ sudo dd if=/dev/zero of=/dev/sdc bs=1G count=1
$ sudo dd if=/dev/zero of=/dev/sde bs=1G count=1

# General recommendations
#########################

# Following http://open-zfs.org/wiki/Performance_tuning#General_recommendations
# 1. Use whole disks
# 2. Use ashift=12 where proper
# 3. Use compression=lz4 at root level, even for uncompressible media

# Having four identical disks, I prefer to have a stripe of two RAID 1 mirrors - RAID 1+0, with a capacity of TWO disks.
# I agree with  http://serverfault.com/a/431357 that is a good balance.

$ sudo zpool create -m none -o ashift=12 tank mirror ata-WDC_WD60EFRX-68MYMN1_WD-WX11D557YNXY ata-WDC_WD60EFRX-68L0BN1_WD-WX41D95PASRY mirror ata-WDC_WD60EFRX-68L0BN1_WD-WX41D95PAHV2 ata-WDC_WD60EFRX-68MYMN1_WD-WX41D94RNKXL

# Note: The line above may still need the -f switch, notwithstanding the dd command above, if zfs picks up fragments of the previous boot partition.

# Check results
###############

$ sudo zpool status
  pool: tank
 state: ONLINE
  scan: none requested
config:
    NAME                                          STATE     READ WRITE CKSUM
    tank                                          ONLINE       0     0     0
      mirror-0                                    ONLINE       0     0     0
	ata-WDC_WD60EFRX-68MYMN1_WD-WX11D557YNXY  ONLINE       0     0     0
	ata-WDC_WD60EFRX-68L0BN1_WD-WX41D95PASRY  ONLINE       0     0     0
      mirror-1                                    ONLINE       0     0     0
	ata-WDC_WD60EFRX-68L0BN1_WD-WX41D95PAHV2  ONLINE       0     0     0
	ata-WDC_WD60EFRX-68MYMN1_WD-WX41D94RNKXL  ONLINE       0     0     0
errors: No known data errors

# Initial  optimisations
########################

# Disable atime for a small I/O boost
$ sudo zfs set atime=off tank

# Set compression
$ zfs set compression=lz4

# check results
###############

$ sudo zfs get all

NAME  PROPERTY              VALUE                  SOURCE
tank  type                  filesystem             -
tank  creation              Sun Dec 20 18:03 2015  -
tank  used                  300K                   -
tank  available             10,5T                  -
tank  referenced            96K                    -
tank  compressratio         1.00x                  -
tank  mounted               no                     -
tank  quota                 none                   default
tank  reservation           none                   default
tank  recordsize            128K                   default
tank  mountpoint            none                   local
tank  sharenfs              off                    default
tank  checksum              on                     default
tank  compression           lz4                    local
tank  atime                 off                    local
tank  devices               on                     default
tank  exec                  on                     default
tank  setuid                on                     default
tank  readonly              off                    default
tank  zoned                 off                    default
tank  snapdir               hidden                 default
tank  aclinherit            restricted             default
tank  canmount              on                     default
tank  xattr                 on                     default
tank  copies                1                      default
tank  version               5                      -
tank  utf8only              off                    -
tank  normalization         none                   -
tank  casesensitivity       sensitive              -
tank  vscan                 off                    default
tank  nbmand                off                    default
tank  sharesmb              off                    default
tank  refquota              none                   default
tank  refreservation        none                   default
tank  primarycache          all                    default
tank  secondarycache        all                    default
tank  usedbysnapshots       0                      -
tank  usedbydataset         96K                    -
tank  usedbychildren        204K                   -
tank  usedbyrefreservation  0                      -
tank  logbias               latency                default
tank  dedup                 off                    default
tank  mlslabel              none                   default
tank  sync                  standard               default
tank  refcompressratio      1.00x                  -
tank  written               96K                    -
tank  logicalused           92,5K                  -
tank  logicalreferenced     40K                    -
tank  filesystem_limit      none                   default
tank  snapshot_limit        none                   default
tank  filesystem_count      none                   default
tank  snapshot_count        none                   default
tank  snapdev               hidden                 default
tank  acltype               off                    default
tank  context               none                   default
tank  fscontext             none                   default
tank  defcontext            none                   default
tank  rootcontext           none                   default
tank  relatime              off                    default
tank  redundant_metadata    all                    default
tank  overlay               off                    default

# Create filesystems as needed
##############################

$ sudo zfs create tank/vault
$ sudo zfs set mountpoint=/mnt/vault tank/vault

$ sudo zfs create tank/archive
$ sudo zfs set mountpoint=/mnt/archive tank/archive

$ sudo zfs create tank/store
$ sudo zfs set mountpoint=/mnt/store tank/store

$ sudo zfs list

NAME           USED  AVAIL  REFER  MOUNTPOINT
tank           684K  10,5T    96K  none
tank/archive    96K  10,5T    96K  /mnt/archive
tank/store      96K  10,5T    96K  /mnt/store
tank/vault      96K  10,5T    96K  /mnt/vault

# Various notes
###############

# To check ashift (it is now automatic)
zdb | grep ashift

# List all properties
zdb

# To destroy zpool
$ zpool destroy tank

# if needed, in the above use -F flag (in case it was in used elsewhere)


[s35. Prepare new or pre-used drives for ZFS use, last update 2017-12-06]