2009-10-09

Using the SheevaPlug as an iSCSI target for Vista or Windows 7

(Updated 2010.08.08)

Well, since I played with this iScsi stuff just for the sake of it, I might as well post a quick guide.

For this setup, I will be using the SheevaPlug running Slackware 13.0 (armedslack) on an SDIO card, a 100 GB HDD connected to the plug through USB (/dev/sda, but you could use a partition or even an image file) and a version of Windows that supports iSCSI (Vista or later). The SheevaPlug server has been creatively named "sheeva".

Compiling

The de-facto iSCSI target server tool for Linux is the Linux SCSI target framework (tgt) project (NB: you know you need to come up with better designation when your URL is actually shorter than your project name), so off we go and download the latest version (Important note: at the time of this post update, version 1.0.7 doesn't appear to work for the SheevaPlug, but 1.0.5 does).
We're pretty much going to follow the "./doc/README.iscsi" from the archive, so you might want to keep that file open for reference.
Once extracted on the SheevaPlug, cd to the usr/ directory and issue a "make ISCSI=1; make install". This package is not that big, so we can compile it on the Plug directly. Remember to add ISCSI=1, as default make will not have iSCSI.

Starting the target server daemon

After that, as root, you need to launch the daemon with
tgtd
The syslog should tell you that everything's rolling with a line like
Oct  9 12:46:23 sheeva tgtd: Target daemon logger with pid=1897 started!

Setting up the iSCSI target

This is where the bulk of our configuration occurs. What we're going to set below is an iSCSI drive named "sheeva:hd100" that maps to our /dev/sda HDD.

  1. First we need to create that device:
    root@sheeva:~# tgtadm --lld iscsi --mode target --op new --tid 1 --target sheeva:hd100
    root@sheeva:~# tgtadm --lld iscsi --mode target --op show
    Target 1: sheeva:hd100
    System information:
    Driver: iscsi
    State: ready
    I_T nexus information:
    LUN information:
    LUN: 0
    Type: controller
    SCSI ID: IET 00010000
    SCSI SN: beaf10
    Size: 0 MB
    Online: Yes
    Removable media: No
    Backing store type: rdwr
    Backing store path: None
    Account information:
    ACL information:
    root@sheeva:~#
  2. Now, despite the fact that a device with LUN0 was created as shown above, this is just a virtual controller device, not a physical target, and we still need to create a LUN for our device:
    root@sheeva:~# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 --backing-store /dev/sda
    root@sheeva:~# tgtadm --lld iscsi --mode target --op show
    Target 1: sheeva:hd100
    System information:
    Driver: iscsi
    State: ready
    I_T nexus information:
    LUN information:
    LUN: 0
    Type: controller
    SCSI ID: IET 00010000
    SCSI SN: beaf10
    Size: 0 MB
    Online: Yes
    Removable media: No
    Backing store type: rdwr
    Backing store path: None
    LUN: 1
    Type: disk
    SCSI ID: IET 00010001
    SCSI SN: beaf11
    Size: 100030 MB
    Online: Yes
    Removable media: No
    Backing store type: rdwr
    Backing store path: /dev/sda
    Account information:
    ACL information:
    root@sheeva:~#
    This time, we have our physical device listed. Note that you could also mount a partition instead of a whole device, and make it appear as a device through iSCSI

  3. At this stage, we have a target, but it doesn't accept inbound connections ("ACL information" is empty), so:
    root@sheeva:~# tgtadm --lld iscsi --mode target --op bind --tid 1 --initiator-address ALL
    root@sheeva:~# tgtadm --lld iscsi --mode target --op show
    Target 1: sheeva:hd100
    System information:
    Driver: iscsi
    State: ready
    I_T nexus information:
    LUN information:
    LUN: 0
    Type: controller
    SCSI ID: IET 00010000
    SCSI SN: beaf10
    Size: 0 MB
    Online: Yes
    Removable media: No
    Backing store type: rdwr
    Backing store path: None
    LUN: 1
    Type: disk
    SCSI ID: IET 00010001
    SCSI SN: beaf11
    Size: 100030 MB
    Online: Yes
    Removable media: No
    Backing store type: rdwr
    Backing store path: /dev/sda
    Account information:
    ACL information:
    ALL
    root@sheeva:~#
  4. Here you might want to find out if Windows is able to see our target, so you can fire up the iSCSI Initiator (in Control Panel -> Administrative Tools). If you are prompted to enable the iSCSI service on startup and modify the firewall rules, accept it.
    Now, if you go to the "Targets" tab and press Refresh, you'll probably see that your target is not yet detected.
    To make it appear in the target list, you want to go to the "Discovery" tab and click "Add/Discover Portal". Then provide the IP/DNS of your server. Port 3260 should be fine as it's used by the Target daemon on the Linux server.
    After doing this, if you go to the "Targets" tab again, you should see something like this listed:
    sheeva:hd100              Inactive
    If not, you might want to check your daemon, firewall, etc. as you should be able to detect the target at this stage.

  5. If you're fine with anybody being able to connect to our iSCSI target on your network, then you can just try to press "Log On" in the Targets tab, and you should be able to connect. You can then go to Computer Management, and you should be able to see the disk!
    You should also see who is connect to your target in the "I_T nexus information" section from tgtadm in Linux:
    root@sheeva:~# tgtadm --lld iscsi --mode target --op show
    Target 1: sheeva:hd100
    System information:
    Driver: iscsi
    State: ready
    I_T nexus information:
    I_T nexus: 4
    Initiator: iqn.1991-05.com.microsoft:dusk
    Connection: 1
    IP Address: 192.168.1.184
    LUN information:
    LUN: 0
    Type: controller
    SCSI ID: IET 00010000
    SCSI SN: beaf10
    Size: 0 MB
    Online: Yes
    Removable media: No
    Backing store type: rdwr
    Backing store path: None
    LUN: 1
    Type: disk
    SCSI ID: IET 00010001
    SCSI SN: beaf11
    Size: 100030 MB
    Online: Yes
    Removable media: No
    Backing store type: rdwr
    Backing store path: /dev/sda
    Account information:
    ACL information:
    ALL
    root@sheeva:~#
    Pretty cool, heh?
    If you do want to restrict access, you should of course follow the README.iscsi and add iSCSI target accounts. Then you can provide these credentials to the CHAP logon parameters in Windows (which can be accessed by clicking "Advanced" in the "Log On to Target" dialog. Be warned however that Windows will return a "CHAP secret given does not conform to the standard" error if your password is too short, so you need to make it at least 10 characters or more.
    To disconnect from a target, on Vista, simply click on "Details", select its Identifier and click "Log off...". For Windows 7, Microsoft did the wise thing and added a "Disconnect" button.

    IMPORTANT NOTE: Because we used LUN 1, and not LUN 0, if you attempt to boot from this newly created iSCSI disk, you MUST fill in the LUN parameter in the iSCSI root path syntax (the sequence of 4 columns that most guides will leave blank). In our case, if we wanted to use the device above for booting with gpxe/dnsmasq, we would add the following in dnsmasq.conf:
    dhcp-option=net:gpxe,17,"iscsi:192.168.1.3:::1:sheeva:hd1"
    Notice that there is a "1" for the LUN before "sheeva:hd1" and that we used :::1: instead of ::::. Likewise if you use a nonstandard port (different than 3260), you would use something like ::<custom port>:<LUN>:<target name>. This is detailed in RFC 4173, or you can find more information here.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.