FreeBSD iSCSI Initiator Installation and Configuration

by on March 11, 2008 · 15 comments· LAST UPDATED March 11, 2008

in , ,

Q. How do I install and configure iSCSI initiator service under FreeBSD server?

A. FreeBSD 7.x has full support for iSCSI. Older version such as FreeBSD 6.3 requires backport for iSCSI. Following instruction are known to work under FreeBSD 7.0 only.

FreeBSD iscsi_initiator driver

The iscsi_initiator implements the kernel side of the Internet SCSI (iSCSI) network protocol standard, the user land companion is iscontrol and permits access to remote virtual SCSI devices via cam.

Compile driver

Please note that FreeBSD 7.x has this driver compiled by default. You can skip this step if driver exists at /boot/kernel/iscsi_initiator.ko. To compile this driver into the kernel,
# cd /usr/src/sys/i386/conf
# cp GENERIC ISCSIKERNEL
# vi ISCSIKERNEL

Place the following lines in your kernel configuration file:
device iscsi_initiator
Save and close the file. Building a Kernel, type the following commands:
# cd /usr/src
# make buildkernel KERNCONF=ISCSIKERNEL

Install the new kernel:
# make installkernel KERNCONF=ISCSIKERNEL
Now reboot the system:
# reboot

Install iSCSI Initiator driver under FreeBSD

You need FreeBSD kernel driver for the iSCSI protocol. You need to use driver called /boot/kernel/iscsi_initiator.ko. You can load this driver by typing following command as root user:
# kldload -v iscsi_initiator.ko
Output:

Loaded iscsi_initiator.ko, id=6

Alternatively, to load the driver as a module at boot time, place the following line in /boot/loader.conf:
# vi /boot/loader.conf
# Beginning of the iSCSI block added by Vivek
iscsi_initiator_load="YES"
# End of the block added by Vivek

Save and close the file.

FreeBSD iscontrol command to login / negotiator / control for an iSCSI initiator session

Now, you need to use iscontrol command. First, do a discovery session and exit:
# iscontrol -d targetaddress=iSCSI-SERVER-IP-ADDRESS initiatorname=nxl
# iscontrol -v -d targetaddress=192.168.1.100 initiatorname=nxl

Please note down the list of available targetnames/targetadresses. Once you know the target name, edit /etc/iscsi.conf file:
# vi /etc/iscsi.conf
Append config directives as follows:

officeiscsi {
        authmethod      = CHAP
        chapIName       = YOUR-ISCSI-USERNAME
        chapSecret      = YOUR-ISCSI-PASSWORD
        initiatorname   = nxl
        TargetName      = iqn.XYZZZZZZZZZZZZZ #  whatever "iscontrol -v -d " gives you
        TargetAddress   = 192.168.1.100:3260,1 # your iscsi server IP
}

Save and close the file.
Where,

  • officeiscsi { : Start config for iSCSI.
  • authmethod : Set authentication method to chap
  • chapIName : Your username
  • chapSecret : Your password
  • initiatorname : if not specified, defaults to iqn.2005-01.il.ac.huji.cs:<hostname>
  • TargetName : is the name by which the target is known, not to be confused with target address, either obtained via the target administrator, or from a discovery session.
  • TargetAddress : is of the form domainname[:port][,portal-group-tag] to quote the RFC: The domainname can be specified as either a DNS host name, a dotted-decimal IPv4 address, or a bracketed IPv6 address as specified in [RFC2732].
  • } : End of config

Start an iSCSI session

The following command will read options from /etc/iscsi.conf, use the targetaddress found in the block nicknamed myiscsi, login and negotiate whatever options are specified, and start an iscsi-session.
# iscontrol -c /etc/iscsi.conf -n officeiscsi
Once you run the iscontrol command it should create a new device in /dev directory. To see the device name run dmesg command:
# dmesg

Format iSCSI volume

Now run sysinstall command to format just discovered iSCSI device name at /dev location:
# sysinstall
Select Custom > 3 Partition > Select iSCSI device name such as da1. Once formatted just mount device, enter:
# mkdir /iscsi
# mount /dev/da1s1 /iscsi

You may also need to update /etc/fstab file:
/dev/ad1s1 /iscsi ufs rw 3 3

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 15 comments… read them below or add one }

1 Tamouh April 14, 2008 at 4:39 am

Great information. Hard to find this amount of details anywhere on the web for FBSD iSCSI. Totally appreciate the efforts

Reply

2 Elnour May 6, 2008 at 11:25 am

Hi,

great guid, but how do you automate the part below

iscontrol -c /etc/iscsi.conf -n officeiscsi

and do you get fstab part to work without the above?

thanks

Reply

3 bat August 28, 2008 at 7:00 pm

Hi, there’s a small typo here:

“You may also need to update /etc/fstab file:
/dev/ad1s1 /iscsi ufs rw 3 3″

i guess ad1s1 should be da1s1. anyway.
thx for the howto

Reply

4 John Hannerhan September 8, 2008 at 7:41 pm

Has anyone tried this, and if so, is it stable?

Reply

5 nixCraft September 8, 2008 at 7:46 pm

