Setting Up an iSCSI Storage Server on Ubuntu 18.04 LTS: A Comprehensive Guide

iSCSI, standing for Internet Small Computer System Interface, is a Storage Area Network (SAN) protocol utilized for online storage management. It is an IP-based storage networking standard that provides block-level access to storage devices by carrying SCSI commands over a TCP/IP network.

iSCSI comprises two main components: the iSCSI target and iSCSI initiator. The iSCSI target is a service on the iSCSI server offering access to shared storage, whereas the iSCSI initiator is a client connecting to the target to access the shared storage.

In this guide, we will demonstrate how to set up an iSCSI target and initiator on an Ubuntu 18.04 server.

Requirements

  • A fresh Ubuntu 18.04 server for iSCSI target with a 2GB external HDD.
  • A fresh Ubuntu 18.04 server for iSCSI initiator.
  • A static IP address 192.168.0.103 configured on the iSCSI target and 192.168.0.102 on the iSCSI initiator.
  • Root passwords configured on both servers.

Getting Started

Begin by updating both servers to the latest version. Execute the following commands on both servers:

    apt-get update -y
    apt-get upgrade -y

Reboot both servers to apply changes.

Install iSCSI Target

First, install the Target Framework (TGT) package on the iSCSI target server using the command:

apt-get install tgt -y

After installation, check the TGT status by running:

systemctl status tgt

