* Home :: Get a random password :: Get a multi-word password :: What is my IP? (v4 | v6)
* My projects

Quick and dirty tutorial on how to export an ISCSI volume with targetcli

Tags: howto,iscsi

Date: 20260306

Updated: 20260306



I need to do this semi-often, so here's a copy/paste tutorial for my future self.

Usually I add another disk to a VM and work on that, so I'll assume you have a disk at /dev/sdb available - replace below accordingly if it shows up as /dev/vdb or /dev/xvdb etc etc.
SECURITY: Please note I disable authentication, so any network host which can access my ISCSI server can mount this volume!!

# install targetcli, example is for (RH)EL, replace "dnf" with "apt" if 
on Debian
dnf install targetcli -y

# start it and enable it at boot
systemctl enable --now target

# configure it to export /dev/sdb via iscsi protocol - what follows is an interactive shell, but it can also be configured from stdin or via direct commands if you are looking to automate it.
targetcli

# you're now in the targetcli shell, the following commands apply to it until noted otherwise
backstores/block create name=disk1 dev=/dev/sdb
iscsi/ create iqn.3000-01.local.iscsi:storage.sdb
iscsi/iqn.3000-01.local.iscsi:storage.sdb/tpg1/luns create /backstores/block/disk1
iscsi/iqn.3000-01.local.iscsi:storage.sdb/tpg1 set attribute generate_node_acls=1
iscsi/iqn.3000-01.local.iscsi:storage.sdb/tpg1 set attribute authentication=0
iscsi/iqn.3000-01.local.iscsi:storage.sdb/tpg1 set attribute demo_mode_write_protect=0
saveconfig
exit

# you have now exited the targetcli shell and are back into your regular linux shell
        

On the client side, you need to do the following:

# install the required software
dnf -y install iscsi-initiator-utils

# discover the ISCSI volumes
iscsiadm -m discovery -t sendtargets -p IPofStorageServer

# output should look like this:
# 10.0.35.92:3260,1 iqn.3000-01.local.iscsi:storage.sdb

# "login", after this step you should see a new drive attached to your machine, this usually shows up in `dmesg`
iscsiadm -m node -l

# output should look like this:
# Login to [iface: default, target: iqn.3000-01.local.iscsi:storage.sdb, portal: 10.0.35.92,3260] successful.
        

That's it, you're done. Do what you need with your new drive.

(c)The Nux(tm) ;-)

No CSS, no Javascript, no some HTML.
No ads, no tracking, no cookies.


Optimised for Dillo browser, great in Lynx, too :)