Initial commit

This commit is contained in:
2023-05-11 15:44:13 +02:00
commit 905361e72f
4 changed files with 133 additions and 0 deletions
Executable
+44
View File
@@ -0,0 +1,44 @@
#!/bin/bash
IQN=$1
HOST=$2
if [[ -z "${IQN}" ]]; then
echo "usage: $0 TargetIQN [Host]"
echo ""
exit
fi
iscsiadm -m discovery -t sendtargets -o update -p ${HOST} &> /dev/null
if [[ ! -z "${HOST}" ]]; then
iscsiadm -m node -T ${IQN} -p ${HOST} -l
else
iscsiadm -m node -T ${IQN} -l
fi
sleep 0.5
SESSIONID=$(iscsiadm -m session | grep "${IQN}" | head -n 1 | sed -e 's/.*\[\(.*\)\].*/\1/g')
DEVICE=$(iscsiadm -m session -r ${SESSIONID} -P 3 | grep "Attached scsi disk" | sed -e 's/.*Attached scsi disk \([^\t]*\).*/\/dev\/\1/g')
BLOCKDEVICE=${DEVICE}
MULTIPATHDEVICE=$(multipath -l ${DEVICE} | grep 'mpath' | sed -e 's/^\([a-z]*\) .*/\1/g')
if [[ ! -z "${MULTIPATHDEVICE}" ]]; then
BLOCKDEVICE="/dev/mapper/${MULTIPATHDEVICE}"
fi
mkdir -p /mnt/iSCSI_${IQN}
FILESYSTEM=$(blkid ${BLOCKDEVICE})
if [ -z "${FILESYSTEM}" ]; then
echo "No Filesystem found, initialize using following command:"
echo "mkfs.ext4 ${BLOCKDEVICE}"
echo ""
echo "And mount afterwards using:"
echo "mount ${BLOCKDEVICE} /mnt/iSCSI_${IQN}"
else
mount -o discard ${BLOCKDEVICE} /mnt/iSCSI_${IQN}
fi