Subscribe to our RSS feed to get alerted every time SUBSCRIBE!

How to Configure ISCSI Target Server on AlmaLinux / Rocky Linux

ISCSI stands for Internet Small Computer Systems Interface.  This protocol is used for storage networking which is very useful for the data storage linking facilities. In RedHat Enterprise Linux there is a by default package is present named as targetcli that is useful to configure the ISCSI server.

Install Targetcli

Step-1 : Check whether the targetcli packages is install by default or not

In this command if anything shows in output means the packages are installed by default. If no output is present then we need to to install the packages using step 2 of this tutorial.

 rpm -q targetcli

Step-2 : Install the targetcli package using DNF package manager

 dnf install targetcli -y

Step-3 : As soon as installation completes start the services of targetcli

 systemctl start target

Step-4 : Enable the services of targetcli so that it will survive during boot

 systemctl enable target

It will show given output

ln -s '/usr/lib/systemd/system/target.service' '/etc/systemd/system/multi-user.target.wants/target.service'

Step-5 : Open the ISCSI port from the firewalld firewall for communicating with ISCSI

 firewall-cmd --permanent –add-port=3260/tcp

It will show given output

success

Step-6 : When done reload the firewall to activate the new rules

 firewall-cmd –reload

It will show given output

success

Step-7 : Check firewalld whether rules are added or not using a given command

 firewall-cmd –list-all

Configure ISCSI Target

Step-8 : List the disk which we want to install the ISCSI Target

 lsblk

We have found it using this list and In our case we are using /dev/vdb

Step-9 : Create the Partition for the /dev/vdb

 fdisk /dev/vdb

It will show given output and add the new partition using given parameter

Command (m for help): p
Device Boot Start Start End Blocks ID System
/dev/vdb1 2048 2048 472143871 236070912 83 Linux
/dev/vdb2 472143872 4722143872 488396799 8126464 82 Linux swap /Solaris
command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): e
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048) :
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519) :
Using default value 20971519
Partition 1 of type Extended and of size 10 GiB is set
Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (4096-20971519, default 4096):
Using default value 4096
Last sector, +sectors or +size{K,M,G} (4096-20971519, default 20971519) : +4G
Partition 5 of type Linux and of size 4 GiB is set
Command (m for help): t
Partition number (1,5, default 5): 5
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

Step-10 : Reload and write the disk partition

 partprobe

Step-11 : Check the partition that you have created

 fdisk -l

It will show given output

Device Boot Start End Blocks ID System
/dev/vdb1 2048 472143871 236070912 83 Linux
/dev/vdb2 472143872 488396799 8126464 82 Linux swap /Solaris
/dev/vdb5 488296780 758434594 563385394 81 Linux lvm

Step-12 : Create the Physical volume

 pvcreate /dev/vdb5

It will show given output

Physical volume "/dev/vda5" successfully created

Step-13 : Create the Volume Group

 vgcreate techbrown-vg /dev/vdb5

It will show given output

Volume group "techbrown-vg" successfully created

Step-14 : Create the Logical Volume

 lvcreate -L 3G -n techbrown-lvm techbrown-vg

It will show given output

Logical volume "techbrown-lvm" created

Step-15 : Check Whether LVM is created or not by using given command

 lsblk

Step-16 : When you have verified now lets move to the targetcli

 targetcli

It will show given output and type the command as shown as below

>ls
>/backstore/block create iscsi_store /dev/techbrown-vg/techbrown-lvm
>iscsi create iqn.2015-06.com.techbrown:techbrownserver
>iscsi/iqn.2015-06.com.techbrown:techbrownserver/tpg1/acls create iqn.2015-06.com.techbrown:techbrowndesktop
>iscsi/iqn.2015-06.com.techbrown:techbrownserver/tpg1/luns create /backstore/block/iscsi_store
>iscsi/iqn.2015-06.com.techbrown:techbrownserver/tpg1/portals create 172.25.26.11
>ls
>saveconfig
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
>exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

Step-17 : When you have completed now restart the target services to make changes in the effect.

 systemctl restart target

Step-18 : Reload the firewalld to flush the old firewall rules and implement the new one

 firewall-cmd --reload

Congratulations now you have configured ISCSI target server on Enterprise Linux.