Main Contents

Restart iSCSI Target in Linux Gracefully

February 21, 2011

Anyone using iSCSI targets in Linux may have discovered what I have - restarting iscsi services causes a disconnect of all the attached initiators. This is true with the scsi-target-utils or the iscsitarget (IET) packages. I typically use an LVM logical volume for iSCSI LUN’s. Occasionally I need to resize them, but the client doesn’t see the new size until a restart. I discovered a better way to do this, which doesn’t disconnect any initiator clients in the process. You need to use the ietadm tool (or tgtadm) and manually delete the LUN and add it back in. Don’t worry - the delete command doesn’t actually delete the block device or any data, just deletes it from the target’s memory. After resizing the LUN with lvextend, determine the tid and lun you need to update:

tgtadm --op show --mode target

or using IET:

cat /proc/net/iet/volume

WARNING: you should stop all IO if possible before continuing. With heavy IO, you can be sure the LUN won’t re-attach, and it may not even detach. I’ve had tgtd crash on me. On SQL, make sure DB’s are not in use. On Hyper-V, just pause or shut down all the VM’s - I’ve never had it work otherwise. If the LUN doesn’t re-attach, use iSCSI Initiator tool in Windows and add a new connection to attach it. Moving on…
Then, to update the LUN with the new size, delete it and add it back using the information above, like this:

tgtadm --mode logicalunit --op delete --tid=2 --lun=1 && tgtadm --mode logicalunit --op new --tid=2 --lun=1 --backing-store=/dev/vg01/vol1

or with IET:

ietadm --op delete --tid=2 --lun=1 && ietadm --op new --tid=2 --lun=1 --params Path=/dev/vg01/vol1,Type=blockio

Remember, if you make any actual changes to the LUN’s besides resizing, you’ll need to update ietd.conf or targets.conf so the changes are remembered on a restart.

Filed under: Linux, Microsoft, Windows |

Sorry, the comment form is closed at this time.