#! /bin/bash
# Package installation for ISCSI
yum install target* -y
# Creating Partition
fdisk /dev/vdb << EEOF
#Press "n" for new partition
#Press "e" for extended partition
#Press "n" for new partition on extended partition
#Press "l" for list of partition
#Assign partition size for example "+4G"
#List of partition number "l"
#Press "t" for partition type
#Partition number "5"
#Partition type "8e" for Linux LVM
#Press "w" for save the configuration
EEOF
#To refresh and update partition type
partprobe
#To create Primary group for the LVM Partition
pvcreate /dev/vdb5
#To create Volume group for LVM partition
vgcreate myvol /dev/vdb5
#To create Logical volume
lvcreate -n data -L +3G myvol
targetcli << EEOF
ls
/backstores/block create iscsi /dev/myvol/data
/iscsi create iqn.2015-02.com.exaple:1server
/iscsi/iqn.2015-02.com.example:1server/tpg1/acls create iqn.2015-06.com.example:desktop1
/iscsi/iqn.2015-02.com.example:1server/tpg1/luns create /backstores/block/iscsi
/iscsi/iqn.2015-02.com.example:1server/tpg1/portals create 172.25.1.11
saveconfig
exit
EEOF
#To start the ISCSI partition
systemctl restart target
systemctl enable target
#To allow ISCSI from Firewall
firewall-cmd --permanent --add-port=3260/tcp
firewall-cmd --reload
# Package installation for ISCSI
yum install target* -y
# Creating Partition
fdisk /dev/vdb << EEOF
#Press "n" for new partition
#Press "e" for extended partition
#Press "n" for new partition on extended partition
#Press "l" for list of partition
#Assign partition size for example "+4G"
#List of partition number "l"
#Press "t" for partition type
#Partition number "5"
#Partition type "8e" for Linux LVM
#Press "w" for save the configuration
EEOF
#To refresh and update partition type
partprobe
#To create Primary group for the LVM Partition
pvcreate /dev/vdb5
#To create Volume group for LVM partition
vgcreate myvol /dev/vdb5
#To create Logical volume
lvcreate -n data -L +3G myvol
targetcli << EEOF
ls
/backstores/block create iscsi /dev/myvol/data
/iscsi create iqn.2015-02.com.exaple:1server
/iscsi/iqn.2015-02.com.example:1server/tpg1/acls create iqn.2015-06.com.example:desktop1
/iscsi/iqn.2015-02.com.example:1server/tpg1/luns create /backstores/block/iscsi
/iscsi/iqn.2015-02.com.example:1server/tpg1/portals create 172.25.1.11
saveconfig
exit
EEOF
#To start the ISCSI partition
systemctl restart target
systemctl enable target
#To allow ISCSI from Firewall
firewall-cmd --permanent --add-port=3260/tcp
firewall-cmd --reload