Complete Guide: How to Discover, Connect, Mount and Format iSCSI LUN in Red Hat Enterprise Linux 9
Introduction
iSCSI (Internet Small Computer Systems Interface) is a powerful protocol that allows you to access remote storage devices over IP networks. In enterprise environments, iSCSI provides a cost-effective alternative to Fibre Channel SANs while offering excellent performance and scalability. This comprehensive guide walks you through the complete process of discovering, connecting, mounting, and formatting iSCSI LUNs (Logical Unit Numbers) in Red Hat Enterprise Linux 9.
Prerequisites
Before beginning this tutorial, ensure you have:
- Red Hat Enterprise Linux 9 system with root privileges
- Network connectivity to the iSCSI target server
- Basic understanding of Linux storage concepts
- iSCSI target server configured and accessible
What You’ll Learn
By the end of this guide, you’ll understand how to:
- Install and configure iSCSI initiator tools
- Discover available iSCSI targets
- Authenticate and connect to iSCSI LUNs
- Format and mount iSCSI storage
- Configure persistent connections
- Troubleshoot common iSCSI issues
Step 1: Install iSCSI Initiator Software
First, install the necessary iSCSI initiator packages on your RHEL 9 system:
# Install iscsi-initiator-utils package sudo dnf install iscsi-initiator-utils -y # Verify installation rpm -qa | grep iscsi
The iscsi-initiator-utils
package provides essential tools including:
iscsiadm
: Primary command-line tool for iSCSI managementiscsi_discovery
: Service for automatic target discovery- Configuration files in
/etc/iscsi/
Step 2: Configure iSCSI Initiator Settings
Configure the iSCSI initiator name, which uniquely identifies your system:
# Check current initiator name cat /etc/iscsi/initiatorname.iscsi # Generate new initiator name (if needed) echo "InitiatorName=$(iscsi-iname)" | sudo tee /etc/iscsi/initiatorname.iscsi # Start and enable iscsid service sudo systemctl start iscsid sudo systemctl enable iscsid
Step 3: Discover iSCSI Targets
Use the iscsiadm
command to discover available targets on your iSCSI server:
# Discover targets using SendTargets method sudo iscsiadm --mode discovery --type sendtargets --portal <TARGET_IP>:3260 # Example with actual IP sudo iscsiadm --mode discovery --type sendtargets --portal 192.168.1.100:3260
Expected output format:
192.168.1.100:3260,1 iqn.2023-01.com.example:storage.target01 192.168.1.100:3260,1 iqn.2023-01.com.example:storage.target02
To view discovered targets:
# List all discovered targets sudo iscsiadm --mode node --op show
Step 4: Configure Authentication (Optional)
If your iSCSI target requires CHAP authentication, configure credentials:
# Set CHAP username and password for specific target sudo iscsiadm --mode node --targetname <TARGET_IQN> --portal <TARGET_IP>:3260 \ --op update --name node.session.auth.authmethod --value CHAP sudo iscsiadm --mode node --targetname <TARGET_IQN> --portal <TARGET_IP>:3260 \ --op update --name node.session.auth.username --value <USERNAME> sudo iscsiadm --mode node --targetname <TARGET_IQN> --portal <TARGET_IP>:3260 \ --op update --name node.session.auth.password --value <PASSWORD>
Step 5: Connect to iSCSI Target
Establish connection to the discovered iSCSI target:
# Login to specific target sudo iscsiadm --mode node --targetname <TARGET_IQN> --portal <TARGET_IP>:3260 --login # Example command sudo iscsiadm --mode node --targetname iqn.2023-01.com.example:storage.target01 \ --portal 192.168.1.100:3260 --login
Verify successful connection:
# Check active sessions sudo iscsiadm --mode session --op show # View detailed session information sudo iscsiadm --mode session --op show --verbose
Step 6: Identify the New Block Device
After successful connection, identify the newly available block device:
# List all block devices lsblk # Check system messages for new device dmesg | tail -20 # View SCSI devices cat /proc/scsi/scsi
The iSCSI LUN typically appears as /dev/sdX
where X is the next available letter.
Step 7: Partition the iSCSI LUN (Optional)
Create partitions on the iSCSI device if needed:
# Use fdisk to create partitions sudo fdisk /dev/sdX # Interactive fdisk commands: # n - create new partition # p - primary partition # 1 - partition number # [Enter] - default first sector # [Enter] - default last sector # w - write changes
For GPT partitioning (recommended for large disks):
# Use parted for GPT sudo parted /dev/sdX mklabel gpt sudo parted /dev/sdX mkpart primary 0% 100%
Step 8: Format the iSCSI LUN
Create a filesystem on the iSCSI device:
# Format with ext4 filesystem sudo mkfs.ext4 /dev/sdX1 # Format with xfs filesystem (alternative) sudo mkfs.xfs /dev/sdX1 # Add filesystem label sudo e2label /dev/sdX1 "iscsi-storage"
Step 9: Create Mount Point and Mount the LUN
Create a directory and mount the formatted iSCSI LUN:
# Create mount point sudo mkdir -p /mnt/iscsi-storage # Mount the filesystem sudo mount /dev/sdX1 /mnt/iscsi-storage # Verify mount df -h /mnt/iscsi-storage mount | grep iscsi-storage
Step 10: Configure Persistent Mounting
To automatically mount the iSCSI LUN at boot, add an entry to /etc/fstab
:
# Get device UUID sudo blkid /dev/sdX1 # Add to fstab using UUID (recommended) echo "UUID=<device-uuid> /mnt/iscsi-storage ext4 defaults,_netdev 0 2" | sudo tee -a /etc/fstab # Alternative using device path echo "/dev/sdX1 /mnt/iscsi-storage ext4 defaults,_netdev 0 2" | sudo tee -a /etc/fstab
The _netdev
option ensures the filesystem is mounted after network services are available.
Step 11: Configure Automatic iSCSI Connection
Enable automatic connection to iSCSI targets at boot:
# Set automatic login for target sudo iscsiadm --mode node --targetname <TARGET_IQN> --portal <TARGET_IP>:3260 \ --op update --name node.startup --value automatic # Enable iscsi service for boot-time connections sudo systemctl enable iscsi
Step 12: Test and Verify Configuration
Perform comprehensive testing to ensure everything works correctly:
# Test filesystem access sudo touch /mnt/iscsi-storage/test-file ls -la /mnt/iscsi-storage/ # Check iSCSI session status sudo systemctl status iscsi sudo systemctl status iscsid # Simulate reboot test (optional) sudo umount /mnt/iscsi-storage sudo iscsiadm --mode node --targetname <TARGET_IQN> --portal <TARGET_IP>:3260 --logout sudo mount -a
Troubleshooting Common Issues
Connection Problems
If you encounter connection issues:
# Check network connectivity ping <TARGET_IP> telnet <TARGET_IP> 3260 # Review iSCSI logs sudo journalctl -u iscsid sudo journalctl -u iscsi # Check firewall settings sudo firewall-cmd --list-ports sudo firewall-cmd --add-port=3260/tcp --permanent sudo firewall-cmd --reload
Discovery Issues
For target discovery problems:
# Clear discovery cache sudo rm -rf /var/lib/iscsi/send_targets/* # Retry discovery with debug sudo iscsiadm --mode discovery --type sendtargets --portal <TARGET_IP>:3260 --debug 8
Performance Optimization
Optimize iSCSI performance:
# Adjust iSCSI parameters sudo iscsiadm --mode node --targetname <TARGET_IQN> --portal <TARGET_IP>:3260 \ --op update --name node.session.timeo.replacement_timeout --value 120 # Configure multipath (if using multiple paths) sudo dnf install device-mapper-multipath -y sudo mpathconf --enable --with_multipathd y
Security Best Practices
Implement these security measures:
- Use CHAP Authentication: Always configure CHAP authentication for production environments
- Network Segmentation: Deploy iSCSI traffic on dedicated VLANs
- Firewall Rules: Restrict access to iSCSI ports (3260/tcp)
- Regular Updates: Keep iSCSI initiator software updated
# Configure bidirectional CHAP sudo iscsiadm --mode node --targetname <TARGET_IQN> --portal <TARGET_IP>:3260 \ --op update --name node.session.auth.authmethod --value CHAP # Set mutual authentication sudo iscsiadm --mode node --targetname <TARGET_IQN> --portal <TARGET_IP>:3260 \ --op update --name node.session.auth.username_in --value <INITIATOR_USERNAME>
Managing Multiple iSCSI LUNs
For environments with multiple LUNs:
# Discover all targets from server sudo iscsiadm --mode discovery --type sendtargets --portal <TARGET_IP>:3260 # Login to all discovered targets sudo iscsiadm --mode node --loginall=all # Check all active sessions sudo iscsiadm --mode session
Conclusion
This comprehensive guide covered the complete process of working with iSCSI LUNs in Red Hat Enterprise Linux 9. You’ve learned how to discover targets, establish connections, format storage, and configure persistent mounting. These skills are essential for managing enterprise storage infrastructure and ensuring reliable data access across your network.
Remember to always test your configuration thoroughly in development environments before implementing in production. Regular monitoring and maintenance of iSCSI connections will ensure optimal performance and reliability of your storage infrastructure.
Additional Resources
- Red Hat Enterprise Linux 9 Storage Administration Guide
- iSCSI RFC 7143 documentation
- RHEL 9 System Administrator’s Guide
- Red Hat Customer Portal for enterprise support
For enterprise deployments, consider implementing monitoring solutions and automated backup strategies to protect your iSCSI-based storage infrastructure.