Title : OpenBSD and iSCSI part2: the initiator (client)
Author: Solène
Date  : 21 February 2019
Tags  : unix openbsd iscsi

This is the second article of the serie about iSCSI. In this one, you will
learn how to connect to an iSCSI target using OpenBSD base daemon **iscsid**.

The configuration file of **iscsid** doesn't exist by default, its location is
**/etc/iscsi.conf**. It can be easily written using the following:


    target "disk1" {
        initiatoraddr $myaddress
        targetaddr $target1
        targetname "iqn.1994-04.org.netbsd.iscsi-target:target0"

While most lines are really obvious, it is **mandatory** to have the line
initiatoraddr, many thanks to cwen@ for pointing this out when I was stuck on

The targetname value will depend of the iSCSI target server. If you use
netbsd-iscsi-target, then you only need to care about the last part, aka
**target0** and replace it by the name of your target (which is target0 for the
default one).

Then we can enable the daemon and start it:

    # rcctl enable iscsid
    # rcctl start iscsid

In your dmesg, you should see a line like:

    sd4 at scsibus0 targ 1 lun 0: <NetBSD, NetBSD iSCSI, 0> SCSI3 0/direct fixed t10.NetBSD_0x5c6cf1b69fc3b38a

If you use netbsd-iscsi-target, the whole line should be identic except for the
sd4 part which can change, depending of your hardware.

If you don't see it, you may need to reload iscsid configuration file with
`iscsictl reload`.

Warning: iSCSI is a bit of pain to debug, if it doesn't work, double check the
IPs in **/etc/iscsi.conf**, check your PF rules on the initiator and the
target. You should be at least able to telnet into the target IP port 3260.

Once you found your new sd device, you can format it and mount it as a regular
disk device:

    # newfs /dev/rsd4c
    # mount /dev/sd4c /mnt

iSCSI is far mor efficient and faster than NFS but it has a total different
purpose. I'm using it on my powerpc machines to build packages on it. This
reduce their old IDE disks usage while giving better response time and
equivalent speed.