A service of Daily Data, Inc.
Contact Form

User Tools

Site Tools


unix:linux:iscsi_tricks_and_techniques

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
unix:linux:iscsi_tricks_and_techniques [2019/08/14 19:43] rodolicounix:linux:iscsi_tricks_and_techniques [2025/11/27 17:15] (current) – [Resizing your target] rodolico
Line 30: Line 30:
  
 <code perl addAlliSCSIS.pl> <code perl addAlliSCSIS.pl>
-#! /usr/bin/perl -w+#! /usr/bin/env perl
  
-my @servers = ( '10.5.136.1' ); +use strict; 
 +use warnings; 
 + 
 +# change following to be a list of 1 or more iSCSI targets to be queried 
 +my @servers = ( '10.10.10.10','10.10.10.9' ); 
 my %targets; my %targets;
  
  
 foreach my $server ( @servers ) { foreach my $server ( @servers ) {
 +   print "\n" . '-'x40 . "\nGetting targets on server $server\n" . '-'x40 . "\n";
    my @list = `iscsiadm -m discovery -t st -p $server`;    my @list = `iscsiadm -m discovery -t st -p $server`;
    chomp @list;    chomp @list;
Line 50: Line 55:
       # only add them if they are in this IP       # only add them if they are in this IP
       $targets{ $targetName } = $portal if $portal =~ m/^$server/;       $targets{ $targetName } = $portal if $portal =~ m/^$server/;
 +      print "$targetName\t$targets{ $targetName }\n";
    }    }
 } }
  
 +print "\n" . '-'x40 . "\nGetting active sessions\n". '-'x40 . "\n";
 # now, get active sessions so we can filter them # now, get active sessions so we can filter them
 my @activeSessions = `iscsiadm -m session`; my @activeSessions = `iscsiadm -m session`;
 chomp @activeSessions; chomp @activeSessions;
-foreach $session ( @activeSessions ) { +foreach my $session ( @activeSessions ) { 
-   $session =~ m/([0-9,:]+).* (.*)$/;+   $session =~ m/^.*[^0-9:.]([0-9,:.]+).*(iqn\S*)/;
    my ( $portal,$targetName ) = ( $1,$2 );    my ( $portal,$targetName ) = ( $1,$2 );
-   delete $targets{ $targetName if exists( $targets{$targetName} );+   print "$portal\t$targetName"; 
 +   if exists( $targets{$targetName} ) ) { 
 +      print "\tNOT updating\n"; 
 +      delete $targets{ $targetName }; 
 +   } else { 
 +      print "Needs to be added\n"; 
 +   }
 } }
  
Line 74: Line 87:
 } }
 # print `ls /dev/disk/by-path/`; # print `ls /dev/disk/by-path/`;
 +
 </code> </code>
  
Line 107: Line 121:
 </code> </code>
  
-Edit /etc/iet/ietd.conf and add the following lines+Edit /etc/iet/ietd.conf (Linux) or /etc/ctl.conf (BSD) and add the following lines
  
 <code>   <code>  
Line 115: Line 129:
 </code> </code>
 Restart iet Restart iet
-<code bash>  /etc/init.d/iscsitarget restart</code>+<code bash>/etc/init.d/iscsitarget restart # Linux 
 +service ctld reload # FreeBSD 
 +</code>
  
 ==== Adding new target to initiator ==== ==== Adding new target to initiator ====
Line 147: 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 a target on the iSCSI target, it is not automatically updated on the initiator. You could simply restart openiscsi or, if you just want to get the new size of one target, log out and the log in again from the initiator.+However, I generally use 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. 
 + 
 +<WRAP center round alert 60%> 
 +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 initiatordo the work, then log back in. 
 +</WRAP> 
 + 
 + 
 +=== On FreeBSD target ===
 <code bash> <code bash>
-log out, then back into target +set the new size on the target (assumed to be /storage/iscsi/target in example( 
-iscsiadm -m node --target='name of target' --portal "ip:port" --logout\\ iscsiadm -m node --target='name of target' --portal "ip:port" --login+zfs set quota=<newsize> storage/iscsi/target 
 +# let ctld know about the change. reload may work instead of restart 
 +service ctld restart
 </code> </code>
-The size of the target should now be updated (hint//fdisk -l /dev/disk/bypath/somename// is your friend)+ 
 +=== On initiator === 
 + 
 +You now need to rescan the target from the initiators. The first example rescans everything, which may not be what you want. 
 +<code bash> 
 +# probably not the best, since it rescans everything. 
 +# see next code block. 
 +iscsiadm -m session --rescan 
 +</code> 
 + 
 +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 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 -lwhich will 
 +# return the size on the first line 
 +fdisk -l /dev/disk/by-path/ip-..... 
 +</code> 
 + 
 +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.phpto avoid any problems.
  
 ==== Remove a target ==== ==== Remove a target ====
Line 162: Line 211:
 # first, log out of the session # first, log out of the session
 iscsiadm -m node --target='name of target' --portal "ip:port" --logout iscsiadm -m node --target='name of target' --portal "ip:port" --logout
-# now, do a discovery and delete the entry from your local database +# now, do a remove it from the session 
-iscsiadm -m discovery --target='name of target' --portal "ip:port" -o delete+iscsiadm -m node --target='name of target' --portal "ip:port" -o delete
 </code> </code>
  
unix/linux/iscsi_tricks_and_techniques.1565829800.txt.gz · Last modified: 2019/08/14 19:43 by rodolico