TrumanWong

iscsiadm

Manage iSCSI connections

Supplementary instructions

iscsiadm command is used to manage iSCSI (Internet Small Computer System Interface) storage connections. iSCSI is a network-based storage protocol that allows block-level data transfer between computers. The iscsiadm command provides functions for connecting, configuring, and managing iSCSI storage devices.

yum install iscsi-initiator-utils #Install iscsiadm
/etc/iscsi/initiatorname.iscsi #iscsi initiator name configuration file location
systemctl enable iscsi #Set the service to start at boot
systemctl enable iscsid
systemctl restart iscsi #Restart iscsi service
systemctl restart iscsid

grammar

iscsiadm [options] <command> <parameters>

Options

-m, --mode # <mode> Specify the working mode, such as discovery (discovery mode), node (management node), session (management session), discoverydb, host, iface (management iSCSI network interface);
-t, --type # Specify the type, such as sendtargets (or st), isns, fw, only used in discovery mode;
-T, --targetname #Specify the target name, only used in node mode;
-p, --portal # <ip:port> Specify the target IP. Without port, the default is 3260. It is only used in discovery and node modes;
-l, --login # Log in to an iSCSI device, only used in discovery and node modes;
-u, --logout # Exit an iSCSI device, only used in node and session mode;
-I, --interface # Specify the network interface used for iSCSI operations;
-P, --print # <0-4> Print details, used in discovery, node, and session modes;
-s, --stats # View session status
-h, --help # Display help;
-V, --version # Display version information.

Example

Send an iSCSI discovery request and list discovered iSCSI device targets:

[root@Azroy-s1 ~]# iscsiadm -m discovery -t st -p 10.10.10.10
10.10.10.10:3260,1 iqn.2000-01.com.synology:NAS.default-target.1

Log in to the discovered iSCSI target:

[root@Azroy-s1 ~]# iscsiadm -m node -T iqn.2000-01.com.synology:NAS.target.1 -p 10.10.10.10 -l
Logging in to [iface: default, target: iqn.2000-01.com.synology:NAS.target.1, portal: 10.10.10.10,3260] (multiple)
Login to [iface: default, target: iqn.2000-01.com.synology:NAS.target.1, portal: 10.10.10.10,3260] successful.

View logged in devices:

[root@Azroy-s1 ~]# iscsiadm -m session
tcp: [3] 10.10.10.10:3260,1 iqn.2000-01.com.synology:NAS.target.1 (non-flash)

Sign out of a signed-in device:

[root@Azroy-s1 ~]# iscsiadm -m node -T iqn.2000-01.com.synology:NAS.target.1 -p 10.10.10.10 -u
Logging out of session [sid: 11, target: iqn.2000-01.com.synology:NAS.target.1, portal: 10.10.10.10,3260]
or
[root@Azroy-s1 ~]# iscsiadm -m session -u #Exit all iscsi sessions

Use lsblk or fdisk to view the hard disk, and then format the hard disk partition to mount the directory.

[root@Azroy-s1 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1.8T 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 1.8T 0 part
   ├─centos-root 253:0 0 1.8T 0 lvm /
   └─centos-swap 253:1 0 5.9G 0 lvm [SWAP]
sdb 8:32 0 10G 0 disk

[root@Azroy-s1 ~]# lsblk -S /dev/sd* #You can check the hard disk transfer type
NAME HCTL TYPE VENDOR MODEL REV TRAN
sda 0:1:0:0 disk HP LOGICAL VOLUME 3.00 sas
sdb 12:0:0:1 disk SYNOLOGY Storage 4.0 iscsi

[root@Azroy-s1 ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes