How to setup iSCSI server (target) on FreeBSD system
Intro
You can read more about iSCSI here. This tutorial was completed on FreeBSD 13.0-p1. This is fairly simple, three step process. Create a file to store data in, create a config file for ctld and enable service on boot up.
Create a storage file
Let’s begin by creating a data storage file using dd utility. Pick a location and size of the file you want to create. In my example I’m creating a file named target0-0 inside of /datastore directory with the size of 512Gb.
# dd if=/dev/zero of=/datastore/target0-0 bs=1G count=512
Create a config file
Now you need to create a config file in /etc/ctl.conf for ctld daemon. This example also includes authentication for added security. It should look something like this, but edit to suite your own environment:
auth-group ag0 { chap username1 secretpassword chap username2 anothersecretpassword } portal-group pg0 { discovery-auth-group no-authentication listen 0.0.0.0 listen [::] } target iqn.freebsd.com.example:target0 { auth-group ag0 portal-group pg0 lun 0 { path /datastore/target0-0 size 512G } }
If you don’t want to use authentication, just remove any references to auth-group from the config file.
Start service and enable on boot up
Edit /etc/rc.conf file and add ctld_enable=”YES” line at the end of the file. Now start the service with the commands:
# service ctld start # service ctld reload
Done
At this point you should be able to connect your client(s) to this iSCSI target. Your client can be another BSD box, Linux or Windows.