Skip to content

Instantly share code, notes, and snippets.

@thwarted
Created January 16, 2015 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thwarted/d72d915c2813ac2adb84 to your computer and use it in GitHub Desktop.
Save thwarted/d72d915c2813ac2adb84 to your computer and use it in GitHub Desktop.
Simple ISCSI setup in Linux

Mostly gleaned from the instructions at https://wiki.archlinux.org/index.php/ISCSI_Initiator to setup the initiator.

Overview of the steps:

server1 is serving the targets and has IP 10.1.1.1/24 desktop1 is initiator. Both machines are in the 10.1.1.0/24 subnet.

  • installed netbsd-iscsi (yum install netbsd-iscsi in my case for Centos 6.5)

  • updated the netmask in /etc/iscsi/targets to be 10.1.1.0/24.

  • created the empty file that would be the backing store for the target with dd if=/dev/zero of=/tmp/iscsi-target0 bs=1024 count=100000 (this matches what's in the sample config in /etc/iscsi/targets)

  • on server1, service netbsd-iscsi start

  • lsof the netbsd-iscsi process to see which port it was listening on.

  • opened tcp port 3260 on the machine that's the target (iptables -I INPUT -p tcp -s 10.1.1.0/24 --dport 3260 -j ACCEPT)

  • Ran iscsiadm -m discovery -t sendtargets -p 10.1.1.1 on desktop1, and saw that target0 was listed

  • Did iscsiadm -m node -L all to login to all the targets (only one, target0, was found, so that's the only one I was logging into)

  • Did iscsiadm -m session -P 3 and saw which device it was:

    iscsiadm -m session -P 3

             ************************
             Attached SCSI devices:
             ************************
             Host Number: 12 State: running
             scsi12 Channel 00 Id 0 Lun: 0
                     Attached scsi disk sdi          State: running
    
  • on desktop1, mke2fs /dev/sdi (prompted me for whole disk, since I didn't use fdisk to create a partition, hit y)

  • on desktop1, mount /dev/sdi /mnt

  • cp /etc/group /mnt

  • umount /mnt from desktop0

  • logout of the target using iscsiadm -m node -U all

  • on server1, I verified that things were written to the target's backing store with `losetup /dev/loop0 /tmp/iscsi-target0 ; mount /dev/loop0 /mnt ; ls /mnt and saw the group file I copied to it on desktop1. (this is why I didn't run fdisk on /dev/sdi first, so I could easily mount the image on the server using the loopback filesystem without having to calculate partition offsets).

Note that if you have iscsi-initiator-utils and netbsd-iscsi installed on the same machine, both packages put files in /etc/iscsi.

It's unfortunate that ISCSI uses non-standard names for the client and server portions, I find that really confusing. And the target names are overly complex (iqn.1994-04.org.netbsd.iscsi-target:target0 in this default setup, some portion of that is customizable). Getting the target running was pretty straight forward. I find all the initiator side stuff kind of confusing. Of course, you'll want authentication and some kind ACLs on the exported targets, but that's the next step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment