11. Storage exercises with mdadm and zfs

11.1. Create volume with 3 drives via mdadm.

Install the package for mdraid on the node:

apt install mdadm

See available drives on your system:

lsblk

output:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0 447.1G  0 disk
sdb      8:16   0 447.1G  0 disk
sdc      8:32   0 447.1G  0 disk
├─sdc1   8:33   0   512M  0 part /boot/efi
├─sdc2   8:34   0 445.7G  0 part /
└─sdc3   8:35   0   977M  0 part [SWAP]
sdd      8:48   0 447.1G  0 disk
sr0     11:0    1   738M  0 rom

Pickup unpartitioned drives: sda, sdb, sdd in this case

Wipe out the superblock on the drives:

mdadm --zero-superblock --force  /dev/sda /dev/sdb /dev/sdd

If the drives were never configured with mdadm:

output:

mdadm: Unrecognised md component device - /dev/sda
mdadm: Unrecognised md component device - /dev/sdb
mdadm: Unrecognised md component device - /dev/sdd

Create /dev/md0 raid level #5 with the 3 drives:

mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sda /dev/sdb /dev/sdd

Monitor the status of device /dev/md0:

mdadm -D /dev/md0

or

cat /proc/mdstat

finally the raid volume is created:

Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdd[3] sdb[1] sda[0]
      937438208 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
      bitmap: 0/4 pages [0KB], 65536KB chunk

unused devices: <none>

11.2. Create and mount exdt4 file system.

Create ext4 file system on /dev/md0:

mkfs.ext4 /dev/md0

Create mounting point:

mkdir /scratch

Mount the file system onto /scratch:

mount /dev/md0  /scratch

verify that the file system is mounted:

df -h

11.3. Destroy the current pool.

umount /scratch
mdadm --stop /dev/md0
mdadm --remove /dev/md0

Clear the drives:

mdadm --zero-superblock --force /dev/sda /dev/sdb /dev/sdd

11.4. ZFS installation

sudo -s
apt install -y software-properties-common
apt-add-repository contrib
apt update
apt upgrade
apt install zfsutils-linux zfs-dkms zfs-zed

11.5. Load module zfs.ko

modprobe zfs

11.6. Create volume.

lsblk

See available drives: /dev/sda, /dev/sdb, /dev/sdd.

Create zpool (volume):

zpool create -f tank  sda sdb sdd

11.7. Create the file system:

zfs create tank/scratch

Check

df -h

It is mounted:

/tank/scratch

11.8. Remove the volume.

zpool destroy tank