LinuxMint 18: Install open-iscsi for iSCSI initiator

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

1 Install open-iscsi

Install open-iscsi package.

$ sudo apt install -y open-iscsi

2 Connect to iSCSI target with iscsiadm

Connect to iSCSI target with iscsiadm.

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

3 Mount iSCSI target device on boot

Change node.startup to automatic in /etc/iscsi/iscsid.conf.

$ sudo sed -e 's/^node.startup = manual/node.startup = automatic/g' \
       -i /etc/iscsi/iscsid.conf

Connect to iSCSI target. If you have connected to iSCSI target before changing node.startup to automatic, you need to connect to iSCSI target again after changing node.startup to automatic.

$ 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