This post is even more of a memory aid than normal; it’s really only useful to me.

Source. I assume Ubuntu is similar.

To create an iSCSI target, first install the software:

aptitude install iscsitarget iscsitarget-modules-2.6-amd64

Edit /etc/default/iscsitarget and put in:

ISCSITARGET_ENABLE=true

Edit /etc/ietd.conf and put in something like this (do man ietd.conf for explanation of the parameters):

Target iqn.2010-12.com.example.host:storage.lun1
  # no user based auth (user and pass empty)
  IncomingUser
  # no user based auth (user and pass empty)
  OutgoingUser
  # Path can be any file or block device, also /dev/sdb
  Lun 0 Path=/dev/sdb1,Type=blockio
  Alias LUN1

/etc/initiators.allow and /etc/initiators.deny should both be empty, and therefore allow all. Use iptables to restrict access to hosts.

Then can start /etc/init.d/iscsitarget start

As for the initiator:

aptitude install open-iscsi

Edit /etc/iscsi/iscsid.conf and change the line:

node.startup = automatic

Then tell it to look for volume groups after starting (because when booting, lvm is started before iscsi). Edit /etc/default/open-iscsi:

LVMGROUPS="vgname"

Then start the deamon (wasn’t it active already…?):

/etc/init.d/open-iscsi restart

Then discover and build the node database (in /etc/iscsi/nodes) for your target (when you do that again, it overwrites, so I don’t know what you should do when you’ve added a target on the server):

iscsiadm -m discovery -t st -p ipaddress

Then login:

# You can logout again by using this line and replacing login with logout.
iscsiadm -m node --targetname "iqn.2010-12.com.example.host:storage.lun1" --portal "192.168.0.102" --login

Disk is now available under a device node like /dev/sdb. I don’t know how I could fix this to a specific device, to prevent changes when you change the hard disk configuration. Perhaps I can configure a udev rule for the lun in question.