I recently found myself needing more disk space on a system, but unfortunately the system concerned can only take one hard disk and I didn’t want to buy a bigger hard disk because I’ve got a load of smaller drives spare. So I figured I’d whack a hard disk into a USB enclosure and connect it to my server (rather than shut the server down to add the hard disk properly). As I’d been waiting for an excuse to play with iSCSI, I figured I’d give it a go rather than share the drive by NFS as I usually would.
There are basically two halves to iSCSI: a target, which is the device you want to share and an initiator, a system that wants to access the shared device. So on one system you need to setup and configure iSCSI target software and on the other initiator software.
I started by downloading, compiling and installing iSCSI Enterprise Target onto my server. Once installed, you need to set-up a configuration file (/etc/ietd.conf) to share the device which looks hideous, but actually it’s not too hard. This is mine:
Lun 0 Path=/dev/sdb,Type=fileio
Alias myth
MaxConnections 1
The first line has to be in a particular format:
So it’s basically the date, the machine’s domain name reversed and a made-up identifier (I used ‘myth’ as the disk is for use by MythTV).
Then I give it the device node (sdb), give it an alias and specify that only one initiator may be connected at any one time. You can define security (a username and password, allowed/disallowed hosts etc.) but I’m on a secure network so I didn’t bother. That’s all the required configuration, now start the daemon:
On the initiator machine I downloaded, compiled and installed Open-iSCSI. The configuration of this is a bit more of a pain, but not too bad. Once it’s installed, you’ll need to run ‘depmod -a’ to allow the kernel to find the newly-installed modules.
You need to start by creating a configuration file called /etc/iscsi/initiatorname.iscsi. Mine is:
InitiatorAlias=mythtv
Basically you just have to make up a name and an alias, which the machine will use to identify itself to the target.
Now you need to start the iscsi daemon:
Now you need to configure the daemon to automatically connect to the target when started. First you need to ‘discover’ the target using the iscsi_discovery command:
In my case, this returns:
Testing iser-login to target iqn.2007-03.uk.co.demon.lug:myth portal 10.0.0.254:3260
starting to test tcp-login to target iqn.2007-03.uk.co.demon.lug:myth portal 10.0.0.254:3260
discovered 1 targets at 10.0.0.254, connected to 0
That demonstrates that the connection is working. Now you can configure the daemon to connect automatically at start:
In my case, I did:
Now you need to restart the daemon. There’s a slight bug in the iscsi daemon which means that it doesn’t shut down properly (it isn’t really considered ’stable’ yet), so in addition to stopping it via the init script (/etc/init.d/open-iscsi stop) you’ll need to kill it off manually then restart it:
All being well, the hard disk should have appeared, so you can access it just like a physical disk connected by SCSI or USB – check in dmesg:
iscsi: registered transport (tcp)
scsi0 : iSCSI Initiator over TCP/IP
scsi 0:0:0:0: Direct-Access IET VIRTUAL-DISK 0 PQ: 0 ANSI: 4
SCSI device sda: 160086528 512-byte hdwr sectors (81964 MB)
sda: Write Protect is off
sda: Mode Sense: 77 00 00 08
SCSI device sda: drive cache: write through
SCSI device sda: 160086528 512-byte hdwr sectors (81964 MB)
sda: Write Protect is off
sda: Mode Sense: 77 00 00 08
SCSI device sda: drive cache: write through
sda: sda1 sda2 < sda5 >
sd 0:0:0:0: Attached scsi disk sda
sd 0:0:0:0: Attached scsi generic sg0 type 0
Now you can enjoy the iSCSI-goodness. Sure sharing with NFS is easier, but apparently iSCSI is faster (actually, it probably doesn’t help very much at all when you’re talking over USB using emulated-SCSI to an IDE disk…).



