CentOS 7: Install iscsi-initiator-utils for iSCSI initiator

This article will describe installing iscsi-initiator-utils for iSCSI initiator.

1 Install iscsi-initiator-utils

Install iscsi-initiator-utils package.

$ sudo yum install -y iscsi-initiator-utils

Add SELinux configuration.

$ cat <<EOF > iscsid.te
module iscsid 1.0;

require {
        type iscsid_t;
        class system module_load;

#============= iscsid_t ==============
allow iscsid_t self:system module_load;
$ checkmodule -M -m -o iscsid.mod iscsid.te
$ semodule_package -m iscsid.mod -o iscsid.pp
$ sudo semodule -i iscsid.pp
$ rm -f iscsid.mod iscsid.te iscsid.pp

2 Connect to iSCSI target with iscsiadm

Connect to iSCSI target with iscsiadm.

$ ISCSI_TARGET_PORTAL=iscsi-target.hiroom2.com
$ ISCSI_TARGET_NAME=iqn.2017-08.com.hiroom2:disk
$ sudo iscsiadm -m discovery -t st -p "${ISCSI_TARGET_PORTAL}",1 iqn.2017-08.com.hiroom2:disk
$ sudo iscsiadm -m node \
       --targetname "${ISCSI_TARGET_NAME}" -p "${ISCSI_TARGET_PORTAL}" -l
Logging in to [iface: default, target: iqn.2017-08.com.hiroom2:disk,
portal:,3260] (multiple)
Login to [iface: default, target: iqn.2017-08.com.hiroom2:disk,
portal:,3260] successful.

3 Mount iSCSI target device on boot

Connect to iSCSI target.

$ sudo iscsiadm -m discovery -t st -p "${ISCSI_TARGET_PORTAL}"
$ sudo iscsiadm -m node \
       --targetname "${ISCSI_TARGET_NAME}" -p "${ISCSI_TARGET_PORTAL}" -l

Create filesystem on iSCSI target device with fdisk and mkfs.

$ cat <<EOF | sudo fdisk ${ISCSI_TARGET_DEV}

$ sudo mkfs.ext4 ${ISCSI_TARGET_DEV}1

Add mount entry to /etc/fstab. For avoiding mounting before network initialization, you need to add _netdev option. For making x-systemd.automount to mount, you need to add x-systemd.automount to option.

$ uuid=$(sudo blkid | grep "^${ISCSI_TARGET_DEV}1:" | \
          sed -e 's/.* UUID="\([^"]*\)".*/\1/g')
$ cat <<EOF | sudo tee -a /etc/fstab
UUID="${uuid}" /mnt ext4 _netdev,x-systemd.automount 0 0