iSCSI allows to share a block device (i.e. a hard drive) at the block level, basically giving full control of partitions and filesystem to the client connected to it. Due to its design, only a single client can connect to it at a time. It's mostly used to provide network storage for commercial application and appliances that lack advanced storage options (RAID), usually VMWare ESXi (virtualization host) but there are others.

On OpenWrt 19.07 there is support only for iSCSI targets (i.e. the OpenWrt device can share its storage with iSCSI), support for iSCSI initiators (i.e. connecting to a iSCSI target to access its shared storage) is implemented in this PR and is available in snapshots only.

install package tgt and kmod-scsi-core

The documentation for the tools used is here although it is not strictly necessary to read it for a basic setup.

Open the uci config file with a text editor to see the comments and edit it. Most options are self-explanatory or explained by the comments inside.

Let's see what is in this file:

config options 'tgt'
# iothreads limits number of worker threads per rdwr target, default is 16
# which seems to be too much for an avarage router
	option iothreads '2'
#	option nop_count '3'
#	option nop_interval '1'
#	option logging '0'
#	list portal '[::1]'
#	list portal ''
#	list portal ''
#	list portal '[::]:3263'

config target 1
	option name ''
#	list allow_name ''
#	list allow_address ''

#config target 2
#	option name ''

# all options are set to default, except for the device
# lun "name" is constructed as TGTID_LUN
#config lun                        1_1
#	option 'device' '/dev/sda'
# type of scsi device. available options: disk, cd, pt (sg passthrough)
#	option 'type' 'disk'
# backing store access method: rdwr (read-write), aio (async IO), sg (for pt type only, device must be /dev/sgN)
#	option 'bstype' 'aio'
# set sync and/or direct flags when opening device, affect only rdwr
#	option 'sync' '0'
#	option 'direct' '0'
# block size for lun, default is 512
#	option 'blocksize' 4096
# override SCSI mode page, see tgtadm man page for details
#	option 'mode_page' 'string'
# vendor, product, revision, SCSI ID and SCSI Serial number
#	option 'vendor_id' 'string'
#	option 'product_id' 'string'
#	option 'product_rev' 'string'
#	option 'scsi_id' 'string'
#	option 'scsi_sn' 'string'
# refuse write attempts. applies only to disk type
#	option 'readonly' '0'
# Disk devices default to non-removable, cd - to removable
#	option 'removable' '0'
#  0 = Classic sense format, 1 = Support descriptor format.
#	option 'sense_format' '0'
# Rotaion rate: 0: not reported, 1: non-rotational medium (SSD), 2-1024: reserverd, 1025+: "Nominal rotation rate"
#	option 'rotation_rate' '0'

#config lun 2_1
#	option device /mnt/iscsi.img

#config lun 2_2
#	option device /dev/sdc

#config account
#	list target 1
#	list target 2
#	option user "username1"
#	option password "pass1"

#config account
#	option target 2
#	option user "user2"
#	option password "pwd2"
#	option outgoing 1

It's better to not delete all comments as they are useful information, but here I don't want to waste space in the wiki so I will provide a short and basic example setup where I am using /dev/sda as the iSCSI drive, as the name, and a user/password set up to have some limited security (it's better to set the “allow_name” and “allow_address” options too to limit access only to your iSCSI client if you want more security)

config options 'tgt'
	option iothreads '2'
config target 1
	option name ''

config lun                        1_1
	option 'device' '/dev/sda'

config account
	list target 1
	option user "username"
	option password "pass"

After you changed the config, restart tgt with service tgt restart. Your iSCSI target is ready.

How to connect to this iSCSI target will be explained in the documentation of the appliance or application or device you want to connect. It will usually involve this iSCSI device name and it's IP address, and the default iSCSI port 3260.

Testing this config on a Zyxel NSA310b (single core ARMv5 device with 256MB RAM) with a normal 3,5'' hard drive provides around 20-30MB/s of performance and loads the CPU to the max. More powerful devices will fare better.

As noted in the comments in the config file, if your device is more powerful you can increase the option iothreads '2'. You can check CPU utilization by installing and executing htop tool.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2021/01/02 23:44
  • by patrakov