Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Ubuntu 18.04 iSCSI Target

In this post, we will configure an Ubuntu 18.04 Iscsi target and manage it using the WebMin web application. You can use this storage for Kubernetes or ESXi.

Currently, I have two ESXi servers that host all of my virtual machines for my home lab.

I want to be able to migrate the virtual machines form one ESXi host to another and vice versa.

The best way to do this is configure network storage and attach that to your ESXi hosts.

This post is a precursor to my building a SAN Server that I will use for my iSCSI storage.

Getting Started

The system has two drives.

The first drive is the operating system drive and will be a 250 GB SSD drive.

The second drive is a 4 TB SATA III drive that will provide the storage.

Since the hardware isn’t here yet, I am using a virtual machine with two virtual drives.

Instead of 4 TB on the second I only created a 100 GB virtual drive.

To begin make sure you have a fresh install of Ubuntu Server 18.04 and that it is fully updated/

apt update && apt upgrade -y

Let’s take a look at my drive arrangement after install.

$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0    7:0    0 86.9M  1 loop /snap/core/4917
sda      8:0    0  250G  0 disk 
├─sda1   8:1    0    1M  0 part 
└─sda2   8:2    0  250G  0 part /
sdb      8:16   0  100G  0 disk 
sr0     11:0    1 1024M  0 rom

My operating system was installed on /dev/sda and /dev/sdb is my storage drive.

Install iSCSI TGTd on Ubuntu

First, to configure our Ubuntu 18.04 iSCSI target we need to install the iSCSI target daemon on our server.

apt install tgt -y

Now we need to Partition our storage drive so that we can use it for iSCSI.

Partition Storage Drive

First, run the fdisk command for your storage drive.

From the lsblk output above, I will use /dev/sdb

fdisk /dev/sdb

Tell fdisk to create a new partition.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p):

Type ‘p’ to create a primary partition.

Next, select the defaults for partition number, first sector and last sector.

Partition number (1-4, default 1): 
First sector (2048-1048575999, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-1048575999, default 1048575999): 

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

Finally, tell fdisk to write the configuration to the disk by typing ‘w’.

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

Our disk is now prepared for sharing with iSCSI.

Installing WebMin

Next let’s get Webmin installed.

This will allow us to manage our server from a secure web page.

Follow this article to install WebMin on Ubuntu 18.04:

Install Webmin on Ubuntu 18.04

After you have Webmin installed we need to configure it to manage iSCSI TGTd.

Installing the iSCSI Webmin Module

Log in to your Webmin interface.

https://{your_server}:10000

In the left menu click on Hardware.

You should see iSCSI TGTd listed in the menu.

If you don’t then click on Refresh Modules at the bottom of the menu.

Click on the iSCSI TGTd menu item.

Configuring the iSCSI Module

We need to configure the module to correctly manage TGT.

Click the gear icon in the upper left.

In the configuration screen we need to configure the paths to tgtd, tgtadm, and tgt-admin:

In addition, we need to change the Bootup script name from tgtd to tgt like above.

Click on Save to save the settings.

Finally, click the Return to index button to continue.

Create an iSCSI Target

Click on the Add a new iSCSI target button.

You will see the Create iSCSI Target screen.

In the first box let’s give our target a name.

In this case, I named it test.

Next, we specify which device to share.

In my case, I selected the partition I created which shows here as SCSI device B partition 1 (Linux EXT).

You can also limit what IPs can see the share and setup CHAP but we will skip that for this tutorial.

Finally, click on the Create button to create the iSCSI share.

To save our settings click on the Restart iSCSI TGTd button.

You Ubuntu 18.04 iSCSI target is now ready to use.

Connect to iSCSI Share

To test our share we will configure another Ubuntu system to use the share.

In my case, I will configure my Ubuntu 18.04 Desktop system to connect to it.

First, I will install the open-iscsi initiator.

apt install open-iscsi -y

Next, we can try to discover our iSCSI share with this command.

iscsiadm -m discovery -t sendtargets -p 192.168.1.23

The IP is the IP address of the iSCSI target server we created earlier.

Running this command we see our IQN that was created.

# iscsiadm -m discovery -t sendtargets -p 192.168.1.23
192.168.1.23:3260,1 iqn.2018-09.lab.admintome.iscsi:test

