Table of Contents
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.
$ 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}”192.168.11.95:3260,1 iqn.2017-08.com.hiroom2:disk$ sudo iscsiadm -m node –targetname “${ISCSI_TARGET_NAME}” -p “${ISCSI_TARGET_PORTAL}” -lLogging in to [iface: default, target: iqn.2017-08.com.hiroom2:disk,portal: 192.168.11.95,3260] (multiple)Login to [iface: default, target: iqn.2017-08.com.hiroom2:disk,portal: 192.168.11.95,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.
$ ISCSI_TARGET_DEV=/dev/sda$ cat <<EOF | sudo fdisk ${ISCSI_TARGET_DEV}np1wEOF$ 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/fstabUUID=”${uuid}” /mnt ext4 _netdev,x-systemd.automount 0 0EOF