sBlock - iSCSI Linux Guide
Publisher: Psychz Networks, May 09,2024- Prerequisites
- Install Initiator
- Verify Daemon
- Discover Volume
- Mount Volume
- View Volume
- Format Volume
- Unmount Volume
This guide will delve into the steps required to connect to and utilize an iSCSI volume from the Linux operating system. iSCSI (Internet Small Computer System Interface) provides access to storage devices over an IP network, allowing for flexible and efficient storage solutions in various computing environments.
Prerequisites
Before proceeding, ensure you have the following details readily available, as they were provided during the creation of the Block Storage:
Dummy data for representation purpose only.
- Initiator IQN: iqn.2024-04.com.xxxxxxxx:mj6rs9x7ok664207ce360c6-testdevice
- Target IQN: iqn.2024-04.com.xxxxxxx:us-west-1.stor.01
- Port: 3260
- CHAP Username: 1234567d258c84
- CHAP Password: xxxxxxxxxxxxx
- Mutual CHAP Username: THIS_is_DUMMY_UNAME
- Mutual CHAP Password: xxxxxxxxxxxxxxx
Install the iSCSI Initiator Utilities
Log in to your Linux host system and install the necessary iSCSI initiator utility package on your Linux system. This package is vital for establishing connections to iSCSI volumes.
For Ubuntu/Debian
# apt update
# apt install open-iscsi
After installation, start the iSCSI service and enable it to start automatically on system boot.
# systemctl start iscsid
# systemctl enable iscsid
For RHEL 7/8/CentOS
# yum install iscsi-initiator-utils
After installation, start the iscsid service and enable it to start automatically on system boot.
# systemctl start iscsid
# systemctl enable iscsid
Verify iSCSI Daemon Status
Check if the iSCSI daemon is running on your system using the appropriate command based on your Linux distribution.
For Ubuntu/Debian
# iscsiadm --mode session
For CentOS/RHEL 7/8
# systemctl status iscsi.service
Discover the iSCSI Volume
Use the `iscsiadm` command to discover the iSCSI volume on your network.
# iscsiadm -m discovery -t st -p <IP address>:3260
- Replace <IP address> with the Target address of the block gateway provided during creation.
Mount the iSCSI Volume
Initiate the connection to the iSCSI volume using the target address and IP address. This needs to be done in the following steps
Step 1: Update Initiator Name
Before you mount the volume, you need to update the Initiator Name with the one provided by us at the time of sBlock creation. To edit the information, please use the following command
# sudo nano /etc/iscsi/initiatorname.iscsi
Now, replace the entire string after "InitiatorName=" with the Initiator IQN.
Sample output
## If you remove this file, the iSCSI daemon will not start.
## If you change the InitiatorName, existing access control lists
## may reject this initiator. The InitiatorName must be unique
## for each iSCSI initiator. Do NOT duplicate iSCSI InitiatorNames.
InitiatorName=iqn.2024-04.com.xxxxxxxx:mj6rs9x7ok664207ce360c6-testdevice
Step 2: Set the authentication method to CHAP
# iscsiadm -m node -T <target address> -p <IP address>:3260 --op update -n node.session.auth.authmethod -v CHAP
- Replace `<target address>` with Target IQN and `<IP address>` with iSCSI Target Adress. This information is shared during the setup.
Step 3: Set the username for CHAP authentication
# iscsiadm -m node -T <target address> -p <IP address>:3260 --op update -n node.session.auth.username -v <username>
Step 4: Set the password for CHAP authentication:
# iscsiadm -m node -T <target address> -p <IP address>:3260 --op update -n node.session.auth.password -v <password>
Step 5: Login to the iSCSI target
# iscsiadm -m node -T <target address> -p <IP address>:3260 -l
Note: iSCSI volumes cannot be mounted simultaneously across multiple Linux clients due to protocol limitations.
View the iSCSI Volume
Confirm the successful connection and view the iSCSI volume on your system.
# fdisk -l
# lsblk
You should see the mounted iSCSI volume listed as an available raw disk, enabling read and write operations from your host.
Format the iSCSI Volume
Now, format the volume with a file system. Common file systems include ext4 (for Linux environments).
# sudo mkfs.ext4 /dev/sdb
Sample Output
Discarding device blocks: done
Creating filesystem with 3932160 4k blocks and 983040 inodes
Filesystem UUID: f1660e31-5338-4c97-bb0e-772a539c8aa8
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
Unmount the iSCSI Volume
When done with the volume, unmount it using the following command:
# iscsiadm -m node -T <target name> -p <IP address>:3260 -u
- Replace `<target name>` and `<IP address>` with the appropriate details for the volume.
By following these steps, you can effectively connect to and utilize iSCSI volumes within your Linux environment, enhancing storage capabilities for your computing needs.