Export ZFS Volume to iSCSI

To export a raw block volume from ZFS for use with iSCSI, you can use the zfs command to create a block device and then use the tgtadm command to create an iSCSI target and add the block device as a logical unit (LUN). Here's an example of the steps you can follow:

  1. Create a block device using the zfs command. For example:
zfs create -V 10G -b $(getconf PAGESIZE) -o compression=off -o sync=always tank/iscsi/volume

This creates a 10 GB block device with the default page size and disables compression and sets sync to always. You can adjust the size and other options as needed.

2.  Set the permissions on the block device so that it can be accessed by the iSCSI initiator. For example:

chmod 666 /dev/zvol/tank/iscsi/volume

3. Install and configure the iSCSI target daemon (tgt). On Debian-based systems, you can use the following command to install tgt:

apt-get install tgt

4.  Create an iSCSI target and add the block device as a LUN. First, create a configuration file for the target in the /etc/tgt/conf.d directory. For example, you can create a file called my_iscsi_target.conf with the following contents:

<target my_iscsi_target>
    backing-store /dev/zvol/tank/iscsi/volume
</target>

Then, use the tgtadm command to add the target and LUN

tgtadm --lld iscsi --op new --mode target --tid 1 -T my_iscsi_target
tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/zvol/tank/iscsi/volume

5.  Start the iSCSI target daemon:

service tgt start

6. On the iSCSI initiator, use the iscsiadm command to discover and log in to the target.

iscsiadm -m discovery -t st -p <target_ip_address>:3260
iscsiadm -m node -T my_iscsi_target -p <target_ip_address>:3260 -l

7. Once the initiator is logged in, the block device should be available for use. You can check for the device using the lsblk command or by looking in the /dev directory.

Note: These are just examples of the commands you can use. You may need to adjust the commands and options based on your specific system and configuration.

Do you have any question to us?

Contact us and we'll get back to you as soon as possible.