Creating ISCSI Server on Ubuntu 18.04 for VMWAre ESXI 7.0

I’m writing this post after a long time without any publication. I’m back!

I’ve reinstalled my environment with my servers, network stuff and I am ready again.

Let me explain the scenario for this blog.

I’ve an Ubuntu 18.04 running with two sets of array disks: 

  • Raid 1 – 4TB 
  • Raid 2 – 4TB.

Also, I’ve a VMWARE ESXI 7.0 SERVER it is a Dell PowerEdge R610 II with 16 threads, 2.66GHz and 96GB RAM without any kind of disk.The proposal is to use Ubuntu server as a NAS for ESXI providing disks using ISCSI to install VMs.

I choose ISCSI because it seems reliable and stable than NFS. I don’t have a good experience with NFS serving large VMs. If you are interested, I found a good link that explains the differences and advantages. You can read it HERE.

I am really a fan of ISCSI and I have been using it provide disks for VMS and physical severs on my LAB.

Let’s work on it!

1 – Installing ISCSI Server on Ubuntu 18.04

sudo apt-get update
sudo apt-get install tgt -y

2 – Creating a disk image

In this experiment an image file is used as a disk, it means a imgage file is the disk. I’ve other things running on this server and I don’t want to delete them. By the way, using image files really makes the backup easy.

I want to create 1TB image file with blocks of 1megabyte. Therefore we have the following code:

sudo dd if=/dev/zero of=/data/iscsi/blocks/esxi-1.img count=0 bs=1M seek=1M

The block size is defined by bs=1M, and the size is defined by bs * seek

In this case we have 1M * 1M = 1.024GB = 1TB.

You should see a result like this:

0+0 records in
0+0 records out
0 bytes copied, 0,000266841 s, 0,0 kB/s

Let’s check if the image files was created as expected:

ls -las /data/iscsi/blocks/

Result:

total 0
0 drwxr-xr-x 2 root root            24 Feb 17 07:17 .
0 drwxr-xr-x 3 root root            20 Feb 11 21:24 ..
0 -rw-r–r– 1 root root 1099511627776 Feb 17 07:17 esxi-1.img

3 – Creating a Target Server

Basic definitions:

iSCSI Qualified Name (IQN)Format: The iSCSI Qualified Name is documented in RFC 3720, with further examples of names in RFC 3721. Briefly, the fields are:

  • literal iqn (iSCSI Qualified Name)
  • date (yyyy-mm) that the naming authority took ownership of the domain
  • reversed domain name of the authority (e.g. org.alpinelinux, com.example, to.yp.cr)
  • Optional “:” prefixing a storage target name specified by the naming authority.

Considering the definitions above then we have:
iqn.2021-02.io.alexbelle.server1:esxi01

Create a new configuration file for tgt service. I am using the name of the target as the base for the name of this file.

nano /etc/tgt/conf.d/iqn.2021-02.io.alexbelle.server1.conf 

The content is an XML with a simple basic definition:

Target is the qualified name.
backing-store refers to the image file
initiator-address is the IP address of the ISCSI client

Here is the content:


<target iqn.2021-02.io.alexbelle.server1:esxi01>
backing-store /data/iscsi/blocks/esxi-1.img
initiator-address 192.168.200.10
</target>

I did not provide any kind of authentication using CHAP, please keep in your mind that it’s just a test proposal.

4 – Start tgt service

It’s time to start the tgt once everything is done.

systemctl start tgt

Let’s check if it’s working.

systemctl status tgt

5 – ESXI 7.0 ISCSI configuration

Also remember it was not configure to use CHAP AUTHENTICATION. It’s trusted by IP address only.

Now you should be able to see a new device available.

6 – Create a New Datastore

It’s done!

May you want to check on target system if it’s connected, you can use the command below:

tgtadm --mode target --op show 

Enjoy your ISCSI disk.

Published by

Alex Belle

Sportsman by nature, nerd by choice.

Leave a comment