IntroductionAs storage requirements continue to grow, external storage is becoming increasingly popular. While the simplest way to deal with this growing demand is to attach an external hard drive via USB, many users demand more power and flexibility; for example, the ability to provide storage over a network, or divide storage for various uses. For this, SAN, or Storage Area Network, is the most powerful tool available, and iSCSI is a free and common way to create a SAN.
This article will discuss how to create a simple Storage Area Network with a file server presenting storage to another machine.
Some SCSI TerminologyIf you are already familiar with SCSI, you can skip this section. Otherwise, give it a read before you continue. I will be using these terms extensively throughout the rest of the article.
Target - Your iSCSI Target server is the server that physically has the storage, and is presenting it over the network to the initiator. Essentially, your fileserver is your target.
Initiator - The initiator is the machine on which the target’s storage will be mounted and used, over the network. This is your HTPC, your workstation, laptop, etc..
LUN – I will be calling any unit of storage shared over iSCSI a LUN. LUN actually stands for Logical Unit Number, or the number assigned to this unit of storage. It is a logical unit (as opposed to a physical unit), so an entire RAID array, a single partition, even a file, can become a LUN and used for storage.
Setting up the TargetThe first step is to setup your storage server with the necessary software. You’ll have to install the iscsitarget daemon, which can be installed on Ubuntu/Debian systems with the command:
sudo apt-get install iscsitargetOnce that’s installed, it’s necessary to do some configuration in the /etc/ietd.conf file to specify what you want to share over the network. You can share a block device (e.g, a hard disk, a partition), a RAID array, an LVM device, or even a file (this file can be an ISO of a DVD, or just some empty file you’ve created to act as an independant storage device. I’ll talk more about this later). Here, I will be sharing a Linux MD device (a software RAID device) as well as a 50GB file.
Configuring /etc/ietd.confThe ietd.conf file usually comes with some examples, but they’re confusing and not all that helpful. It’s easier to just write your iSCSI target lines at the bottom, by hand. The /etc/ietd.conf file is only readable and editable by root, so open it with your favorite text editor, for example “gedit”, like so:
sudo gedit /etc/ietd.confFor my setup, sharing a single MD device and a single file, I added the following lines to my configuration file:
Lun 0 Path=/dev/md0,Type=blockio
Lun 1 Path=/root/fiftyGBFile,Type=fileio
That’s all that I needed to configure in this file. Obviously yours will be different; here is what the lines mean:
This defines an iSCSI target, as discussed above in the terminology section. The “iqn…” part is the target’s name, which must be unique. The name takes the format:
YYYY-MM is the year and month that the target becomes valid, so it is the current year and month.
The domain name is the name of the machine on the network; if you are sharing over the internet, you will want to use your actual domain name (in reverse order, so com.example instead of example.com). If you are just sharing over your home network, you only need to specify your hostname.
Finally, specify a unique identifier for this target. I used “storage.homeShare”, because this is the share for my home. You may chose something more descriptive, such as “mediaTarget” or “remote.backupServer”.
The next two lines specify which LUNs are shared through this target, starting with 0. You must define a path and a type.
Lun 0 Path=/dev/md0,Type=blockio
In this example I am specifying /dev/md0 which is a 2TB software RAID volume, and /root/fifty50GBFile, which is a blank file I created using the command:
sudo dd if=/dev/zero of=/root/fiftyGBFile bs=512K count=102400Of course, for files you could have chosen (for example) an ISO or IMG file, to be mounted by the iSCSI initiator as-is. In this case, I created a blank file because I plan to write a filesystem to it and use it as a backup device. Then, this file will contain an ext3 filesystem which can be mounted by any computer to access my backups, as opposed to having a physical disk for backup.
The Type= line determines how iSCSI will treat writing to the device. In my case, I want to treat my RAID device using blockio, but the file I created using fileio. If in doubt, use fileio, or read more about these two options in the manual for iscsi.
Once you have finished editing your ietd.conf file, save it and restart the iscsitarget daemon, for the changes to load:
sudo /etc/init.d/iscsitarget restartNow you are ready to move on to the initiator, who will receive the storage from the target.
Setting up the InitiatorThe first thing to do is install the initiator software, which is the open-iscsi package. In Debian/Ubuntu Linux, this can be done with the command:
sudo apt-get install open-iscsiNext, you will need to make sure it is started:
sudo /etc/init.d/open-iscsi startNow, you need the initiator software to “discover” any iSCSI devices being shared by your storage server. To do this, simply run:
sudo iscsi_discovery -d [server IP address]If everything is setup correctly, the iscsi_discovery tool will report back that it has found a target. For example:
jdeprizi@enterprise:~$ sudo iscsi_discovery -d 192.168.0.6
Set target iqn.2009-01.voyager:storage.homeShare to automatic login over iser to portal 192.168.0.6:3260
discovered 1 targets at 192.168.0.6, connected to 1
To verify that it worked correctly, you can run the command:
cat /proc/scsi/scsiIf all has gone as planned, you will see one “VIRTUAL DISK” for each LUN you created. To see where these devices have shown up on your system, use the command:
cat /proc/partitionsIn my case, I have created two LUNs; so I see two “VIRTUAL DISKS” of LUN 0 and LUN 1:
Host: scsi3 Channel: 00 Id: 00 Lun: 00 Vendor: IET Model: VIRTUAL-DISK Rev: 0 Type: Direct-Access ANSI SCSI revision: 04 Host: scsi3 Channel: 00 Id: 00 Lun: 01 Vendor: IET Model: VIRTUAL-DISK Rev: 0 Type: Direct-Access ANSI SCSI revision: 04And when I view /proc/partitions, I see my devices at sdc and sdd:
8 32 1953524992 sdc
8 48 52428800 sdd
Controlling the devicesFinally, you are ready to use your iSCSI shared devices. You can treat them like you would a normal disk attached to your system, which is the real power of this technology. You can create a filesystem on them, even partition them into smaller pieces, as you would a physical hard drive.
This is mostly outside the scope of this article, but for a quick demonstration, if I were to format the 50GB LUN (sdd on my initiator) as ext3 and mount it, I could do:
sudo /sbin/mkfs.ext3 /dev/sdd sudo mount /dev/sdd /media/backupdrive
ConclusionUsing iSCSI technology to create a simple Storage Area Network isn’t the easiest task imaginable, but it really isn’t too hard, especially for a basic home setup. Sharing the devices over gigabit ethernet means file transfers are fast enough that you can use your network shares as if they are local, and, with iSCSI/SAN, you can treat them that way, too: creating partitions, writing individual file systems, and mounting them as their own devices.