Steps to Connect And Mount ISCSI Target on Linux Server
Internet Small Computer System Interface (iSCSI) is an IP-based standard for connecting storage devices. iSCSI uses IP networks and allows data to be transferred over long distances. iSCSI provides shared storage among client systems. Storage devices are attached to servers (targets). Client systems (initiators) access the remote storage devices over IP networks. To the client systems, the storage devices appear to be locally attached.
In this blog post, we are going to discuss Steps that need to follow to connect and mount ISCSI target on Linux Server. To know steps for How to move iSCSI Target to Another Linux Server Click here to read more.
Follow below Steps
1. Install iscsi-initiator-utils rpm package on client Linux Machine
2. Share iSCSI initiator ID with Storage Admin
3. Discovering & Login to targets in iSCSI LUN
4. Check if the disk added Linux Machine
5. Create a partition on newly attached disk
6. Create afile system on the partition
7. Add entry in /etc/fstab and mount
Step 1. Install iscsi-initiator-utils rpm package on client Linux Machine: To use the Linux system as an iSCSI initiator or client, We need to install iscsi-initiator-utils rpm package. Use OS yum command to install the required packages. Please note we are using OLE 7.9 for this demo.
[root@test-machine01 ~]#
[root@test-machine01 ~]# cat /etc/oracle-release
Oracle Linux Server release 7.9
[root@test-machine01 ~]#
[root@test-machine01 ~]# yum install iscsi-initiator-utils
Resolving Dependencies
--> Running transaction check
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================================================
Installing:
iscsi-initiator-utils x86_64 6.2.0.874-22.0.1.el7_9 ol7_latest 429 k
Installing for dependencies:
iscsi-initiator-utils-iscsiuio x86_64 6.2.0.874-22.0.1.el7_9 ol7_latest 96 k
Transaction Summary
==============================================================================================================================================================================================
Install 1 Package (+1 Dependent package)
Total download size: 524 k
Installed size: 2.5 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): iscsi-initiator-utils-iscsiuio-6.2.0.874-22.0.1.el7_9.x86_64.rpm | 96 kB 00:00:01
(2/2): iscsi-initiator-utils-6.2.0.874-22.0.1.el7_9.x86_64.rpm | 429 kB 00:00:02
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 224 kB/s | 524 kB 00:00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : iscsi-initiator-utils-iscsiuio-6.2.0.874-22.0.1.el7_9.x86_64 1/2
Installing : iscsi-initiator-utils-6.2.0.874-22.0.1.el7_9.x86_64 2/2
Verifying : iscsi-initiator-utils-6.2.0.874-22.0.1.el7_9.x86_64 1/2
Verifying : iscsi-initiator-utils-iscsiuio-6.2.0.874-22.0.1.el7_9.x86_64 2/2
Installed:
iscsi-initiator-utils.x86_64 0:6.2.0.874-22.0.1.el7_9
Dependency Installed:
iscsi-initiator-utils-iscsiuio.x86_64 0:6.2.0.874-22.0.1.el7_9
Complete!
[root@test-machine01 ~]#
[root@test-machine01 ~]#
[root@test-machine01 ~]# rpm -qa |grep iscsi
iscsi-initiator-utils-iscsiuio-6.2.0.874-22.0.1.el7_9.x86_64
iscsi-initiator-utils-6.2.0.874-22.0.1.el7_9.x86_64
[root@test-machine01 ~]#
Step 2. Share iSCSI initiator ID with Storage Admin: iSCSI rpm will create file initiatorname.iscsi with initiator id. Share this ID with your Storage Admin. They will allocate iSCSI LUN based on initiator id to Linux Machine.
[root@test-machine01 ~]#
[root@test-machine01 ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1988-12.com.oracle:e6ef280a1d4
[root@test-machine01 ~]#
Step 3. Discovering targets in iSCSI server: Once Storage Team confirms iSCSI LUN are allocated. We need to discover and login to the allocated iSCSI LUN. Once login is done successfully make login automatic so iSCSI LUN login automatically once client Linux machine is rebooted. Please note IP: 192.168.101.201 is iSCSI Server (Target) IP.
[root@test-machine01 ~]#
[root@test-machine01 ~]# /sbin/iscsiadm -m discovery -t sendtargets -p 192.168.101.201
192.168.101.201:3260,1 iqn.2010-06.com.nutanix:test-machine01-backup02-ef09be32-0a57-465d-93e2-79e7d0bdb404-tgt0
[root@test-machine01 ~]#
[root@test-machine01 ~]# /sbin/iscsiadm -m node -T iqn.2010-06.com.nutanix:test-machine01-backup02-ef09be32-0a57-465d-93e2-79e7d0bdb404-tgt0 -p 192.168.101.201 -l
Logging in to [iface: default, target: iqn.2010-06.com.nutanix:test-machine01-backup02-ef09be32-0a57-465d-93e2-79e7d0bdb404-tgt0, portal: 192.168.101.201,3260] (multiple)
Login to [iface: default, target: iqn.2010-06.com.nutanix:test-machine01-backup02-ef09be32-0a57-465d-93e2-79e7d0bdb404-tgt0, portal: 192.168.101.201,3260] successful.
[root@test-machine01 ~]#
[root@test-machine01 ~]# /sbin/iscsiadm -m node -T iqn.2010-06.com.nutanix:test-machine01-backup02-ef09be32-0a57-465d-93e2-79e7d0bdb404-tgt0 -p 192.168.101.201 --op update -n node.startup -v automatic
[root@test-machine01 ~]#
[root@test-machine01 ~]# /sbin/iscsiadm -m session -P 0
tcp: [2] 192.168.101.201:3260,1 iqn.2010-06.com.nutanix:test-machine01-backup02-ef09be32-0a57-465d-93e2-79e7d0bdb404-tgt0 (non-flash)
[root@test-machine01 ~]#
Step 4. Check if the disk added Linux Machine: We can check in /var/log/messages for device name in our case it’s sda. Use command fdisk -l /dev/sda to get capacity details.
[root@test-machine01 log]# vi /var/log/messages
Dec 26 03:32:01 test-machine01 rsyslogd: [origin software="rsyslogd" swVersion="5.8.10" x-pid="3436" x-info="http://www.rsyslog.com"] rsyslogd was HUPed
Dec 26 05:30:58 test-machine01 kernel: [25894179.219584] EXT4-fs (veeamimage0): mounted filesystem with ordered data mode. Opts: (null)
Dec 26 09:50:25 test-machine01 kernel: [25909746.477065] scsi host3: iSCSI Initiator over TCP/IP
Dec 26 09:50:25 test-machine01 kernel: [25909746.779177] scsi 3:0:0:0: Direct-Access NUTANIX VDISK 0 PQ: 0 ANSI: 5
Dec 26 09:50:25 test-machine01 kernel: [25909746.784262] sd 3:0:0:0: Attached scsi generic sg1 type 0
Dec 26 09:50:25 test-machine01 kernel: [25909746.793775] sd 3:0:0:0: [sda] 2147483648 512-byte logical blocks: (2.09 TB/1.00 TiB)
Dec 26 09:50:25 test-machine01 kernel: [25909746.793778] sd 3:0:0:0: [sda] 4096-byte physical blocks
Dec 26 09:50:25 test-machine01 kernel: [25909746.797385] sd 3:0:0:0: [sda] Write Protect is off
Dec 26 09:50:25 test-machine01 kernel: [25909746.798549] sd 3:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
Dec 26 09:50:25 test-machine01 kernel: [25909746.829019] sd 3:0:0:0: [sda] Attached SCSI disk
Dec 26 09:50:26 test-machine01 iscsid: Could not set session2 priority. READ/WRITE throughout and latency could be affected.
Dec 26 09:50:26 test-machine01 iscsid: Connection2:0 to [target: iqn.2010-06.com.nutanix:test-machine01-backup02-ef09be32-0a57-465d-93e2-79e7d0bdb404-tgt0, portal: 192.168.101.201,3260] through [iface: default] is operational now
[root@test-machine01 log]#
[root@test-machine01 log]#
[root@test-machine01 log]# fdisk -l /dev/sda
Disk /dev/sda: 2099.5 GB, 1099511627776 bytes
255 heads, 63 sectors/track, 133674 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disk identifier: 0x00000000
[root@test-machine01 log]#
Step 5. Create a partition on the newly attached disk: We will use the full disk as a single partition. Use command fdisk /dev/sda and follow the below steps to do a single partition on the disk. Once the partition is done verify partition with command parted /dev/sda print or fdisk /dev/sda with print (p) option.
[root@test-machine01 log]#
[root@test-machine01 log]# fdisk /dev/sda
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x50bb870d.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: The size of this disk is 2.2 TB (2199023255552 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID
partition table format (GPT).
The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-267349, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-267349, default 267349):
Using default value 267349
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@test-machine01 log]#
[root@test-machine01 log]#
[root@test-machine01 log]# fdisk -l /dev/sda
Disk /dev/sda: 2199.0 GB, 2199023255552 bytes
255 heads, 63 sectors/track, 267349 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disk identifier: 0x50bb870d
Device Boot Start End Blocks Id System
/dev/sda1 1 267349 2147480811 83 Linux
Partition 1 does not start on physical sector boundary.
[root@test-machine01 log]#
[root@test-machine01 ~]#
[root@test-machine01 ~]# parted /dev/sda print
Model: NUTANIX VDISK (scsi)
Disk /dev/sda: 2199GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Number Start End Size Type File system Flags
1 32.3kB 2199GB 2199GB primary ext4
[root@test-machine01 ~]]#
[root@test-machine01 ~]]#
[root@test-machine01 ~]]# fdisk /dev/sda
WARNING: The size of this disk is 2.2 TB (2199023255552 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID
partition table format (GPT).
The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p
Disk /dev/sda: 2199.0 GB, 2199023255552 bytes
255 heads, 63 sectors/track, 267349 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disk identifier: 0x50bb870d
Device Boot Start End Blocks Id System
/dev/sda1 1 267349 2147480811 83 Linux
Partition 1 does not start on physical sector boundary.
Command (m for help): q
[root@test-machine01 ~]#
Step 6. Create a file system on the partition: Use the command mkfs.ext4 /dev/sda1 to format a disk with ext4 filesystem or mkfs.xfs /dev/sda1 to format a disk with xfs filesystem. Use command blkid to get UUID of the partition.
[root@test-machine01 log]#
[root@test-machine01 log]# mkfs.ext4 /dev/sda1
mke2fs 1.43-WIP (20-Jun-2013)
/dev/sda1 alignment is offset by 512 bytes.
This may result in very poor performance, (re)-partitioning suggested.
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=256 blocks
134217728 inodes, 536870202 blocks
26843510 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
16384 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848, 512000000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@test-machine01 log]#
[root@test-machine01 log]#
[root@test-machine01 log]#
[root@test-machine01 log]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 2T 0 disk
ââsda1 8:1 0 2T 0 part
sr0 11:0 1 3.8G 0 rom
vda 248:0 0 30G 0 disk
ââvda1 248:1 0 500M 0 part /boot
ââvda2 248:2 0 29.5G 0 part
ââvg_test-machine01-lv_root (dm-0) 249:0 0 26.5G 0 lvm /
ââvg_test-machine01-lv_swap (dm-1) 249:1 0 3G 0 lvm [SWAP]
vdb 248:16 0 35G 0 disk
ââvdb1 248:17 0 35G 0 part
ââvg_test-machine01-lv_app (dm-2) 249:2 0 35G 0 lvm /app
[root@test-machine01 log]#
[root@test-machine01 log]# blkid
/dev/vda1: UUID="1e11091d-df58-4495-92df-9416168916c9" TYPE="ext4"
/dev/vda2: UUID="2rbj5c-kPkT-g03n-zYLw-oEea-pPqP-8byLbe" TYPE="LVM2_member"
/dev/vdb1: UUID="xFV1p4-TL7n-QeBt-Fup0-80Vs-lzkt-6dcBut" TYPE="LVM2_member"
/dev/sr0: LABEL="OL6.10 x86_64 Disc 1 20180625" TYPE="iso9660"
/dev/sda1: UUID="c48cb080-23d2-4e4e-80cb-3c40f4dc3aaa" TYPE="ext4"
[root@test-machine01 log]#
Step 7. Add entry in /etc/fstab and mount: To mount all filesystem with machine reboot add entry “UUID=”c48cb080-23d2-4e4e-80cb-3c40f4dc3aaa” /backup02 ext4 _netdev 0 0” in /etc/fstab. We will mount the filesystem with /backup02. Create folder backup02 under root directory and mount using mount -a command.
[root@test-machine01 ~]#
[root@test-machine01 ~]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Aug 22 16:35:37 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_test-machine01-lv_root / ext4 defaults 1 1
UUID=1e11091d-df58-4495-92df-9416168916c9 /boot ext4 defaults 1 2
UUID=c0131cfe-11e9-4357-95a4-ceeedb04beef /app ext4 defaults 0 0
/dev/mapper/vg_test-machine01-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
UUID="c48cb080-23d2-4e4e-80cb-3c40f4dc3aaa" /backup02 ext4 _netdev 0 0
[root@test-machine01 ~]#
[root@test-machine01 ~]#
[root@test-machine01 ~]#
[root@test-machine01 ~]# cd /
[root@test-machine01 /]#
[root@test-machine01 /]# mkdir backup02
[root@test-machine01 /]#
[root@test-machine01 /]# mount -a
[root@test-machine01 /]#
[root@test-machine01 /]# df -Th /backup02
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 2.0T 71M 1.9T 1% /backup02
[root@test-machine01 /]#
[root@test-machine01 /]#
This document is just for learning purpose and always validate in the LAB environment first before applying in the LIVE environment.
Hope so you like this article!
Please share your valuable feedback/comments/subscribe and follow us below and don’t forget to click on the bell icon to get the most recent update. Click here to understand more about our pursuit.
Related Articles
- How to Enable PasswordLess SSH login in Linux
- Steps to Install & Configure SNMP in Oracle Linux 7
- Steps to Add and Extend Swap Space in Linux
- Steps To Increase Mount Point Space In Oracle Linux
- Steps to Move ISCSI Target to Another Linux Server
Very appreciated you have mentioned everything about iscsi targets on linux server very descriptively. It is very informative and helpful for me specially and for others also thanks for share with us.