Expected output:

  ? tgt.service - (i)SCSI target daemon
     Loaded: loaded (/lib/systemd/system/tgt.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2019-11-08 07:40:28 UTC; 27s ago
       Docs: man:tgtd(8)
    Main PID: 2343 (tgtd)
     Status: "Starting event loop..."
      Tasks: 1
     CGroup: /system.slice/tgt.service
             ??2343 /usr/sbin/tgtd -f

  Nov 08 07:40:28 ubuntu systemd[1]: Starting (i)SCSI target daemon...
  Nov 08 07:40:28 ubuntu tgtd[2343]: tgtd: iser_ib_init(3431) Failed to initialize RDMA; load kernel modules?
  Nov 08 07:40:28 ubuntu tgtd[2343]: tgtd: work_timer_start(146) use timer_fd based scheduler
  Nov 08 07:40:28 ubuntu tgtd[2343]: tgtd: bs_init(387) use signalfd notification
  Nov 08 07:40:28 ubuntu systemd[1]: Started (i)SCSI target daemon.

Configure iSCSI Target

Next, create a Logical Unit Number (LUN) device on your iSCSI server. The LUN is a backend storage device that the initiator will later use. Create the configuration file in the /etc/tgt/conf.d directory:

nano /etc/tgt/conf.d/iscsi.conf

Add the following configuration:

    <target iqn.2019-11.example.com:lun1>
         # Provided device as an iSCSI target
         backing-store /dev/sdb1                             
         initiator-address 192.168.0.102 
        incominguser iscsi-user password
         outgoinguser iscsi-target secretpass
    </target>

Save the changes and restart the TGT service:

systemctl restart tgt

Configuration explanations:

  • target: Name of the specific target.
  • backing-store: Specifies the storage disk for the initiator.
  • initiator-address: IP address of the initiator.
  • incominguser: Provides security credentials for LUN access.
  • outgoinguser: Used for mutual CHAP authentication.

Verify the iSCSI target server:

tgtadm --mode target --op show

Expected output confirming the target availability:

  Target 1: iqn.2019-11.example.com:lun1
      System information:
          Driver: iscsi
          State: ready
      I_T nexus information:
      LUN information:
          LUN: 0
              Type: controller
              SCSI ID: IET     00010000
              SCSI SN: beaf10
              Size: 0 MB, Block size: 1
              Online: Yes
              Removable media: No
              Prevent removal: No
              Readonly: No
              SWP: No
              Thin-provisioning: No
              Backing store type: null
              Backing store path: None
              Backing store flags: 
          LUN: 1
              Type: disk
              SCSI ID: IET     00010001
              SCSI SN: beaf11
              Size: 2146 MB, Block size: 512
              Online: Yes
              Removable media: No
              Prevent removal: No
              Readonly: No
              SWP: No
              Thin-provisioning: No
              Backing store type: rdwr
              Backing store path: /dev/sdb1
              Backing store flags: 
      Account information:
          iscsi-user
          iscsi-target (outgoing)
      ACL information:
          192.168.0.102

Install and Configure iSCSI Initiator

On the iSCSI initiator server, install the iSCSI Initiator package:

apt-get install open-iscsi -y

Then, discover the target on the iSCSI target server:

iscsiadm -m discovery -t st -p 192.168.0.103

Expected discovery output:

  192.168.0.103:3260,1 iqn.2019-11.example.com:lun1

This command generates files with LUN information. List them with:

ls -l /etc/iscsi/nodes/iqn.2019-11.example.com\:lun1/192.168.0.103\,3260\,1/ /etc/iscsi/send_targets/192.168.0.103,3260/

Expected files:

  /etc/iscsi/nodes/iqn.2019-11.example.com:lun1/192.168.0.103,3260,1/:
  total 4
  -rw------- 1 root root 1840 Nov  8 13:17 default

  /etc/iscsi/send_targets/192.168.0.103,3260/:
  total 8
  lrwxrwxrwx 1 root root  66 Nov  8 13:17 iqn.2019-11.example.com:lun1,192.168.0.103,3260,1,default -> /etc/iscsi/nodes/iqn.2019-11.example.com:lun1/192.168.0.103,3260,1
  -rw------- 1 root root 547 Nov  8 13:17 st_config

Edit the default file to define the CHAP credentials for accessing the iSCSI target:

nano /etc/iscsi/nodes/iqn.2019-11.example.com\:lun1/192.168.0.103\,3260\,1/default

Update the following lines:

  node.session.auth.authmethod = CHAP  
  node.session.auth.username = iscsi-user
  node.session.auth.password = password          
  node.session.auth.username_in = iscsi-target
  node.session.auth.password_in = secretpass         
  node.startup = automatic

Save and restart the iSCSI initiator service:

systemctl restart open-iscsi

Expected service restart output:

   * Unmounting iscsi-backed filesystems                                                                                                  [ OK ] 
   * Disconnecting iSCSI targets                                                                                                                 iscsiadm: No matching sessions found
                                                                                                                                        [ OK ]
   * Stopping iSCSI initiator service                                                                                                     [ OK ] 
   * Starting iSCSI initiator service iscsid                                                                                              [ OK ] 
   * Setting up iSCSI targets                                                                                                                    
  Logging in to [iface: default, target: iqn.2019-11.example.com:lun1, portal: 192.168.0.103,3260] (multiple)
  Login to [iface: default, target: iqn.2019-11.example.com:lun1, portal: 192.168.0.103,3260] successful.
                                                                                                                                        [ OK ]
   * Mounting network filesystems                                                                                                         [ OK ] 

Verify the storage disk is shared from the iSCSI target with:

lsblk

Expected disk availability:

  NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
  sda      8:0    0 465.8G  0 disk 
  ??sda1   8:1    0  93.1G  0 part /
  ??sda2   8:2    0     1K  0 part 
  ??sda5   8:5    0 186.3G  0 part /home
  ??sda6   8:6    0 181.6G  0 part /Data
  ??sda7   8:7    0   4.8G  0 part [SWAP]
  sdb      8:16   0     2G  0 disk 

Verify iSCSI connections:

tgtadm --mode conn --op show --tid 1

Expected output:

  Session: 1
      Connection: 0
          Initiator: iqn.1993-08.org.debian:01:2e1e2383de41
          IP Address: 192.168.0.102

Create Filesystem and Mount the Shared Device

Create a filesystem on the shared device (sdb) to make it usable:

fdisk /dev/sdb

Expected output walkthrough for partition creation:

  Welcome to fdisk (util-linux 2.31.1).
  Changes will remain in memory only, until you decide to write them.
  Be careful before using the write command.

  Device does not contain a recognized partition table.
  Created a new DOS disklabel with disk identifier 0x06091fe8.

  Command (m for help): n
  Partition type
     p   primary (0 primary, 0 extended, 4 free)
     e   extended (container for logical partitions)
  Select (default p): p
  Partition number (1-4, default 1):
  First sector (2048-4194303, default 2048):
  Last sector, +sectors or +size{K,M,G,T,P} (2048-4194303, default 4194303):

  Created a new partition 1 of type 'Linux' and of size 2 GiB.

  Command (m for help): w
  The partition table has been altered.
  Calling ioctl() to re-read partition table.
  Syncing disks.

Format the partition:

mkfs.ext4 /dev/sdb1

Mount the partition to the /mnt directory:

mount /dev/sdb1 /mnt

Verify the mounted device:

df -h

Expected output showing the mounted device:

  Filesystem      Size  Used Avail Use% Mounted on
  udev            1.9G  4.0K  1.9G   1% /dev
  tmpfs           384M  1.2M  383M   1% /run
  /dev/sda1        92G   36G   51G  42% /
  none            4.0K     0  4.0K   0% /sys/fs/cgroup
  none            5.0M     0  5.0M   0% /run/lock
  none            1.9G   54M  1.9G   3% /run/shm
  none            100M   48K  100M   1% /run/user
  /dev/sda5       184G   96G   79G  55% /home
  /dev/sda6       179G   32G  138G  19% /Data
  /dev/sdb1       2.0G  3.0M  1.9G   1% /mnt

Congratulations! You have successfully installed and configured an iSCSI target server and connected to it from an iSCSI initiator. You can now use this shared iSCSI device like a normal attached disk.

FAQ

  • What is iSCSI?
    iSCSI, or Internet Small Computer System Interface, is a storage networking standard for accessing storage devices over an IP network.
  • What are the primary components of iSCSI?
    iSCSI consists of an iSCSI target, which provides access to shared storage, and an iSCSI initiator, which acts as a client to access the target.
  • Which Ubuntu version is this guide for?
    This guide is tailored for Ubuntu 18.04 servers.
  • How much external storage is required for the iSCSI target?
    A 2GB external HDD is required for the iSCSI target in this setup.
  • How do I verify if the iSCSI target is available?
    Use the command `tgtadm –mode target –op show` on the target server to verify availability.
  • What authentication method is used with iSCSI?
    CHAP (Challenge-Handshake Authentication Protocol) is used for authentication in this setup.