Ubuntu 16.04: Share ZFS storage via NFS/SMB

This article will describe how to create ZFS storage pool and share storage via NFS/SMB.

 

1 Install zfsutils-linux

zfsutils-linux is a ZFS userland tools.

$ sudo apt-get install -y zfsutils-linux

2 Load zfs.ko

zfs.ko is ZFS device driver.

$ sudo modprobe zfs

3 Create storage pool

Create storage pool with using /dev/vdb and naming tank.

$ sudo zpool create -f tank /dev/vdb
$ sudo zpool list
NAME   SIZE  ALLOC   FREE  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
tank  79.5G    50K  79.5G         -     0%     0%  1.00x  ONLINE  -

/tank is created.

$ ls /
bin    dev   initrd.img  lost+found  opt   run   srv   tmp  vmlinuz
boot   etc   lib         media       proc  sbin  sys   usr
cdrom  home  lib64       mnt         root  snap  tank  var
$ df -h /tank
Filesystem      Size  Used Avail Use% Mounted on
tank             78G     0   78G   0% /tank

Now you can use /tank as ZFS file system.

4 Share via NFS

Instal NFS server. No need to edit /etc/exports and run exportfs.

$ sudo apt-get install -y nfs-kernel-server

Now share storage pool via NFS.

Below command will provide writable storage to 192.168.11.0/24 network.

$ sudo zfs set sharenfs="rw=@192.168.11.0/24" tank

NFS mount from 192.168.0.24 network.

IP address of server running ZFS storage pool is 192.168.11.67.

$ sudo mount -t nfs 192.168.11.67:/tank /mnt

5 Share via SMB

Install samba.

sudo apt-get install -y samba

In the case of SMB, it needs to edit /etc/samba/smb.conf.

This article will disable guest access and allow user which is added by pdbedit.

/var/lib/samba/usershares is created by zfs command.

$ diff -uprN /etc/samba/smb.conf{.org,}
--- /etc/samba/smb.conf.org     2016-04-30 20:46:35.778323625 +0900
+++ /etc/samba/smb.conf 2016-04-30 20:48:23.866009451 +0900
@@ -177,13 +177,14 @@

 # Setup usershare options to enable non-root users to share folders
 # with the net usershare command.
+   usershare path = /var/lib/samba/usershares

 # Maximum number of usershare. 0 (default) means that usershare is
 # disabled.
-;   usershare max shares = 100
+   usershare max shares = 100

 # Allow users who've been granted usershare privileges to create
 # public shares, not just authenticated ones
-   usershare allow guests = yes
+   usershare allow guests = no

 #======================= Share Definitions =======================

Add user with pdbedit.

$ sudo pdbedit -a hiroom2
new password:
retype new password:

Share storage pool via SMB with zfs command.

User can only read to /tank because of /tank permission.

If you need to write /tank, please chmod /tank.

$ sudo zfs set sharesmb=on tank

Access \\ubuntu-16.04-zfs.hiroom2.com\tank from windows machine and display username/password dialog.

ubuntu-16.04-zfs.hiroom2.com is name of server running ZFS storage pool.

0001_Access-to-ZFS-via-SMB-on-Windows.png