Linux SCSI and iSCSI Configuration and Installation
This guide provides step-by-step instructions for configuring and installing SCSI and iSCSI on a Linux system. Follow the steps below to set up your environment.
What is SCSI?
SCSI (Small Computer System Interface) is a set of standards for connecting and transferring data between computers and peripheral devices.
What is iSCSI?
iSCSI (Internet Small Computer Systems Interface) is a protocol that allows SCSI commands to be sent over IP networks, enabling remote storage access.
Package name: targetcli
Demon name: targetd
Port number: 3260
Command name: targetcli
Service name: iscsid.service
Log file: /var/log/messages
Configuration file: /etc/iscsi/saveconfig.json
Note: The iSCSI target service is typically managed by the targetcli command.
Second machine ISCSI
Package name: iscsi-initiator-utils
Demon name: iscsid
Port number: 3260
Command name: iscsiadm
Steps to Configure and Install SCSI
1. Install Required Packages
Install the necessary SCSI utilities:
sudo apt update
sudo apt install targetcli
Redhat base installation
sudo yum install targetcli
2. Start and Enable the Target Service
Start and enable the target service to run on boot:
sudo systemctl start target
sudo systemctl enable target
For Redhat base installation:
sudo systemctl start targetd
sudo systemctl enable targetd
3. Configure the SCSI Target
Use the targetcli command to configure the SCSI target:
sudo targetcli
Within the targetcli shell, you can create a new target, add LUNs, and configure access control. For example:
/> backstores/block create name=myblockstore dev=/dev/sdb
/> iscsi/ create iqn.2023-10.com.example:mytarget
/> iscsi/mytarget/tpg1/acls/ create iqn.2023-10.com.example:initiator
/> iscsi/mytarget/tpg1/luns/ create /backstores/block/myblockstore
/> saveconfig
Exit the targetcli shell with:
/> exit
4. Save the Configuration
Save the configuration to ensure it persists across reboots:
sudo targetcli saveconfig
5. Verify the Configuration
Check the status of the target service:
sudo systemctl status target
For Redhat base installation:
sudo systemctl status targetd
Steps to Configure and Install iSCSI Initiator
1. Install Required Packages
Install the iSCSI initiator utilities:
sudo apt update
sudo apt install open-iscsi
For Redhat base installation:
sudo yum install iscsi-initiator-utils
2. Start and Enable the iSCSI Service
Start and enable the iSCSI service to run on boot:
sudo systemctl start iscsid
sudo systemctl enable iscsid
3. Discover iSCSI Targets
Discover available iSCSI targets on the network:
sudo iscsiadm --mode discovery --type sendtargets --portal <target_ip_address>
Replace <target_ip_address> with the IP address of the iSCSI target.
4. Log in to the iSCSI Target
Log in to the discovered iSCSI target:
sudo iscsiadm --mode node --targetname iqn.2023-10.com.example:mytarget --login
Replace iqn.2023-10.com.example:mytarget with the actual target name.
5. Verify the iSCSI Connection
Check the status of the iSCSI connection:
sudo iscsiadm --mode session -p 0
Note: 0 = inshort information, 1 = Half information, 2 = Full information
This command will display the active iSCSI sessions and their status.
6. Configure Automatic Login
To ensure the iSCSI initiator automatically logs in to the target on boot, modify the configuration file:
sudo vim /etc/iscsi/initiatorname.iscsi
Ensure the node.startup option is set to automatic:
node.startup = automatic
7. Restart the iSCSI Service
Restart the iSCSI service to apply the changes:
sudo systemctl restart iscsid
Example Configuration
Here is an example of a complete configuration for both SCSI and iSCSI:
# SCSI Target Configuration
sudo targetcli
/> backstores/block create name=myblockstore dev=/dev/sdb
/> iscsi/ create iqn.2023-10.com.example:mytarget
/> iscsi/mytarget/tpg1/luns/ create /backstores/block/myblockstore
/> iscsi/mytarget/tpg1/acls/ create iqn.2023-10.com.example:initiator
/> exit
sudo targetcli saveconfig
# iSCSI Initiator Configuration