From Newroco tech docs
Jump to navigationJump to search

Setup of Target

Install iscsitarget and configure storage:

  1. sudo apt-get -y install iscsitarget iscsitarget-dkms

make a disk image:

  1. sudo mkdir /var/iscsi_disks
  1. sudo dd if=/dev/zero of=/var/iscsi_disks/<disk_name>.img count=0 bs=1 seek=<size>


  1. sudo dd if=/dev/zero of=/var/iscsi_disks/zabbix_logs.img count=0 bs=1 seek=100G

Enable ICSI Targeting:

Access the file:

  1. sudo vi /etc/default/iscsitarget

and change SCSITARGET_ENABLE=false to true.

Configure Target iqdn:

  1. sudo vi /etc/iet/ietd.conf

add the following at the end of the file:

  1. Target iqdn.<year>-<month>.<domain>:<any name>
  2. Lun 0 Path=<Path_to.img>,Type fileio
  3. initiator-address <>
  4. incominguser <username> <password>


  1. Target iqdn.2017-08.tandp-host1:ZabbixLogs
  2. Lun 0 Path=/var/icsi_disks/zabbix_logs.img,Type fileio
  3. initiator-address
  4. incominguser zabbix S70r4g3P455w0rd

Restart iscsitarget:

  1. sudo systemctl restart iscsitarget

Check status:

  1. sudo ietadm --op show --tid=1

You should see:

  1. Wthreads=8
  2. Type=0<
  3. QueuedCommands=32
  4. NOPInterval=0
  5. NOPTimeout=0

Client setup and initial configuration

Information in configuring open-iscsi by clients (not to become a storage provider)


  1. apt-get install open-iscsi parted

This should create your unique initiator name which if you need to configure access control on the iscsi server you can get by

  1. tail -n1 /etc/iscsi/initiatorname.iscsi

Once you know there is a volume available for use with the server being configured use

  1. iscsiadm -m discovery -t sendtargets -p portal.ip.add.ress

NB portal IP address may not be the same address as used for managing the SAN

to get the name of the volume available to the server. This will be in the form of

  1. storage.ip.add.ress:port,1 uniqueinitiatornameofstorage-volumename



Depending on the storage server, the initiator name can be quite long, but you just need to be able to cut and paste parts into the next command:

  1. iscsiadm -m node -T uniqueinitiatornameofstorage-volumename -p storage.ip.add.ress:port -l


  1. iscsiadm -m node -T -p -l

The iscsi volume should now be available as a disk device to be managed by the OS. Check by

  1. ls /dev/disk/by-path/

The output will tell you what disk device to address e.g.

  1. # ls -l /dev/disk/by-path/
  2. total 0
  3. lrwxrwxrwx 1 root root 9 Nov 1 16:38 ip-storage.ip.add.ress:3260-uniqueinitiatornameofstorage-volumename-lun-0 -> ../../sda

where sda is the key element. Using that information create a volume on the drive with parted:

parted /dev/sda

Then create a filesystem as needed

mkfs.ext4 /dev/sda1

(what disk filesystem you use depends on need, but assuming backup etc. is taken care of, EXT4 probably best all-round performance option)

NB if using ext4, the defaults leave 5% of space reserved for root operations. If the volume is for use for data storage, then you should reduce this with

tune2fs -m 1 /dev/sda1

To ensure your iscsi volume is available on reboot

  1. vi /etc/iscsi/iscsid.conf

and set

  1. node.startup = automatic

Then edit the settings for your iscsi node

  1. vi /etc/iscsi/nodes/uniqueinitiatornameofstorage-volumename/ip-storage.ip.add.ress,3260,1/default

and set

  1. node.conn[0].startup = automatic

Note if you only have one iscsi volume on a server, there will only be one nodes subdirectory so Tab autocomplete is your friend.

Now mount the volume (note if this is to extend space in use you may need to mount the volume at a temporary location, move existing data and then remount at the desired permanent location. This best done with the UUID, which got created when the volume did.

  1. mkdir /path/to/mymountpoint
  2. ls -l /dev/disk/by-uuid
  3. systemctl daemon-reload
  4. mount /dev/disk/by-uuid/youruuid /path/to/mymountpoint

Assuming success (best to test you can write to the mounted volume) next make the mount auto remount on reboot by

  1. vi /etc/fstab

and appending a line of the form

  1. UUID=youruuid /path/to/mymountpoint ext4 defaults,relatime,_netdev 0 0

for normal file stores, and

  1. UUID=youruuid /path/to/mymountpoint ext4 defaults,noatime,_netdev 0 0

for backups (where noatime means access times are not recorded, which should preserve the accesstime from when the file was last accessed on the active store). Where a key option is _netdev, which tells the operating system not to try and mount this volume until the network is up.

When /etc/fstab is modified a service reload is needed so the new changes are seen. Less needed when just adding a new line, more needed when removing/modifying an existing one so the OS doesn't try to remount an old configuration.

  1. systemctl daemon-reload

Troubleshooting and Tips

Logging out of ISCSI sessions

If you need to logout of the iscsi storage to allow changes to the volume etc., unmount it and run

  1. iscsiadm -m node -T uniqueinitiatornameofstorage-volumename -p storage.ip.add.ress:port -u

Logout all sessions

  1. iscsiadm --mode node --logoutall=all

Login all known nodes

  1. iscsiadm --mode node --loginall=all

Delete node

To delete a discovered node run

  1. iscsiadm -m node -o delete -T <iqn>

General information

To see all known nodes

  1. iscsiadm -m node

To see current active sessions

  1. iscsiadm -m session -P 3