Connect to the share with this command:

iscsiadm -m node --login

You will see it successfully connect:

Logging in to [iface: default, target: iqn.2018-09.lab.admintome.iscsi:test, portal: 192.168.1.23,3260] (multiple)
Login to [iface: default, target: iqn.2018-09.lab.admintome.iscsi:test, portal: 192.168.1.23,3260] successful.

Your share now shows up as a regular block device.

# lsblk
NAME                  MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                     8:0    0    40G  0 disk 
└─sda1                  8:1    0    40G  0 part 
  ├─ubuntu--vg-root   253:0    0    39G  0 lvm  /
  └─ubuntu--vg-swap_1 253:1    0   976M  0 lvm  [SWAP]
sdb                     8:16   0   100G  0 disk 
sr0                    11:0    1  1024M  0 rom

In my case, it shows up as /dev/sdb.

We can partition it and format it just as we normally would.

Let’s create a 20 GB partition on it.

# fdisk /dev/sdb

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 0x1c28b513.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-209713151, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-209713151, default 209713151): +20G

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

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

Next, lets format it to EXT4.

# mkfs.ext4 /dev/sdb1
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 5242880 4k blocks and 1310720 inodes
Filesystem UUID: 4d40ad52-4142-4a63-8f60-2dee495bf311
Superblock backups stored on blocks: 
  32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
  4096000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Now if we do a lsblk we should see our partition.

# lsblk
NAME                  MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                     8:0    0    40G  0 disk 
└─sda1                  8:1    0    40G  0 part 
  ├─ubuntu--vg-root   253:0    0    39G  0 lvm  /
  └─ubuntu--vg-swap_1 253:1    0   976M  0 lvm  [SWAP]
sdb                     8:16   0   100G  0 disk 
└─sdb1                  8:17   0    20G  0 part 
sr0                    11:0    1  1024M  0 rom

There is our new 20 GB partition as /dev/sdb1.

Now if you would like you can mount it.

# mkdir /data
root@admintome:~# mount /dev/sdb1 /data
root@admintome:~# ls /data
lost+found

Get the UUID of the partition.

# blkid /dev/sdb1
/dev/sdb1: UUID="4d40ad52-4142-4a63-8f60-2dee495bf311" TYPE="ext4" PARTUUID="1c28b513-01"

Copy the UUID so we can put it into our fstab.

To make it stick in a reboot, edit your /etc/fstab file.

# /etc/fstab: static file system information.                                                                                             
#                                                                                                                                         
# Use 'blkid' to print the universally unique identifier for a                                                                            
# device; this may be used with UUID= as a more robust way to name devices                                                                
# that works even if disks are added and removed. See fstab(5).                                                                           
#                                                                                                                                         
#                                                                     
/dev/mapper/ubuntu--vg-root /               ext4    errors=remount-ro 0       1
/dev/mapper/ubuntu--vg-swap_1 none            swap    sw              0       0
UUID=4d40ad52-4142-4a63-8f60-2dee495bf311		      /data	      ext4    _netdev	      0	      0

The last line is the line I added to restore the mount.

Save the file and exit.

Next we need to make sure that open-iscsi logs in after every reboot.

Run the following command to save our connection:

iscsiadm -m node --target iqn.2018-09.lab.admintome.iscsi:test --portal 192.168.1.23:3260 -o new

Next edit your /etc/iscsi//iscsid.conf and change node.startup from manual to automatic:

node.startup = automatic

Save and exit the file.

Restart the open-iscsi service.

systemctl restart open-iscsi

Now your iSCSI mount will be there when you reboot.

Conclusion

In this post demonstrated configuring an Ubuntu 18.04 iSCSI Target and Initiator.

After my hardware comes in, I will write a couple more posts on how to create Kubernetes Persistent Volumes using our iSCSI server and connect shared VMWare ESXi datastore storage.

I hope you have enjoyed this post.

If you did then please share and comment below.

Also be sure to sign up for the AdminTome Blog Newsletter.

The post Ubuntu 18.04 iSCSI Target appeared first on AdminTome Blog.



This post first appeared on AdminTome, please read the originial post: here

Share the post

Ubuntu 18.04 iSCSI Target

×

Subscribe to Admintome

Get updates delivered right to your inbox!

Thank you for your subscription

×