How To Configure iSCSI Initiator on Ubuntu 22.04|20.04

 Thank to: https://techviewleo.com/

iSCSI is a protocol used to transport packets over TCP/IP networks. It is often used to set up shared storage where multiple servers can access central resources as if they existed on the local device.

This setup works using a client-server model with the iSCSI target holding the block storage and the iSCSI initiator configured to send and receive packets from the target.

In our previous guide, we walked through how to configure the iSCSI Target on Ubuntu 22.04|20.04. Today we will cover the required steps on how to configure iSCSI Initiator on Ubuntu 22.04|20.04.

Requirements

This guide will work best if you have the following:

  • Ubuntu 22.04|20.04
  • iSCSI target installed and configured.

The guide below can be used to install and configure the iSCSI target on Ubuntu 22.04|20.04.

Once the requirements have been met, proceed as shown.

#1. Install iSCSI initiator on Ubuntu 22.04|20.04

The iSCSI initiator package exists in the default Ubuntu repositories and can be installed using the command:

sudo apt-get install open-iscsi -y

Dependency tree:

Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  finalrd libisns0 libopeniscsiusr
The following NEW packages will be installed:
  finalrd libisns0 libopeniscsiusr
  open-iscsi
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
.....

#2. Configure iSCSI initiator on Ubuntu 22.04|20.04

Once installed, you need to make a few adjustments for the iSCSI target and initiator to communicate as desired.

Edit the iSCSI initiator name and provide the name set when configuring the iSCSI target ACL.

sudo vim /etc/iscsi/initiatorname.iscsi 

Now modify the line to accommodate your iSCSI initiator. For my case, the initiator is iqn.2022-06.techviewleo.example:node01.initiator01

.......
InitiatorName=iqn.2022-06.techviewleo.example:node01.initiator01

Save the changes and close the file.

If you have authentication set on the target. Proceed and make the below configuration.

sudo vim /etc/iscsi/iscsid.conf 

Under the CHAP Settings uncomment the below lines and edit them accordingly.

#*****************
# Startup settings
#*****************
.......
node.startup = automatic

# *************
# CHAP Settings
# *************
......
node.session.auth.authmethod = CHAP
.....
node.session.auth.username = techviewleo
node.session.auth.password = Passw0rd1
....

Save the changes and restart the service:

sudo systemctl restart iscsid open-iscsi 

#3. Connect to the iSCSI Target

Once the above configurations have been made, the connection between the iSCSI initiator and target needs to be established.

Begin by identifying the shared target.

$ sudo iscsiadm -m discovery -t sendtargets -p 192.168.205.11
192.168.205.11:3260,1 iqn.2022-06.techviewleo.example:dlp.target01

Remember to replace 192.168.205.11 with your iSCSI target IP address.

Confirm the status:

sudo iscsiadm -m node -o show 

Sample Output:

Now log in to the target using the command:

sudo iscsiadm -m node --login 

Sample Output:

Logging in to [iface: default, target: iqn.2022-06.techviewleo.example:dlp.target01, portal: 192.168.205.11,3260]
Login to [iface: default, target: iqn.2022-06.techviewleo.example:dlp.target01, portal: 192.168.205.11,3260] successful.

Verify if the connection has been established:

$ sudo iscsiadm -m session -o show 
tcp: [3] 192.168.205.11:3260,1 iqn.2022-06.techviewleo.example:dlp.target01 (non-flash)

#.4 Create a File System on Shared Backstore

Once the connection has been established, the block storage will be shared with the iSCSI initiator and can be checked with the command:

$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
loop0    7:0    0     4K  1 loop /snap/bare/5
loop1    7:1    0  61.9M  1 loop /snap/core20/1405
loop2    7:2    0 155.6M  1 loop /snap/firefox/1232
......
loop11   7:11   0  45.9M  1 loop /snap/snap-store/582
loop12   7:12   0 254.1M  1 loop /snap/gnome-3-38-2004/106
loop13   7:13   0 162.3M  1 loop /snap/firefox/1443
sdb      8:0    0    5G  0 disk 
sdc      8:16   0   10G  0 disk 
sda    252:0    0    40G  0 disk 
├─sda1 252:1    0     1M  0 part 
├─sda2 252:2    0   513M  0 part /boot/efi
└─sda3 252:3    0  39.5G  0 part /

You can also use the command below to check partitions:

$ cat /proc/partitions 
major minor  #blocks  name

   7        0          4 loop0
   7        1      63380 loop1
........
 252        0   41943040 vda
 252        1       1024 vda1
 252        2     525312 vda2
 252        3   41414656 vda3
   7        8      48080 loop8
   7        9      63412 loop9
   7       10        284 loop10
   7       11      46964 loop11
   7       12     260192 loop12
   7       13     166184 loop13
   8        0   10485760 sdb
   8       16    5242880 sdc

When setting up the iSCSI target, we had two iSCSI Backstores, fileio 5GB storage, and a block storage object of 10GB. The two iSCSI Backstores are now available on the iSCSI initiator as sdb and sdc. The naming may vary depending on the available disks on your system.

Now create a file system on the shared Backstores.

For this guide, I will use parted:

sudo parted --script /dev/sdb "mklabel gpt"
sudo parted --script /dev/sdb "mkpart primary 0% 100%"

Do this for any other disk depending on the available backstores.

Now proceed and format the partition to EXT4.

sudo mkfs.ext4 /dev/sdb1

Mount the disk.

sudo mount /dev/sdb1 /mnt

Verify this:

df -hT

Sample Output:



Proceed and write data to the disk.

sudo mkdir /mnt/new

That is it!

Comentarios

Entradas populares de este blog

Guía de herramientas básicas para estudiantes: 31 apps y webs imprescindibles para ayudarte con los estudios

Comando FOR para archivos BAT

How to Fix Failed to Connect a Hyper-V Standalone to Veeam Backup