So far no problem here but yes technology is new…

Reply

6 Andrei November 13, 2008 at 12:09 pm

Just tested it with Openfiler and it doesn’t work.
I will soon test it with FreeNAS also.
I keep having this error:
#iscontrol -c /etc/iscsi.conf -n target0
0×0203: Not found
If I play with the username/pass (change it) it cryes about authentification error…
I’ll also do some tcpdump traces to see what’s the error…

Reply

7 nixCraft November 13, 2008 at 12:34 pm

Andrei,

I’ve tested above instructions only on FreeBSD 7. Let us know more about your findings on FreeNAS or Openfiler.

Reply

8 Andrei November 17, 2008 at 2:27 pm

It works with Openfiler (tested only on vmware environment). I reconfigured from the beginning. The important thing is to remove any network ACLs and authentification and start from the simplest configuration. But I can’t set it to add the device automatically after reboot (excluding cron’s @reboot).

Reply

9 Fabian December 23, 2008 at 6:02 pm

I tried this tutorial on a amd64 version. It works fine up to the part, where the new partion shuld be mounted. When trying to mount the device (mount /dev/da0s1 /iscsi), the following message occurs:

mount: /dev/da0s1 : Invalid argument

I tried to build the fs, with the following command:

newfs /dev/da0s1

After this, the device can be mounted. But when trying to access the volume (read or write) the complete machine freezes and needs a hard-reset to start up again. Any ideas?

Reply

10 Ian January 27, 2009 at 10:27 pm

I agree with Andrei… works great with OpenFiler, both being under VMware control. But, I also tested with a ZFS iSCSI target on Solaris 10 08/07, and it didn’t work. I think the ZFS iSCSI target controller (or the Solaris 10 one) is broken, as a Mac OS iSCSI initiator can’t talk to it properly either. I will check more into the compatibility issue. But, doing a “iscontrol -c /etc/iscsi.conf -n ” causes an infinite da???? detection loop by the system.

Ian

Reply

11 togr February 19, 2009 at 10:17 pm

I just set this up between freebsd 7.0 and netapp filer simulator (ontap 7251) , both running under virtualbox 214 with CHAP authentication. All worked very well since the very first try.
This is obviously not a production environment so I can’t really tell anything except that it worked with the mentioned config:(
I noticed a small flaw of iscontrol: I could not display valid initiator name of my freebsd, this should be something like iqn.XXXXXX….., it is visible on filer after first discovery session, but you need to have access to storage side, which not always is possible (large organisations often have separate teams).

Reply

12 Eric Chang September 10, 2009 at 3:02 am

nopam# kldstat
Id Refs Address Size Name
1 7 0xc0400000 9fab28 kernel
2 1 0xc0dfb000 ff18 iscsi_initiator.ko
3 1 0xc0e0b000 6a45c acpi.ko
4 1 0xc44d9000 a6000 zfs.ko
5 1 0xc457f000 2000 opensolaris.ko
nopam#

nopam# iscontrol -v -d targetaddress=192.168.10.202 initiatorname=nxl
adding ‘targetaddress=192.168.10.202′
I-: cmd=0×3 len=265
SessionType=Discovery
InitiatorName=nxl
MaxBurstLength=131072
HeaderDigest=None,CRC32C
DataDigest=None,CRC32C
MaxRecvDataSegmentLength=65536
ErrorRecoveryLevel=0
DefaultTime2Wait=0
DefaultTime2Retain=0
DataPDUInOrder=Yes
DataSequenceInOrder=Yes
MaxOutstandingR2T=1
T-: cmd=0×23 len=211
MaxBurstLength=131072
HeaderDigest=None
DataDigest=None
MaxRecvDataSegmentLength=65536
ErrorRecoveryLevel=0
DefaultTime2Wait=0
DefaultTime2Retain=0
DataPDUInOrder=Yes
DataSequenceInOrder=Yes
MaxOutstandingR2T=1
I-: cmd=0×4 len=16
SendTargets=All
recvpdu: Socket is not connected
recvpdu failed
I-: cmd=0×6 len=0
recvpdu: Socket is not connected
recvpdu failed
nopam#

this is the result of my working.
any ideas ??
sorry for my poor english ..

Reply

13 Robin Stahlbaum November 6, 2009 at 8:04 pm

Works well for me. I used ESX 4 based freebsd and openfiler.
thanks for the info

Reply

14 Brian June 22, 2010 at 6:39 pm

Many targets will require a properly formatted InitiatorName. i.e. It must start with iqn. and it must contain a ‘:’

Also, once the drive is mounted, many camcontrol commands will work to get additional info.

There does seem to be occasional problems with FreeBSD attempting to mount the drives before the iscsi connection is established.

Reply

15 swinful August 10, 2010 at 2:38 pm

Vivek,

Great, short and sweat article. Just wanted to add, there is no need to add “device iscsi_initiator” into the kernel, recompile and reboot the system if you will use it as a loadable module. You may simple just “# kldload iscsi_initiator” from the command-line or add it to /boot/loader.conf to have it load automatically at boot time.

Regards,
-swinful

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: