apt install tgt
Create a new target named "target1":
tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2020-01.es.tinaja:target1
Delete a specific target:
tgtadm --lld iscsi --op delete --mode target --tid 1
Add a logical unit to the target:
tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/vdb
Delete a logical unit from the target:
tgtadm --lld iscsi --op delete --mode logicalunit --tid 1 --lun 1
View the targets defined:
tgtadm --lld iscsi --op show --mode target
Enable the target with tid 1 in all the interfaces:
tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL
Or we can just use tgt-admin :)
tgt-admin -h
Include logical units in /etc/tgt/targets.conf or /etc/tgt/conf.d/*.conf as:
include /dev/vdb
Install open-iscsi on the linux client:
apt install open-iscsi
The installation will set up automatically the initiator's name and it'll be stored in /etc/iscsi/initiatorname.iscsi:
## DO NOT EDIT OR REMOVE THIS FILE!
## If you remove this file, the iSCSI daemon will not start.
## If you change the InitiatorName, existing access control lists
## may reject this initiator. The InitiatorName must be unique
## for each iSCSI initiator. Do NOT duplicate iSCSI InitiatorNames.
InitiatorName=iqn.1993-08.org.debian:01:0000000001
We need to discover the targets configured on the iSCSI server (the following command will show a list of all the IQNs of the targets):
iscsiadm --mode discovery --type sendtargets --portal 10.0.0.1[:3260]
And then, we can manually login to a specific target:
iscsiadm --mode node -T iqn.2020-01.es.tinaja:target1 --portal 10.0.0.1 --login
After login to the target a new block device will be available at the initiator system.
If the target is defined with a username and password, they must be defined before login:
iscsiadm --mode node -T iqn.2020-01.es.tinaja:target1 --portal 10.0.0.1 -o update \
-n node.session.auth.username -v username
iscsiadm --mode node -T iqn.2020-01.es.tinaja:target1 --portal 10.0.0.1 -o update \
-n node.session.auth.password -v password
It's also possible to login to all the available targets with -L:
iscsiadm --mode node --portal 10.0.0.1 -L
To display all the current sessions:
iscsiadm -m session
When needed, we can logout from a specific target:
iscsiadm -m node -T iqn.2020-01.es.tinaja:target1 -p 10.0.0.1 -u
Or logout from all the targets:
iscsiadm -m node -p 10.0.0.1 --logout
open-iscsi provides a daemon that takes care of the sessions and will login to the targets after the next reboot.