Setting up an iSCSI Initiator for the Thecus N5200 Pro under Gentoo Linux

Home

Problem

I recently purchased the Thecus N5200 Pro along with 5 x 500Gb Seagate SATA drives to store, redundantly, my mass of "data". This happens to be configured as a RAID 5 array of approx 2TB with 10% allocated for iSCSI use (approx 200Gb). Now, how do I get access to this from my Gentoo Box?

Solution

Kernel Configuration

Firstly, we need to compile in the required Linux kernel elements to get this going. These specifically are (for Kernel 2.6.21-gentoo-r4);
Device Drivers --> SCSI Transports --> <M> iSCSI Transport Attributes SCSI low-level drivers --> <M> iSCSI Initiator over TCP/IP Crytographic API --> [*] MD5 digest algorithm [*] CRC32c CRC algorithm

Software

Secondly, we need to install
sys-block/open-iscsi
localhost ~ # emerge -s open-iscsi Searching... [ Results for search key : open-iscsi ] [ Applications found : 1 ] * sys-block/open-iscsi [ Masked ] Latest version available: 2.0.865.12 Latest version installed: [ Not Installed ] Size of files: 224 kB Homepage: http://www.open-iscsi.org/ Description: Open-iSCSI project is a high performance, transport independent, multi-platform implementation of RFC3720. License: GPL-2
It is masked, that is easily fixed...
localhost ~ # echo sys-block/open-iscsi >> /etc/portage/package.keywords
Followed with a
localhost ~ # emerge -av open-iscsi These are the packages that would be merged, in order: Calculating dependencies... done! [ebuild N ] sys-block/open-iscsi-2.0.865.12 USE="-debug" 225 kB Total: 1 package (1 new), Size of downloads: 225 kB Would you like to merge these packages? [Yes/No]
Now onto the final stage...

Software Configuration

Lets first of all start by giving ourselves an iSCSI Initiator name. This is taken from
/etc/initiatorname.iscsi
:
# The InitiatorName should take the following format # iqn.${YEAR}-${MONTH}-${DOMAIN_REVERSED}.${HOSTNAME}:${UNIQUE_STRING} # Where YEAR and MONTH are the dates that your domain was registered. # You can use WHOIS to find when your domain was registered. # If you don't have a real domain in the outside world, invent one, but use # .local for your top-level. # Example case #1: # This assumes you own foobar.co.uk. # Domain name: foobar.co.uk. # Registration date: March 2001 # Hostname: linux # InitiatorName=iqn.2001-03.uk.co.foobar.linux:openiscsi-29b48ad602d5f83dd9cd9aa3ef741216 # Example case #2: # This assumes you don't have a domain of your own. # Domain name: foobar.local # Registration date: March 2001 # Hostname: linux # InitiatorName=iqn.2001-03.local.foobar.linux:openiscsi-29b48ad602d5f83dd9cd9aa3ef741216
Therefore, in my case I have defined it as follows:
InitiatorName=iqn.2007-11.localdomain.localhost:openiscsi-initiator InitiatorAlias=localhost
The next part would appear to be a bit of an oversight however it's a fairly trivial fix (it will complain and basically tell you to do this otherwise);
localhost ~ # cd /etc localhost etc # mkdir iscsi localhost etc # cd iscsi localhost iscsi # ln -sf ../initiatorname.iscsi
Before starting up the iSCSI daemon
localhost iscsi # /etc/init.d/iscsid start * Loading iSCSI modules - scsi_transport_iscsi ... [ ok ] * Loading iSCSI modules - iscsi_tcp ... [ ok ] * Starting iSCSI initiator service ... [ ok ] localhost iscsi #
Now it's time to configure the actual connection, thankfully there is a nice tool to help us with this -
iscsiadm
localhost ~ # iscsiadm iscsiadm -m discovery [ -hV ] [ -d debug_level ] [-P printlevel] [ -t type -p ip:port -I ifaceN ... [ -l ] ] | [ -p ip:port ] [ -o operation ] [ -n name ] [ -v value ] iscsiadm -m node [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -L all,manual,automatic ] [ -U all,manual,automatic ] [ -S ] [ [ -T targetname -p ip:port -I ifaceN ] [ -l | -u | -R | -s] ] [ [ -o operation ] [ -n name ] [ -v value ] ] iscsiadm -m session [ -hV ] [ -d debug_level ] [ -P printlevel] [ -r sessionid | sysfsdir [ -R | -u | -s ] [ -o operation ] [ -n name ] [ -v value ] ] iscsiadm -m iface [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -I ifacename ] [ [ -o operation ] [ -n name ] [ -v value ] ]
The first stage is discovery (replace
nas
with the hostname or IP of your NAS device);
localhost ~ # iscsiadm -m discovery -t sendtargets -p nas 192.168.0.123:3260,1 iqn.2007-11.localdomain:RAID.iscsi0.vg0.myiscsi
This has now found the NAS device, and added the entry to the "table". We can see this by typing
localhost ~ # iscsiadm -m node 192.168.0.123:3260,1 iqn.2007-11.localdomain:RAID.iscsi0.vg0.myiscsi
and the options associated (defaults from
/etc/iscsi.conf
)
localhost ~ # iscsiadm -m node -o show node.name = iqn.2007-11.localdomain:RAID.iscsi0.vg0.myiscsi node.tpgt = 1 node.startup = manual iface.hwaddress = default iface.iscsi_ifacename = default iface.net_ifacename = default iface.transport_name = tcp node.discovery_address = nas node.discovery_port = 3260 node.discovery_type = send_targets node.session.initial_cmdsn = 0 node.session.initial_login_retry_max = 4 node.session.cmds_max = 128 node.session.queue_depth = 32 node.session.auth.authmethod = None node.session.auth.username = <empty> node.session.auth.password = <empty> node.session.auth.username_in = <empty> node.session.auth.password_in = <empty> node.session.timeo.replacement_timeout = 120 node.session.err_timeo.abort_timeout = 10 node.session.err_timeo.reset_timeout = 30 node.session.iscsi.FastAbort = No node.session.iscsi.InitialR2T = No node.session.iscsi.ImmediateData = Yes node.session.iscsi.FirstBurstLength = 262144 node.session.iscsi.MaxBurstLength = 16776192 node.session.iscsi.DefaultTime2Retain = 0 node.session.iscsi.DefaultTime2Wait = 2 node.session.iscsi.MaxConnections = 1 node.session.iscsi.MaxOutstandingR2T = 1 node.session.iscsi.ERL = 0 node.conn[0].address = 192.168.0.123 node.conn[0].port = 3260 node.conn[0].startup = manual node.conn[0].tcp.window_size = 524288 node.conn[0].tcp.type_of_service = 0 node.conn[0].timeo.logout_timeout = 15 node.conn[0].timeo.login_timeout = 15 node.conn[0].timeo.auth_timeout = 45 node.conn[0].timeo.active_timeout = 5 node.conn[0].timeo.idle_timeout = 60 node.conn[0].timeo.ping_timeout = 5 node.conn[0].timeo.noop_out_interval = 10 node.conn[0].timeo.noop_out_timeout = 15 node.conn[0].iscsi.MaxRecvDataSegmentLength = 131072 node.conn[0].iscsi.HeaderDigest = None,CRC32C node.conn[0].iscsi.DataDigest = None node.conn[0].iscsi.IFMarker = No node.conn[0].iscsi.OFMarker = No
Because I use CHAP authentication I need to provide a username and password, the default values can be seen as follows;
node.session.auth.authmethod = None node.session.auth.username = <empty> node.session.auth.password = <empty>
which we will change as follows (replace
myusername
and
mypassword
as appropriate);
localhost ~ # iscsiadm -m node -o update -n node.session.auth.authmethod -v CHAP localhost ~ # iscsiadm -m node -o update -n node.session.auth.username -v myusername localhost ~ # iscsiadm -m node -o update -n node.session.auth.username -v mypassword
and that should do it! Lets give it a whirl.

