Tuesday, March 8, 2011

Using Ubuntu 10.10 to Setup Inexpensive Network Storage

The cost of network storage can be reduced if many of the feature options offered by existing storage vendors are not required. For example if volume snapshots are not necessary. In this article, I will demonstrate how to setup a PC to act as an iscsi target to allow access to the systems storage from any designated system.



The first thing to consider when setting up a low cost storage solution is how much drive redundancy is required. Even if the end user tells you "It's no big deal if the data stored at this location gets lost," think twice about that. Ask yourself, is my company willing to risk data loss for an important file inadvertently saved in this location. Redundant Array of Inexpensive Disks (or RAID) has been a solution to single disk failures for many years. If drive redundancy is desired, do NOT implement a software based RAID solution. Many inexpensive motherboards exist on the market with RAID capabilities on-board. Additionally add-in hardware RAID controllers on todays market also very affordable. Both of these items make the decision to use a software RAID solution (when looking as robustness and performance) unsound.



All of this being said, let us assume that a system is available that has a Pentium Processor, 2GB of RAM, and a Array of hard disks. Onto this system install Ubuntu 10.10 server software. This can be obtained from their website. Once installed and patched follow the steps below


  1. Install the iscsi target software using the command

    sudo apt-get install iscsitarget

  2. Configure the storage location on the Target. The location can be a disk drive or a file:

    1. To configure the storage inside of a file, as root create the file at the desired location using the command:

      dd if=/dev/zero of=<fileloaction>/<filename> bs=1024k count=<number of 1M blocks>

    2. To configure storage as a drive, make certain that the drive is not mounted. Partition as necessary.


  3. Enable iscsitarget by editing /etc/default/iscsitarget and set the line

    ISCSITARGET_ENABLE=True

  4. Edit the ietd.conf in /etc/iet, enter the following lines

    Target iqn.<yyyy-mm>.<reversedomainname>:<global unique id>

    IncomingUser <username><secret>

    OutgoingUser <username><secret>

    Lun <#> Path=<path to drive or file>,Type=<Fileio or Blockio>

    :

  5. Edit the initiators.allow in /etc/iet, enter the following:

    Target iqn.<yyyy-mm>.<reversedomainname>:<global unique id> <IP of Initiator>

  6. Start the iscsitarget daemon by executing /etc/init.d/iscsitarget start




Review the startup messages by issuing dmesg to verify proper startup. Now configure the iscsi initiator from the client and all is good to go..


The meat of the configuration is in step 4 above. Lets look at this in more detail.


The first line identifies the target. This target name must be globally unique in the network. Typically the unique id could be configured with hostname.<some qualifier>. For example, assume a network called home.com exists. On this network an ISCSI Target host name exists called ISCT1. If this target was configured in March of 2010, we could set line 1 to:


Target iqn.2010-03.com.home:ISCT1.myid1


where myid1 is some random definition that is unique to the network.


Line 2 allows for specification of logon credentials to the device. Note that the intiators,allow setting s will limit access to the target from a specific initiator IP. If further access is restricted based on username, enter it here. If not required, enter no information after IncomingUser.


Line 3 allows for authentication of the Target to the initiator, if requried. If not enter no information after OutgoingUser.


Line 4 and on is the definition for each storage device in this target. Multiple LUNs can be defined. For example: if a entire partion (eg. /dev/sdh1) is to be presented to the initiator as well as 2 individual files (eg. /storage/lun5.img and /storage/lun6.img) The entries might appear as:


Lun 0 Path=/dev/sdh1.Type=Fileio


Lun 1 Path=/storage/lun5.img,Type=Fileio


Lun 2 Path=/storage/lun6.img,Type=Fileio


I've identified only some of the items the can be defined in the ietd.conf file. For complete information, refer to the ietd.conf man page


Finally, in step 5 above the initiators.allow file mapps the target name to the initiator IP. Thus only the IP of the specified initiator can access the Target.