Distroname and release: Debian Buster

ISCSI and ZFS ZVOL

An short guide for using an ZVOL as ISCSI storage device.

The ISCSI setup consists of an Server (ISCSI Target), and client (ISCSI Initiator)
Prerequisite: The ZVOL must exist already.

ISCSI Target (Server)

There are multiple options for the ISCSI target, but we will be use using LIO (kernel space).

Install targecli and iscsi client tools. Client tools is not required, but nice to have to debug (open-iscsi)

 apt-get install targetcli-fb open-iscsi
Now we can use the targecli CLI.

Create the backstore blockdevice! We will be using the already created ZVOL here! (Notice the path, we are using).

targetcli
> cd /backstores/block
/backstores/block> create block1 /dev/zvol/DATA/zvol_workstation 
Created block storage object block1 using /dev/zvol/DATA/zvol_workstation.
Create the iSCSI Qualified NAME (IQN), still using the targetcli interface. See think link for IQN clarification.
If you are lazy, just use "create" without arguments.
> cd /iscsi/
/iscsi/> create iqn.2019-10.local.linuxlasse.iscsi:storage01
Now the IQN is created, we need to create an LUN on the previously created backstore, and again in the tagetcli interface.
 cd /iscsi/iqn.2019-10.local.linuxlasse.iscsi:storage01/tpg1/luns 
 /iscsi/iqn.20...e01/tpg1/luns> create /backstores/block/block1
You must create an ACL for each client that needs to connect.
On linux initiator , find the initiatorname, like so! (requires open-iscsi tools):
grep ^InitiatorName /etc/iscsi/initiatorname.iscsi 
InitiatorName=iqn.1993-08.org.debian:01:3e1beb39d22e
(New names can be generated with the iscsi-iname command) Then in the targetcli interface, create the acesslist.
> cd /iscsi/iqn.2019-10.local.linuxlasse.iscsi:storage01/tpg1/acls
> create iqn.1993-08.org.debian:01:3e1beb39d22e

ISCSI Client ( initiator )

If not already installed on the client.
apt-get install open-iscsi
Discover available targets, can be done like so.
 iscsiadm -m discovery -t sendtargets -p 192.168.10.11
 192.168.10.11:3260,1 iqn.2019-10.local.linuxlasse.iscsi:storage01

Connect to the ISCSI blockdevice

iscsiadm --mode node --targetname iqn.2019-10.local.linuxlasse.iscsi:storage01 --portal 192.168.10.11:3260 --login Looking in /var/log/messages should show attached scsi.
 grep Attached /var/log/messages
Oct  9 15:14:42 prodigy kernel: [2176700.847504] sd 9:0:0:0: Attached scsi generic sg10 type 0
Oct  9 15:14:42 prodigy kernel: [2176700.853664] sd 9:0:0:0: [sdk] Attached SCSI disk
Done, now you can use this as an normal disk, now format it with fdisk/cfdisk/parted or whatever.

You can disconnect the ISCSI device from the initiator like so.

iscsiadm --mode node --targetname iqn.2019-10.local.linuxlasse.iscsi:storage01 --portal 192.168.10.11:3260 --logout

Other info, and commands

Restrict IP subnet of the Target Portal Group (TPG)

This will make ISCSI initiator only listen on an specific IP.
>cd /iscsi/iqn.2019-10.local.linuxlasse.iscsi:storage01/tpg1/portals
>ls
o- portals ................................................................................... [Portals: 1]
  o- 0.0.0.0:3260 .................................................................................... [OK]
Now delete the listen address scope, and assign the local IP of the initiator (server)
delete ip_address=0.0.0.0 ip_port=3260
Deleted network portal 0.0.0.0:3260
/iscsi/iqn.20.../tpg1/portals> ls
o- portals ................................................................................... [Portals: 0]
/iscsi/iqn.20.../tpg1/portals> create ip_address=192.168.10.11 ip_port=3260
Using default IP port 3260
Created network portal 192.168.10.11:3260.
/iscsi/iqn.20.../tpg1/portals> ls
o- portals ................................................................................... [Portals: 1]
  o- 192.168.10.11:3260 .............................................................................. [OK]

Saving configs!

Notes, that configs, is always saved in memory, nomatter if autosave is set or not.
The autosave function is for saving to the config file or not!
Per default, the config is "auto" saved to "/etc/rtslib-fb-target/saveconfig.json when you exit, you can change this behaviour if you wish, and then save manually, or save manually as you work.
Using the tagetcli again
targetcli
>cd /
>set global auto_save_on_exit=false
>saveconfig

Restores

Restore can then be done with "restoreconfig" command from targetcli.
Do not trust the authors words! POC, tests and experience is key

Copyright LinuxLasse.net 2009 - 2019 All Rights Reserved.

Valid HTML 4.01 Strict Valid CSS!