Testing

Lets login:
localhost ~ # iscsiadm -m node -l Login session [iface: default, target: iqn.2007-11.localdomain:RAID.iscsi0.vg0.myiscsi, portal: 192.168.0.123,3260]
a quick check of
dmesg
to see if it has worked...
localhost ~ # dmesg | tail -n 13 scsi1 : iSCSI Initiator over TCP/IP scsi 1:0:0:0: Direct-Access THECUS N5200-VDISK 0 PQ: 0 ANSI: 4 sd 1:0:0:0: [sdb] 389021696 512-byte hardware sectors (199179 MB) sd 1:0:0:0: [sdb] Write Protect is off sd 1:0:0:0: [sdb] Mode Sense: 77 00 00 08 sd 1:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA sd 1:0:0:0: [sdb] 389021696 512-byte hardware sectors (199179 MB) sd 1:0:0:0: [sdb] Write Protect is off sd 1:0:0:0: [sdb] Mode Sense: 77 00 00 08 sd 1:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA sd 1:0:0:0: [sdb] Attached SCSI disk sd 1:0:0:0: Attached scsi generic sg1 type 0
Success!! Now we have in essence a network attached SCSI drive, ready to be partitioned, formated and used as if it were in our very own machine! Hopefully all goes well for you also.

Misc

When we are done we can logout of our session as simply as
localhost ~ # iscsiadm -m node -u Logout session [sid: 1, target: iqn.2007-11.localdomain:RAID.iscsi0.vg0.myiscsi, portal: 192.168.0.123,3260]
In addition, because my NAS device exists at home and I move around with my laptop (uni, work etc) I wanted to conditionally mount my iSCSI partition upon boot depending on where I was. I achieved the following by using the following script which I placed in
/etc/init.d/iscsimount
(and start at boot with
rc-update add iscsimount default
)
!/sbin/runscript NAME="iSCSI Automounter" depend() { after iscsid use net } start() { einfo "Starting ${NAME} [for Home use]" if [ `dnsdomainname` = "localdomain" ]; then ebegin "Connecting to iSCSI NAS Portal" iscsiadm -m node -l eend $? sleep 1 ebegin "Mounting iSCSI mount points" mount /mnt/iscsi_data eend $? else einfo "Not at home, skipping..." fi return 0 } stop() { einfo "Stopping ${NAME} [for Home use]" if [ `dnsdomainname` = "localdomain" ]; then ebegin "Unmounting iSCSI mount points" umount /mnt/iscsi_data eend $? ebegin "Disconnecting iSCSI NAS Portal" iscsiadm -m node -u eend $? else einfo "Not at home, skipping..." fi return 0 }
which can be downloaded here if so desired.

References


Last updated: 12th November 2007