iSCSI on FreeBSD

iSCSI

Create a dataset on my zfs pool

# sudo zfs create -V 30G tank/windows

 

If you want to delete a dataset for any circumstances you can run the following command

# sudo zfs destroy tank/windows

 

Alternatively you can create a disk image if you are not using ZFS as file system with the following command

Note: This step is not necessary if you have created a zfs dataset. Also if you decided to create a disk image, do not forget to change the path on you istgt.conf configuration file

# sudo dd if=/dev/zero of=/home/windows.img bs=1M count=30000 # count is the size in megabytes

 

Install iSCSi software on the FreeBSD server

# cd /usr/ports/net/istgt

# sudo make install clean (everything by default)

 

As a root run the following command in order to enable the service

# echo ‘istgt_enable=”YES”‘ >> /etc/rc.conf

 

Let’s create our configurations files

# cd /usr/local/etc/istgt/

 

There are three configuration files that we have to create

 

  • istgt.conf
  • auth.conf
  • istgtcontrol.conf

We create the first file under the path /usr/local/etc/istgt

# sudo vi istgt.conf

 

Copy and paste the following lines into the file

# cat istgt.conf

[Global]

Comment “Global section”


NodeBase “vhostfbsd.2014-04.mrwhitebp.com”

PidFile /var/run/istgt.pid

AuthFile /usr/local/etc/istgt/auth.conf

LogFacility “local7”

Timeout 30

NopInInterval 20

DiscoveryAuthMethod Auto

MaxSessions 16

MaxConnections 4

MaxR2T 32

MaxOutstandingR2T 16

DefaultTime2Wait 2

DefaultTime2Retain 60

FirstBurstLength 262144

MaxBurstLength 1048576

MaxRecvDataSegmentLength 262144

InitialR2T Yes

ImmediateData Yes

DataPDUInOrder Yes

DataSequenceInOrder Yes

ErrorRecoveryLevel 0

[UnitControl]

Comment “Unit Controller”

AuthMethod CHAP Mutual

AuthGroup AuthGroup10000

Portal UC1 127.0.0.1:3261

Netmask 127.0.0.1

[PortalGroup7]

Comment ” PORT”


Portal DA1 192.168.1.9:3260 # ip of your FreeBSD server

[InitiatorGroup7]

Comment “Initiator Group7”

InitiatorName “ALL”


Netmask 192.168.1.0/24 # your network and network mask

[LogicalUnit1]


Comment “windows” # name of your disk. If you create a disk images change the name for windows.img

TargetName windows # name of your disk. If you create a disk images change the name for windows.img

TargetAlias “windows” # name of your disk. If you create a disk images change the name for windows.img

Mapping PortalGroup7 InitiatorGroup7

AuthMethod CHAP

AuthGroup AuthGroup7

UseDigest Auto

UnitType Disk

LUN0 Storage /dev/zvol/tank/windows Auto # path of your disk or dataset

#alternatively if you create a disk images your LUN0 should be looks like this

#LUN0 Storage /home/windows.img Auto

 

Note: I have changed the colour lines that you need to adjust to your needs

Second file under the same path

# sudo vi auth.conf

 

Copy and paste the following lines into the file

 

[AuthGroup7]

Comment “Auth Group7”


Auth “windows” “esteEselpass123456” # This is the user and password

[AuthGroup10000]

Comment “Unit Controller”

Auth “ctluser” “user” “mutualuser” “mutualsecret”

Auth “onlysingle” “secret”

 

Third file under the same path

# sudo vi istgtcontrol.conf

 

Copy and paste the following lines into the file

[Global]

Comment ” configuration”

Timeout 60

AuthMethod CHAP Mutual

Auth “user” “secret” “mutual user” “mutual secret”

Host localhost

Port 3261

 

Start the iScsi service

# sudo service istgt start

 

Now let’s connect our drive to our windows system

Windows 8

Open iSCSI initiator on windows 8

Go back to “targets” and connect the drive. Do not forget user and password

 

The status should change from “Inactive” to “Connected”

Now let’s look at the last result. Open the “Computer Management” on windows 8 and go to the “Disk management”. You should find a new disk 7 (select your partition table from MBR or GPT and give it format.)

 

Finally should be able to access your drive from the “File explorer”