====== Risky iSCSI Procedures ======
This article covers procedures which I have found to be non-trvial to complete.
==== Resizing your target ====
Ok, you messed up and the target is too small. If you are using LVM2 partitions for your exports (good idea), simply take it offline on the initiators, then add space on the target. Now (and I'm not sure this is required), restart iscsi on the target.
However, I generally use a FreeBSD target (with ZFS on it, setting the targets to Volumes). Following assumes you are using FreeBSD ZFS Volumes for your target, and Devuan (Debian) on your initiator.
Warning: Do not allow anything to access the target during this process. You can probably get by with just shutting down anything which accesses it. Or, for the paranoid amongs us, logout of the target from your initiator, do the work, then log back in.
=== On FreeBSD target ===
# set the new size on the target (assumed to be /storage/iscsi/target in example(
zfs set volsize= storage/iscsi/target
# let ctld know about the change. reload may work instead of restart
service ctld restart
=== On initiator ===
You now need to rescan the target from the initiators. The first example rescans everything, which may not be what you want.
# probably not the best, since it rescans everything.
# see next code block.
iscsiadm -m session --rescan
Better to only scan the one you actually changed. This assumes the target has the substring //thing1// in it.
# find the Session ID of the target in question.
# NOTE: that you can just do iscsiadm -m session for the whole
# list and manually find the SID (number surrounded by square brackets)
iscsiadm -m session -P 0 | grep thing1 | cut -d'[' -f2 | cut -d']' -f 1
# now, rescan only that SID (that one target)
iscsiadm --mode session --sid=15 --rescan
# use any tool you like to check the new size. I use fdisk -l, which will
# return the size on the first line
fdisk -l /dev/disk/by-path/ip-.....
At this point, your size it set correctly (we hope). Now, you need to resize the file system which is different depending on which file system it is. For virtuals, I generally boot from the gparted live CD (https://gparted.org/download.php) to avoid any problems.
==== Remove a target ====
Removing a target is easy; simply remove it from the target, restart openiscsi. However, the initiators still have it in their "database" and you must remove it from there also.
To "clean up" after removing a target, you must log out of the target, then clean up the database. Repeat, you must LOG OUT of the target, THEN clean up the database.
# first, log out of the session
iscsiadm -m node --target='name of target' --portal "ip:port" --logout
# now, do a remove it from the session
iscsiadm -m node --target='name of target' --portal "ip:port" -o delete
What about removing **all** exports from a target, say when you are retiring a complete iSCSI target? That is fairly simple (though you need to log of each individually, I think). If you can shut down the iSCSI initiator, do that, then find the directory/file which contains all the information.
On Debian, it is a directory in /etc/iscsi/send_targets and /etc/iscsi/nodes. Just remove the files/directories. Red Hat appears to use the same thing, but they put the information in /var/lib/iscsi instead of /etc/iscsi.
Once you have removed the directories, you can start up your iSCSI initiator and they will be gone.
You can also do it by logging out of all targets, then issuing some command that I have not been able to figure out. I have to do this soon, so I'll update it after I've done it, but for now, look at the thread at https://groups.google.com/forum/#!topic/open-iscsi/7x28lO6-Rho