unix:linux:iscsi_tricks_and_techniques
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| unix:linux:iscsi_tricks_and_techniques [2016/09/06 19:57] – external edit 127.0.0.1 | unix:linux:iscsi_tricks_and_techniques [2025/11/27 17:15] (current) – [Resizing your target] rodolico | ||
|---|---|---|---|
| Line 22: | Line 22: | ||
| ===== Tricks and Techniques ===== | ===== Tricks and Techniques ===== | ||
| + | |||
| + | ==== Script to update all targets ==== | ||
| + | |||
| + | For some reason, I'm occasionally a little out of sync between what my target offers and what my initiator knows about. The following script will not //remove// anything, but it will add every target offered by the iscsi target. | ||
| + | |||
| + | Add one or more entries into @servers, and it will scan the targets in question, then compare against what our initiator knows, then add any new entries. | ||
| + | |||
| + | <code perl addAlliSCSIS.pl> | ||
| + | #! / | ||
| + | |||
| + | use strict; | ||
| + | use warnings; | ||
| + | |||
| + | # change following to be a list of 1 or more iSCSI targets to be queried | ||
| + | my @servers = ( ' | ||
| + | my %targets; | ||
| + | |||
| + | |||
| + | foreach my $server ( @servers ) { | ||
| + | print " | ||
| + | my @list = `iscsiadm -m discovery -t st -p $server`; | ||
| + | chomp @list; | ||
| + | # @list contains lines of type | ||
| + | # 10.19.209.2: | ||
| + | # split them apart and add them to the hash | ||
| + | | ||
| + | my ( $portal, $targetName ) = split( ' ', $entry ); | ||
| + | # $portal has some extra info after a comma, so clean it up | ||
| + | $portal =~ m/ | ||
| + | $portal = $1; | ||
| + | # some targets return multiple IP's for a given name, so | ||
| + | # only add them if they are in this IP | ||
| + | $targets{ $targetName } = $portal if $portal =~ m/ | ||
| + | print " | ||
| + | } | ||
| + | } | ||
| + | |||
| + | print " | ||
| + | # now, get active sessions so we can filter them | ||
| + | my @activeSessions = `iscsiadm -m session`; | ||
| + | chomp @activeSessions; | ||
| + | foreach my $session ( @activeSessions ) { | ||
| + | | ||
| + | my ( $portal, | ||
| + | print " | ||
| + | if ( exists( $targets{$targetName} ) ) { | ||
| + | print "\tNOT updating\n"; | ||
| + | delete $targets{ $targetName }; | ||
| + | } else { | ||
| + | print "Needs to be added\n"; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | # check if we have any new entries and bail if not | ||
| + | if ( scalar keys %targets ) { | ||
| + | # We have new entries, so run them; | ||
| + | | ||
| + | my $portal = $targets{$targetName}; | ||
| + | print " | ||
| + | `iscsiadm -m node --targetname ' | ||
| + | } | ||
| + | } else { | ||
| + | print "No new entries\n"; | ||
| + | } | ||
| + | # print `ls / | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== Fixing bolluxed machine ==== | ||
| + | |||
| + | Ok, your initiator is in a really bad shape, or you did something on the target you shouldn' | ||
| + | |||
| + | <code bash> | ||
| + | / | ||
| + | rm -fR / | ||
| + | / | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | **Note**: This is on an old Debian Wheezy machine, so start/stop commands are different after that. | ||
| + | |||
| + | The first line stops the initiator. The second line removes all remembered connections from the initiators cache, then we start the initiator again. | ||
| + | |||
| + | At this point, we don't " | ||
| ==== Viewing targets exported from a target device, from the target device ==== | ==== Viewing targets exported from a target device, from the target device ==== | ||
| Line 37: | Line 121: | ||
| </ | </ | ||
| - | Edit / | + | Edit / |
| < | < | ||
| Line 45: | Line 129: | ||
| </ | </ | ||
| Restart iet | Restart iet | ||
| - | <code bash> | + | <code bash>/ |
| + | service ctld reload # FreeBSD | ||
| + | </ | ||
| ==== Adding new target to initiator ==== | ==== Adding new target to initiator ==== | ||
| Line 77: | Line 163: | ||
| 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. | 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. | ||
| - | When you modify | + | However, I generally use a FreeBSD |
| + | |||
| + | <WRAP center round alert 60%> | ||
| + | Warning: Do not allow anything | ||
| + | </ | ||
| + | |||
| + | |||
| + | === On FreeBSD target === | ||
| <code bash> | <code bash> | ||
| - | # log out, then back into target | + | # set the new size on the target |
| - | iscsiadm -m node --target='name of target' --portal " | + | zfs set quota=< |
| + | # let ctld know about the change. reload may work instead | ||
| + | service ctld restart | ||
| </ | </ | ||
| - | The size of the target | + | |
| + | === On initiator === | ||
| + | |||
| + | You now need to rescan the target from the initiators. | ||
| + | <code bash> | ||
| + | # 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. | ||
| + | |||
| + | <code bash> | ||
| + | # find the Session ID of the target | ||
| + | # 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' | ||
| + | # 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-..... | ||
| + | </code> | ||
| + | |||
| + | At this point, | ||
| ==== Remove a target ==== | ==== Remove a target ==== | ||
| Line 92: | Line 211: | ||
| # first, log out of the session | # first, log out of the session | ||
| iscsiadm -m node --target=' | iscsiadm -m node --target=' | ||
| - | # now, do a discovery and delete the entry from your local database | + | # now, do a remove it from the session |
| - | iscsiadm -m discovery | + | iscsiadm -m node --target=' |
| </ | </ | ||
unix/linux/iscsi_tricks_and_techniques.1473209837.txt.gz · Last modified: 2016/09/06 19:57 by 127.0.0.1
